@task-handoff/thctl 0.0.35

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ TaskHandoff
2
+ Copyright 2026 TaskHandoff
3
+
4
+ This product includes software developed by the TaskHandoff project.
package/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # Control Plane CLI (`thctl`)
2
+
3
+ `thctl` is the command line client for the TaskHandoff Control Plane. It connects to one or more Control Plane deployments, authorizes through the existing Web login, and exposes the same authoritative projections and commands as the Control Plane UI in a scriptable contract.
4
+
5
+ The CLI never owns state: reads consume Control Plane projections, writes go through the shared `@task-handoff/control-plane-client` API layer, and `thctl schema` exports the declared leaf contract (arguments, options, input/output JSON Schema) as the single machine-readable source.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install -g @task-handoff/thctl
11
+ thctl --help
12
+ ```
13
+
14
+ `@task-handoff/thctl` is published by the TaskHandoff runtime release pipeline, so the CLI version matches the server runtime packages (`@task-handoff/server`, `@task-handoff/control-plane`, `@task-handoff/node-agent`). Prereleases are available through the `alpha` and `beta` dist-tags.
15
+
16
+ From a repository checkout:
17
+
18
+ ```bash
19
+ pnpm install
20
+ node bin/thctl.js --help # repository checkout
21
+ pnpm runtime:pack:thctl # build the publishable package
22
+ ```
23
+
24
+ `pnpm exec thctl` is not wired in the workspace root: pnpm does not link a project's own bin, so checkout usage goes through `node bin/thctl.js` (or the packed tarball).
25
+
26
+ ## Profiles
27
+
28
+ A profile is one pinned Control Plane identity. Profiles live in `~/.config/task-handoff/cli` (honoring `XDG_CONFIG_HOME`, overridable through `TASK_HANDOFF_CLI_CONFIG_DIR`).
29
+
30
+ ```bash
31
+ thctl profile add https://control.example.com # first connect pins the identity fingerprint (TOFU)
32
+ thctl profile add http://127.0.0.1:8787 --label local
33
+ thctl profile list
34
+ thctl profile use local
35
+ thctl profile show
36
+ thctl profile trust <label> --yes # re-pin after a verified identity change
37
+ thctl profile remove <label>
38
+ ```
39
+
40
+ - `profiles.json` stores origin, Control Plane ID, signing-key fingerprint, protocol version and the capability snapshot; it never stores secrets.
41
+ - Identity changes are rejected until `profile trust` re-pins the new fingerprint; a normal certificate renewal does not change the fingerprint.
42
+ - The Control Plane must declare the `cliSessions` capability. Servers without it are rejected before login with exit code 14.
43
+
44
+ ## Authorization
45
+
46
+ `thctl login` reuses the Control Plane Web login as an authorization page; the CLI itself never receives the Web session. The approval page is shown to an already signed-in operator, who approves or denies the request, and the CLI exchanges the approval for its own separately revocable `cli` session.
47
+
48
+ ```bash
49
+ thctl login # browser flow: opens /cli/authorize and receives the loopback callback
50
+ thctl login --device # devices without a browser: user code + verification URL, polled with backoff
51
+ thctl whoami
52
+ thctl logout # revokes the CLI session server-side and clears the local credential
53
+ ```
54
+
55
+ - The loopback callback binds `127.0.0.1` on a random port and validates the `state` parameter.
56
+ - The device flow prints the user code and `verificationUriComplete`, then polls the token endpoint; `slow_down` doubles the interval, denial and expiry surface as exit code 5.
57
+ - The session token is stored in `credentials.json` (0600, directory 0700), never in `profiles.json`.
58
+ - CLI sessions appear in the Control Plane session settings and can be revoked there; a revoked session clears the local credential on the next 401.
59
+ - Sessions renew automatically when less than seven days remain.
60
+
61
+ ## Local desktop Control Plane
62
+
63
+ When the desktop app runs its Control Plane without user management (`--auth-mode disabled`), `thctl` connects without any profile setup or Web login:
64
+
65
+ ```bash
66
+ thctl whoami # discovers the local Control Plane, writes the managed `local` profile, mints a local CLI session
67
+ ```
68
+
69
+ - Discovery reads the user-level runtime lock (`${TMPDIR}/task-handoff-control-plane-<uid>.lock`, overridable through `TASK_HANDOFF_CONTROL_PLANE_LOCK_PATH`), checks that the recorded owner process is alive with a matching start identity, takes the loopback host and port, and verifies the signed identity document. Port scanning, LAN addresses and non-loopback origins are never trusted.
70
+ - The first discovery writes a managed profile: label `local` (or an origin-derived label if `local` is taken), `source: local-discovery`, pinned to the presented identity (TOFU), and set as the default only when no default exists. Manual profiles are never overwritten, and a manual profile for the same origin is reused instead.
71
+ - These servers declare `localCliSessions: true` instead of `cliSessions`. That capability allows session minting only on loopback: with no stored credential the CLI calls `POST /api/auth/cli/local` and stores the returned session in `credentials.json` (0600).
72
+ - A disabled Control Plane reached remotely refuses local sessions with exit code 14; run `thctl` on that machine, or enable user management and use `thctl login`.
73
+ - Local sessions belong to the built-in `Local Operator` account (`local-trust` identity, Admin, all nodes). They appear as regular `cli` sessions that can be listed and revoked in the Control Plane, and account creation plus session minting are audited.
74
+ - Local sessions share the 14-day TTL and revocation semantics and are never renewed through `/api/auth/cli/renew`. When the session expires, is revoked, or is rejected with 401, the CLI clears the credential and mints a new session, continuing the current command. `thctl logout` still revokes the server session and clears the credential; the next command mints a fresh local session while the desktop Control Plane is reachable.
75
+ - If the desktop Control Plane moves to a new port, the managed profile converges to the new loopback origin and records the identity change (`profile show --json` exposes `source` and `identityChangedAt`).
76
+ - Once the Control Plane is switched to `authentication: required`, the local endpoint is rejected and `thctl` falls back to the Web/device authorization flow.
77
+
78
+ ## Command surface
79
+
80
+ Global options: `--profile <label>`, `--json`, `--yes`, `--dry-run`, `--config <file>`, `--token-stdin`.
81
+
82
+ | group | commands |
83
+ | --- | --- |
84
+ | `profile` | `add`, `list`, `use`, `show`, `remove`, `trust` |
85
+ | auth | `login`, `logout`, `whoami` |
86
+ | `instance` | `list`, `show`, `create`, `delete`, `start`, `stop`, `restart`, `rename` |
87
+ | `ai-session` | `list`, `show`, `history`, `turns`, `turn`, `timeline`, `turn-timeline`, `create`, `send`, `interrupt`, `approval`, `resume`, `read`, `rename`, `fork`, `close`, `model`, `reasoning`, `queue list`, `queue steer`, `queue retry`, `queue remove`, `queue edit`, `queue reorder` |
88
+ | `app-session` | `list`, `show`, `start`, `stop`, `rename`, `access`, `restart` |
89
+ | `node` | `list`, `show`, `rename`, `create`, `remove`, `check`, `sync-local`, `folders list`, `folders tree`, `folders add`, `folders update`, `folders remove`, `runtimes list`, `runtimes create`, `runtimes update`, `runtimes remove`, `runtimes check`, `docker images`, `image-options`, `settings external-listener show`, `settings external-listener set`, `settings model-relay show`, `settings model-relay set`, `updates jobs`, `updates check`, `updates apply`, `pairing invite`, `pairings list`, `pairings remove`, `connections list`, `connections create`, `connections remove` |
90
+ | `node-join` | `invite`, `status`, `complete` |
91
+ | `story` | `list`, `show`, `create`, `update`, `archive`, `restore`, `remove`, `document update`, `document remove`, `document reorder`, `automation list`, `automation show`, `automation create`, `automation update`, `automation remove`, `automation enable`, `automation disable`, `automation run`, `automation runs` |
92
+ | `trigger` | `list`, `show`, `create`, `update`, `remove`, `run`, `bind`, `unbind`, `apply` |
93
+ | `model` | `list`, `show`, `create`, `copy`, `discover`, `test`, `reorder`, `update`, `sync`, `merge`, `remove`, `node list`, `node create`, `node update`, `node remove`, `node discover`, `node test` |
94
+ | `project` | `list`, `show`, `create`, `update`, `remove` |
95
+ | `image` | `list`, `show`, `create`, `update`, `remove`, `options` |
96
+ | `market` | `catalog`, `refresh` |
97
+ | `env-template` | `list`, `show`, `create`, `remove` |
98
+ | `git-credential` | `list`, `show`, `create`, `update`, `remove`, `assignments list`, `assignments assign`, `assignments unassign` |
99
+ | `chat` | `status`, `bridges list`, `bridges create`, `bridges update`, `bridges start`, `bridges stop`, `bridges remove`, `sessions list`, `sessions show` |
100
+ | `mobile-session` | `list`, `revoke` |
101
+ | `control-plane` | `status`, `settings show`, `settings update`, `diagnostic-logs export` |
102
+ | `cloud` | `show`, `challenge`, `remote-access`, `disconnect` |
103
+ | `proxy` | `invites list`, `invites create`, `invites remove`, `bindings list`, `bindings remove`, `diagnostics`, `pending-claims list`, `pending-claims resume`, `pending-claims remove` |
104
+ | `user` | `list`, `show`, `sessions`, `session-revoke`, `create`, `update`, `access`, `password-reset`, `role list`, `role create`, `role update`, `role remove`, `permission list`, `identity-provider list`, `identity-provider create`, `identity-provider update`, `identity-provider remove`, `external-identity list`, `external-identity approve`, `external-identity reject` |
105
+ | stream | `events` |
106
+ | contract | `schema` |
107
+
108
+ - Data goes to stdout, diagnostics to stderr; `--json` keeps the server wire field names.
109
+ - `--config <file>` carries a JSON request body for commands whose input is too large for flags (write inputs such as `instance create`, `node create`, `project create`, `image create`, `model create`, `chat bridges create`); the file must parse to a JSON object. `--token-stdin` reads a one-time token from stdin (for example `node-join complete`). Secrets are never accepted as positional arguments, so `--config` and `--token-stdin` are the only secret input channels.
110
+ - Write commands require confirmation. Non-TTY callers must pass `--yes`; `--dry-run` prints the request (or the ordered requests of a multi-step write) without sending it.
111
+ - Exit codes: `0` ok, `2` usage, `3` not implemented, `4` confirmation required, `5` not authenticated, `6` forbidden, `7` not found, `8` conflict, `9` rate limited, `10` network, `11` protocol, `12` server, `13` identity, `14` capability missing, `15` cancelled.
112
+ - `thctl schema [group [leaf]] [--format json|md] [--out <file>]` exports the contract; leaves marked `outputMode: json-lines` stream one JSON document per line.
113
+ - `story automation create|update` read the automation payload from `--config <file>`: the file never carries `storyId` (it comes from the argument) — `create` takes `{ actionId, schedule, enabled?, policy? }`, `update` takes any non-empty subset of `{ actionId, schedule, enabled, policy }`.
114
+
115
+ ### Capability gating
116
+
117
+ Management commands are gated by the capabilities the target advertises, and a missing capability only closes that one command domain:
118
+
119
+ - Node-scoped commands (`node check`, `node folders *`, `node runtimes *`, `node docker images`, `node image-options`, `node settings *`, `node updates *`, `node pairing invite`, `node pairings *`, `node connections *`, `node-join *`) query the node's structured capability document from `GET /api/nodes/:id` through the shared `supportsNode*` helpers.
120
+ - Control Plane management commands (`user *`, `control-plane *`, `cloud *`, `proxy *`, `mobile-session *`) query the identity payload's `supportsControlPlane*` helpers (`userManagement`, `customRoles`, `externalIdentityLogin`).
121
+ - A server that predates a route answers with `404`/`405`/`501` without the structured error envelope; the CLI normalizes this to `CLI_CAPABILITY_MISSING` and exits `14`, naming both the command and the capability it required. Login, `whoami`, and commands in domains that are still supported keep working.
122
+ - A protocol-version mismatch is only a warning; it never blocks registration, login, or existing commands.
123
+
124
+ ### Instances
125
+
126
+ ```bash
127
+ thctl instance list --json
128
+ thctl instance show <instanceId> --json
129
+ thctl instance create --config ./instance.json --start
130
+ thctl instance delete <instanceId> --yes
131
+ thctl instance delete <instanceId> --volumes --yes
132
+
133
+ # ./instance.json:POST /api/controlled-instances 的请求体
134
+ # {
135
+ # "nodeId": "node_x",
136
+ # "source": { "type": "local-folder", "path": "/Users/me/project" },
137
+ # "imageSelection": { "imageId": "img_x" },
138
+ # "start": true
139
+ # }
140
+ ```
141
+
142
+ - `create` 的 `runtimeId` 省略时服务端用 `runtime_local_docker`;`nodeId` 省略时按 project/服务端默认节点解析;Docker runtime 必须能从 `environmentSource`、`imageSelection` 或 project 默认镜像解析出镜像,否则 400 `RUNTIME_IMAGE_REQUIRED`。
143
+ - 带 `gitCredentialRetention: "instance-retained"` 的创建要求账号具备 `manage-secrets` 权限,否则退出码 6。
144
+ - 创建返回 `startOutcome`:`not-requested`(body 未要求 start)、`started`(已请求启动,Docker 镜像可能仍在 provisioning)、`failed`(已创建但启动失败,错误在 `startOutcome.error`)。
145
+ - `delete` 的 `deleteVolumes` 恒为布尔值:不带 `--volumes` 发送 `false`(卷保留),带 `--volumes` 发送 `true`;删除未完成时命令以退出码 8 结束,`volumeResults` 在错误详情里,重跑同一命令即可重试。
146
+
147
+ ### Nodes, settings, and access
148
+
149
+ ```bash
150
+ # Node inventory and ownership
151
+ thctl node list --json
152
+ thctl node check <nodeId>
153
+ thctl node folders tree <nodeId> --json
154
+ thctl node runtimes list <nodeId> --json
155
+ thctl node docker images <nodeId> --json
156
+ thctl node settings external-listener show <nodeId>
157
+ thctl node updates check <nodeId> --config ./check.json
158
+ thctl node updates apply <nodeId> --config ./rollout.json --wait
159
+
160
+ # Enroll another machine
161
+ thctl node-join invite --config ./join-invite.json --yes
162
+ thctl node-join status <inviteId>
163
+ thctl node-join complete --config ./join-complete.json --yes
164
+
165
+ # Catalogs and settings
166
+ thctl project create --config ./project.json --yes
167
+ thctl image list --json
168
+ thctl market catalog --json
169
+ thctl model discover --config ./discover.json
170
+ thctl env-template create <instanceId> --config ./env-template.json --yes
171
+ thctl git-credential create --config ./credential.json --yes
172
+ echo "$GIT_TOKEN" | thctl git-credential create --config ./credential.json --token-stdin --yes
173
+ echo "$NEW_PASSWORD" | thctl user password-reset <userId> --token-stdin --yes
174
+ thctl chat status --json
175
+ thctl control-plane settings show --json
176
+ thctl control-plane diagnostic-logs export --out ./diagnostic-logs.tar.gz
177
+ thctl cloud challenge --json
178
+
179
+ # Access management
180
+ thctl user create --config ./user.json --yes
181
+ thctl user role list --json
182
+ thctl user identity-provider list --json
183
+ thctl user external-identity approve <approvalId> --yes
184
+ ```
185
+
186
+ - `node updates apply --wait` polls `updates/jobs` until the rollout reaches a terminal state; an interrupted wait exits `15`.
187
+ - `control-plane diagnostic-logs export` streams the archive to `--out` and never prints the payload to stdout.
188
+ - `user create|update|access|password-reset`, `role *`, `identity-provider *`, and `external-identity *` are each independently gated by `userManagement`, `customRoles`, and `externalIdentityLogin`; losing one does not disable `user list|show|sessions`.
189
+
190
+ ## Event stream
191
+
192
+ ```bash
193
+ thctl events
194
+ thctl events --topic ai.sessions --topic instances
195
+ thctl events --topic ai-sessions --instance <instanceId>
196
+ thctl events --json | jq -c 'select(.topic == "instances")'
197
+ ```
198
+
199
+ `thctl events` subscribes to the existing `/api/events` WebSocket with the CLI session bearer token and writes every event envelope as one JSON line (JSON Lines in both default and `--json` mode).
200
+
201
+ - `--topic` is repeatable; values are protocol topics (for example `ai.sessions`, `app.sessions`, `instances`, `nodes`, `triggers`, `stories`, `models`) or exact event types. The `ai-sessions` and `app-sessions` spellings are accepted as aliases. `--topic` omitted subscribes to `*`.
202
+ - `--instance <instanceId>` scopes the subscription server-side; a scope the account cannot see closes the stream with exit code 6.
203
+ - Transport frames (`streams.hello`, keepalive `pong`) are consumed by the CLI and never printed.
204
+ - The subscription opts into the hierarchical AI Session projection and explicitly disables resource metric snapshots and the high-frequency AI Session transient streams; only authoritative events are printed.
205
+ - Disconnects reconnect with the shared exponential backoff and re-subscribe. Reconnection is snapshot-first: nothing is emitted before the new `streams.hello` handshake completes, and replayed event ids are deduplicated, so consumers never see the same event id twice. The command never falls back to polling.
206
+ - Credential rejection (HTTP 401) clears the stored CLI session and exits 5; an initial connection failure exits 10 instead of retrying forever, while a failure after the first authoritative handshake keeps retrying.
207
+ - `Ctrl+C` closes the stream and exits 0.
208
+
209
+ ## Minimum server version
210
+
211
+ The Control Plane must be a release that declares the `cliSessions` capability in its public identity document and exposes the CLI authorization and session routes (or, for the local desktop Control Plane, declares `localCliSessions` and exposes `POST /api/auth/cli/local`). Older Control Planes are rejected with exit code 14 before any local state is written. The pinned protocol version is recorded per profile as `YYYY-MM-DD` and shown by `thctl profile show`.
package/bin/thctl ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/thctl.js");