@lichao0223/lobehub-cli 0.0.0-stage → 0.0.78

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
@@ -1,3 +1,383 @@
1
- # Temporary Holding Version
1
+ # @lichao0223/lobehub-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ LobeHub command-line interface.
4
+
5
+ ## Release to npm
6
+
7
+ The `Release Fork CLI` GitHub Actions workflow publishes to npm's `latest` tag when
8
+ CLI production inputs change on `canary`. Merge the feature or fix PR after its
9
+ checks and required product acceptance; no separate version-bump PR is needed.
10
+
11
+ Automatic inputs are `apps/cli/src/**`, build scripts, `package.json`, the CLI
12
+ workspace/TypeScript/tsdown configuration, and the release workflow/helper.
13
+ Tests, fixtures, Markdown documentation, E2E-only changes and generated manuals
14
+ are excluded. Changes only to shared workspace packages or the offline report
15
+ can be released by manually dispatching `Release Fork CLI` on `canary`.
16
+
17
+ CI allocates the next patch above the highest stable npm version (for example,
18
+ `0.0.78` → `0.0.79`). A higher stable version intentionally set in `package.json`
19
+ is honored for a minor/major release. The generated version is used for the
20
+ bundle and manual; CI does not commit version changes back to the branch. The
21
+ checked-in version is therefore a development baseline, not necessarily npm's
22
+ latest release. Use `npm view @lichao0223/lobehub-cli version` to check the published version.
23
+
24
+ The workflow tests the bundle, runs the complete `prepublishOnly` build, checks
25
+ the built CLI and packs it. Immediately before publication it creates a
26
+ `cli-release/v<version>` Git tag pointing at the source commit. The tag reserves
27
+ the version for retries; the published package also records `gitHead`.
28
+ Publication is serialized and the workflow waits up to ten minutes for npm to
29
+ expose the matching version/source under `latest`. A successful upload alone is
30
+ not reported as a verified publication.
31
+
32
+ Use **Re-run failed jobs** on the original run to recover a failed publication.
33
+ A retry reuses its reserved version or skips it if already published. If npm is
34
+ still processing an earlier reserved release, a different commit's release stops
35
+ with a recovery message instead of allocating another version. Older reruns do
36
+ not publish over newer source commits. Build/test failures before reservation
37
+ can be fixed by the next PR normally. Do not delete reservation tags to retry a
38
+ release. Registry errors stop the workflow.
39
+
40
+ GitHub may coalesce queued runs while another release is running; the surviving
41
+ newer commit includes the earlier merged changes. This publishes source snapshots,
42
+ not necessarily one version per merged PR.
43
+
44
+ Publishing uses the repository's `NPM_TOKEN` secret, as the SDK release does.
45
+ It must have publish permission for `@lichao0223/lobehub-cli` and support unattended
46
+ publishing under the package's npm authentication policy. PR previews continue
47
+ to publish separately to `pkg.pr.new`.
48
+
49
+ ## Update a connected device
50
+
51
+ ```bash
52
+ lh update # Install the latest CLI without restarting a connector
53
+ lh connect status # Connection, running version, and any required action
54
+ lh connect status --verbose # Service metadata and CLI installation paths
55
+
56
+ # Wait for active tasks to finish, then restart the detected connector:
57
+ lh connect restart
58
+ lh connect status # Verify the new running version and connection
59
+ ```
60
+
61
+ Installing an update and activating it are separate steps. `lh update` keeps the
62
+ running connector in place; it reports the installed and running versions separately.
63
+ Restarting disconnects the device and closes its remote terminals. A terminal
64
+ provided by LobeHub may close or print `Terminated` before the restart request
65
+ returns. Reconnect before checking status; “Restart requested” is not confirmation
66
+ that the device is already connected.
67
+
68
+ `lh connect restart` detects a CLI daemon or a user/system systemd service. System
69
+ services use `sudo` unless already running as root. When multiple connectors are
70
+ running, select one with `--manager daemon`, `--manager user`, or `--manager system`.
71
+ Service restarts preserve the unit's configuration; daemon connection flags such
72
+ as `--token` cannot override it. `lh connect service restart` remains a user-service
73
+ alias. With no managed connector and no inspection failures, `lh connect restart`
74
+ retains its existing behavior of starting a daemon. Daemon restarts wait for the
75
+ previous process to exit before starting its replacement, including when upgrading
76
+ from an older CLI. If shutdown times out, no replacement is started.
77
+
78
+ A daemon cannot be restarted from a terminal or shell it owns: its shutdown would
79
+ kill the waiting restart command. This is rejected before stopping the connection;
80
+ run `lh connect restart` from a local terminal or an independent SSH session instead.
81
+ If process ancestry cannot be verified, the restart is also rejected without
82
+ stopping the connector. Systemd service restarts still use the service manager.
83
+
84
+ If an older restart lost `daemon.pid`, `lh connect status` can recover it from the
85
+ status record only after verifying that the process is alive and is a daemon, not
86
+ a foreground connection or systemd service. This recovery does not restart the
87
+ connection. Cleanup checks PID ownership; normal restarts also wait for the old
88
+ process to exit before creating new records.
89
+
90
+ If the version still differs after a restart, the status report shows the command's
91
+ CLI entry path and the connector's entry path when available. Different paths mean
92
+ you should update the connector's installation or change its service configuration.
93
+ Diagnostics never dump the service's command line or environment. Older connectors
94
+ on Linux use a conservative `/proc` lookup; an inaccessible or unsupported entry
95
+ is reported as unknown instead of guessed.
96
+
97
+ ## Managed cloud devices
98
+
99
+ A managed cloud device is a device that LobeHub creates and runs for you. The
100
+ platform that runs it starts the agent with:
101
+
102
+ ```bash
103
+ lh connect --managed
104
+ ```
105
+
106
+ Managed mode reads everything from the environment. It does not use a stored
107
+ login, a keychain or a browser, and it writes no credentials to disk, so it runs
108
+ headless in a container. `lh connect service install` is not needed: the
109
+ platform supervises the process and restarts it when it exits.
110
+
111
+ | Variable | Required | Meaning |
112
+ | --------------------------------- | -------- | ----------------------------------------------------------- |
113
+ | `LOBEHUB_MANAGED_DEVICE_ID` | yes | The device id. It replaces the id derived from the machine. |
114
+ | `LOBEHUB_MANAGED_DEVICE_SECRET` | yes | The bootstrap secret. The CLI never prints it. |
115
+ | `LOBEHUB_SERVER` | yes | The LobeHub server URL. |
116
+ | `LOBEHUB_DEVICE_GATEWAY_URL` | yes | The device gateway URL. |
117
+ | `LOBEHUB_DEVICE_ACTIVITY_COMMAND` | no | A JSON array: a command to run while the device does work. |
118
+
119
+ If a required variable is missing, the CLI names it and exits with status 1.
120
+ `LOBEHUB_SERVER` and `LOBEHUB_DEVICE_GATEWAY_URL` must use `https`; `http` is
121
+ accepted only for `localhost` and the loopback addresses `127.0.0.0/8` and
122
+ `::1`. The URLs must not contain a user name, a password, a query or a fragment.
123
+ A path is kept, so `https://example.com/lobehub` sends the token request to
124
+ `https://example.com/lobehub/api/device/managed/token`. `--managed` cannot be used
125
+ with `--token`, `--gateway`, `--device-id`, `--workspace`, `--public` or
126
+ `--daemon`.
127
+
128
+ After the CLI reads the secret, it removes it from its own environment, so the
129
+ processes it starts (tool calls, agent runs) do not inherit it. This does not
130
+ hide the secret from the device: other processes of the same user can still
131
+ read the environment the CLI started with (for example `/proc/<pid>/environ`).
132
+ The secret only gets tokens for this device, and it stops working when the
133
+ device is deleted.
134
+
135
+ **Token.** The CLI sends `POST {LOBEHUB_SERVER}/api/device/managed/token` with
136
+ `{ "deviceId", "secret" }` and gets `{ "token", "expiresAt" }`, where
137
+ `expiresAt` is an RFC 3339 time with `Z` or an offset. The token's
138
+ `workspace_id` claim, when present, makes the device a workspace device;
139
+ otherwise its `sub` is the owning user.
140
+
141
+ - The CLI gets a new token when 80% of the token's lifetime has passed (at least
142
+ 5 s after it got the previous one). The open gateway connection stays up:
143
+ only the next connection uses the new token, so running tool calls, agent
144
+ runs and tunnels continue.
145
+ - On HTTP 408, 429 or 5xx, a network error or an unreadable response, the CLI
146
+ tries again after 1 s, then 2 s, 4 s and so on, up to 60 s between attempts
147
+ (each delay ±20%). It continues until the server answers.
148
+ - On HTTP 401 (wrong secret, or the device was deleted), 404 (the server has no
149
+ managed cloud devices) or another 4xx, the CLI exits with status 1.
150
+ - If the gateway rejects a token, the CLI gets a new token and connects again.
151
+ If the gateway also rejects that token before a connection succeeds, the CLI
152
+ exits with status 1.
153
+
154
+ **Activity command.** When `LOBEHUB_DEVICE_ACTIVITY_COMMAND` is set, the CLI runs
155
+ it while the device serves a tool call, an RPC, an agent run or an open tunnel.
156
+ It runs when the work starts and then every 30 s while work continues, never
157
+ more than once in 30 s and never two at a time. The work does not wait for it.
158
+ A run that takes longer than 10 s is stopped. Failures appear only in the debug
159
+ log (`--verbose`).
160
+
161
+ The value is a JSON array of strings: the program, then its arguments, for
162
+ example `["my-agent","touch"]`. The CLI runs the program directly, without a
163
+ shell, so there is no quoting, `$VAR`, `~` or glob expansion, and `|`, `;`, `&`,
164
+ `>` and `<` are ordinary characters. If the value is not a non-empty JSON array
165
+ of non-empty strings, the CLI exits with status 1 at startup. To use shell
166
+ features, give an explicit shell, for example
167
+ `["sh","-c","my-agent touch >> /var/log/activity"]`. When the CLI stops, it
168
+ also stops a command that is still running.
169
+
170
+ ## Publish local artifacts
171
+
172
+ ```bash
173
+ # Publish ordinary HTML and its referenced local resources
174
+ lh artifact publish ./page.html --root . --json
175
+
176
+ # Read the Canvas component and generation rules
177
+ lh artifact guide canvas
178
+
179
+ # Publish a self-contained Canvas HTML file
180
+ lh artifact publish ./report.html --type canvas --json
181
+
182
+ # The binding remembers the type; subsequent publishes update the same artifact
183
+ lh artifact publish ./report.html --json
184
+
185
+ # Create a separate Canvas and bind future publishes to it
186
+ lh artifact publish ./report.html --new --json
187
+
188
+ # Take a published artifact offline (the deployment and its releases are kept)
189
+ lh artifact unpublish ./report.html --json
190
+ ```
191
+
192
+ Bindings and pending operations live in the project's `.lobehub/artifacts.json`.
193
+ Retry the same command with unchanged input after a failed Canvas save or publish;
194
+ the CLI resumes that operation without creating another Canvas or saved version.
195
+ Restore the original input before retrying if you edited it during recovery.
196
+ An explicit validation or version-conflict rejection releases the pending save,
197
+ so you can correct the file or inspect the latest version before trying again.
198
+ If publication explicitly rejects a slug, correct `--slug` and retry with the same
199
+ content and target; the CLI reuses the saved Canvas and version.
200
+ Canvas bindings are scoped to the authenticated account, server and workspace.
201
+
202
+ Canvas input is a single HTML file with inline styles, scripts and data, subject
203
+ to the Canvas guide's validation and size limits. Publication saves a version in
204
+ LobeHub and returns a public URL; it requires a server with Canvas publishing and
205
+ a compatible runtime. JSON errors retain any saved Canvas ID and version.
206
+
207
+ `--slug <name>` requests the readable prefix for a new deployment. Market adds an
208
+ eight-character suffix; both HTML and Canvas use the same rule. Existing deployments
209
+ retain their address when updated, including older records without a stored label.
210
+ JSON `publicUrl` is the direct hosting URL; `shareUrl` is the LobeHub product share
211
+ page, and `subdomainLabel` is the actual assigned label when the server returns it.
212
+
213
+ `--deployment <id>` overrides the deployment for this run without changing the
214
+ canonical binding. `--new` and `--deployment` cannot be combined. Changing an
215
+ existing artifact's content type requires `--new`.
216
+
217
+ ## Acceptance skill
218
+
219
+ The acceptance skill is maintained in [lobehub/acceptance](https://github.com/lobehub/acceptance).
220
+ Install from the repository's default branch:
221
+
222
+ ```bash
223
+ lh acceptance install
224
+ ```
225
+
226
+ Update the installed skill:
227
+
228
+ ```bash
229
+ lh acceptance update
230
+ ```
231
+
232
+ Publishing reports to LobeHub requires authentication (`lh login`). Without a
233
+ login, acceptance runs locally — see [Local reports](#local-reports).
234
+
235
+ This selects the same source as `npx skills add lobehub/acceptance --skill acceptance`.
236
+ Changes merged into the default branch are available on the next install or
237
+ update, without a tag, GitHub Release, or skill-version bump. Installed files
238
+ remain unchanged until you run an update.
239
+
240
+ `install` skips existing files unless `--force` is passed. `update` replaces the
241
+ materialized files in `.agents/skills/acceptance`, removes stale resources, and
242
+ maintains agent links. The server resolves a commit and downloads the entire
243
+ skill from that snapshot before files are changed. `--json` reports the exact
244
+ source commit and the version declared in `SKILL.md`; that version is a label,
245
+ not the selector for default updates.
246
+
247
+ Use an up-to-date CLI and LobeHub server. Older servers may return `401` during
248
+ installation and need to be upgraded.
249
+
250
+ To select an existing version tag explicitly, use `lh acceptance update --skill-version 0.5.0` (requires the updated CLI and server), or the equivalent
251
+ [tagged skill source](https://github.com/lobehub/acceptance/tree/v0.5.0/skills/acceptance)
252
+ with `npx skills add`. A later `lh acceptance update` without `--skill-version`
253
+ returns to the current default-branch source.
254
+
255
+ ## Local reports
256
+
257
+ A machine that has never signed in renders acceptance reports locally instead
258
+ of publishing them; `lh acceptance preflight --json` reports `"mode": "local"`.
259
+
260
+ ```bash
261
+ lh acceptance run render .acceptances/<subject>/<round> --requirement "<business goal>"
262
+ ```
263
+
264
+ This writes `report.html` beside the rounds: the acceptance page, offline — the
265
+ checklist, evidence, before/after pairs, video chapters and round history,
266
+ rendered from every round of that acceptance. Nothing is uploaded. The reader
267
+ can accept or reject checks and circle regions on screenshots there; **Save
268
+ reviews** downloads the decisions, and the next
269
+ `lh acceptance feedback .acceptances/<subject>` (or `view`) files them as
270
+ `reviews.json` and reports them like hosted feedback.
271
+
272
+ Comments, mentions and shared links need LobeHub. After `lh login`,
273
+ `lh acceptance publish .acceptances/<subject>` publishes the unpublished rounds
274
+ in order into one acceptance and carries the standing review decisions over;
275
+ running it again publishes only newer rounds.
276
+
277
+ The page is built by `apps/workbench` (`bun run --cwd ../workbench build:report`);
278
+ `bun run build` copies it to `dist/acceptance-report.html` when it exists.
279
+
280
+ ## Local Development
281
+
282
+ | Task | Command |
283
+ | ------------------------------------------ | -------------------------- |
284
+ | Run in dev mode | `bun run dev -- <command>` |
285
+ | Build the CLI | `bun run build` |
286
+ | Link `lh`/`lobe`/`lobehub` into your shell | `bun run cli:link` |
287
+ | Remove the global link | `bun run cli:unlink` |
288
+
289
+ - `bun run build` generates `dist/index.js`, plus `dist/acceptance-report.html` when the local report page is built.
290
+ - To make `lh` available in your shell, run `bun run cli:link`.
291
+ - After linking, if your shell still cannot find `lh`, run `rehash` in `zsh`.
292
+
293
+ ## Custom Server URL
294
+
295
+ By default the CLI connects to `https://app.lobehub.com`. To point it at a different server (e.g. a local instance):
296
+
297
+ | Method | Command | Persistence |
298
+ | -------------------- | --------------------------------------------------------------- | ----------------------------------- |
299
+ | Environment variable | `LOBEHUB_SERVER=http://localhost:4000 bun run dev -- <command>` | Current command only |
300
+ | Login flag | `lh login --server http://localhost:4000` | Saved to `~/.lobehub/settings.json` |
301
+
302
+ Priority: `LOBEHUB_SERVER` env var > `settings.json` > default official URL.
303
+
304
+ ## Shell Completion
305
+
306
+ ### Install completion for a linked CLI
307
+
308
+ | Shell | Command |
309
+ | ------ | ------------------------------ |
310
+ | `zsh` | `source <(lh completion zsh)` |
311
+ | `bash` | `source <(lh completion bash)` |
312
+
313
+ ### Use completion during local development
314
+
315
+ | Shell | Command |
316
+ | ------ | -------------------------------------------- |
317
+ | `zsh` | `source <(bun src/index.ts completion zsh)` |
318
+ | `bash` | `source <(bun src/index.ts completion bash)` |
319
+
320
+ - Completion is context-aware. For example, `lh agent <Tab>` shows agent subcommands instead of top-level commands.
321
+ - If you update completion logic locally, re-run the corresponding `source <(...)` command to reload it in the current shell session.
322
+ - Completion only registers shell functions. It does not install the `lh` binary by itself.
323
+
324
+ ## Quick Check
325
+
326
+ ```bash
327
+ which lh
328
+ lh --help
329
+ lh agent <TAB>
330
+ ```
331
+
332
+ ## Tests
333
+
334
+ The default `test` and `test:coverage` scripts run offline unit tests only. Live
335
+ E2E uses a separate config and never replaces or removes your selected CLI home.
336
+ It always runs this checkout's `dist/index.js`, not a globally installed `lh` or
337
+ a caller-supplied `LH_CLI_PATH`.
338
+
339
+ From `apps/cli`, prepare a dedicated test account (never your everyday account):
340
+
341
+ ```bash
342
+ bun run build
343
+ export LOBEHUB_CLI_HOME=.lobehub-e2e
344
+ export LOBEHUB_SERVER=https://your-test-server.example
345
+ node dist/index.js login --server "$LOBEHUB_SERVER"
346
+ node dist/index.js whoami
347
+
348
+ # Explicitly authorize real writes for this test account/server.
349
+ export LOBEHUB_E2E_ALLOW_WRITES=1
350
+ bun run test:e2e e2e/model.e2e.test.ts --testTimeout=60000 --hookTimeout=60000
351
+ ```
352
+
353
+ Without a selected home, server, write opt-in, built CLI, or valid authentication,
354
+ the live setup fails before fixture creation. A directory name does not itself
355
+ isolate server data: sign in with a dedicated test identity. Model tests own a
356
+ temporary provider, including the remote-model clearing case. Other suites may
357
+ create data or consume model credits, so do not run them on a personal account.
358
+ Collection alone (`bunx vitest list --config vitest.e2e.config.mts`) needs no login.
359
+ Signal and VFS tests additionally require their documented Agent ID variables.
360
+ Search fixtures wait up to 60 seconds for asynchronous indexing; a timeout fails
361
+ the suite rather than accepting empty results. The command above supplies a live
362
+ network budget explicitly; this does not change unit-test timeouts or enable retries.
363
+
364
+ ### Native Codex app-server on a connected device
365
+
366
+ A current CLI advertises `codex-app-server-v1` only after its resolved Codex binary
367
+ completes a native app-server handshake. The probe runs once per gateway connection
368
+ (and again after 10 minutes), not once per system-info request. `lh connect capabilities`
369
+ reports that same capability as JSON without logging in, connecting a device, or creating
370
+ a conversation. Desktop gateway connections invoke this command through their bundled
371
+ CLI, so an unrelated global CLI cannot determine support. Missing, incompatible, or
372
+ timed-out binaries do not advertise native support.
373
+
374
+ Codex topics run through `codex exec` unless the user enables the
375
+ **Codex App Server Runtime** Lab. With the Lab on and a capable connection, the server
376
+ runs them through app-server and persists each message's native session and turn IDs.
377
+ These topics keep the `codex exec` recovery: a missing native session is retried fresh
378
+ with the topic transcript.
379
+
380
+ The internal `lh hetero exec --codex-app-server` transport uses a per-operation process
381
+ that owns cancellation and shell identity. This transport rejects unsupported approval
382
+ or sandbox arguments instead of weakening permissions. The richer permission bridge is
383
+ maintained separately.