@carrieros/cli 0.2.0 → 0.4.0

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.
Files changed (124) hide show
  1. package/README.md +170 -64
  2. package/dist/commands/attach.js +45 -0
  3. package/dist/commands/btw.js +78 -0
  4. package/dist/commands/changes.js +167 -0
  5. package/dist/commands/chat.js +81 -15
  6. package/dist/commands/context.js +200 -0
  7. package/dist/commands/doctor.js +63 -3
  8. package/dist/commands/files.js +84 -23
  9. package/dist/commands/help.js +1 -0
  10. package/dist/commands/history.js +88 -23
  11. package/dist/commands/login.js +31 -7
  12. package/dist/commands/logout.js +1 -0
  13. package/dist/commands/memory.js +162 -0
  14. package/dist/commands/mode-model.js +39 -3
  15. package/dist/commands/modes.js +4 -1
  16. package/dist/commands/permissions.js +77 -0
  17. package/dist/commands/project.js +106 -0
  18. package/dist/commands/repo.js +146 -0
  19. package/dist/commands/repos.js +61 -0
  20. package/dist/commands/review.js +92 -0
  21. package/dist/commands/scope.js +9 -6
  22. package/dist/commands/search.js +92 -0
  23. package/dist/commands/sessions.js +224 -65
  24. package/dist/commands/settings.js +94 -0
  25. package/dist/commands/update.js +229 -0
  26. package/dist/commands/upload.js +204 -31
  27. package/dist/commands/usage.js +213 -17
  28. package/dist/commands/whoami.js +12 -9
  29. package/dist/ide/editor-context.js +275 -0
  30. package/dist/ide/ide-session.js +355 -0
  31. package/dist/ide/tool-host.js +109 -0
  32. package/dist/main.js +26 -1
  33. package/dist/services/api.js +315 -15
  34. package/dist/services/auth-origin.js +20 -0
  35. package/dist/services/chat-stream.js +168 -0
  36. package/dist/services/checkpoints.js +278 -0
  37. package/dist/services/client-tools.js +352 -0
  38. package/dist/services/code-intel.js +243 -0
  39. package/dist/services/code-symbols.js +94 -0
  40. package/dist/services/coding-workflow.js +554 -0
  41. package/dist/services/command-coordinator.js +273 -0
  42. package/dist/services/command-policy.js +434 -0
  43. package/dist/services/config.js +311 -24
  44. package/dist/services/container-runner.js +254 -0
  45. package/dist/services/container-supervisor.js +38 -0
  46. package/dist/services/context.js +296 -23
  47. package/dist/services/device-auth.js +72 -35
  48. package/dist/services/diff.js +196 -0
  49. package/dist/services/env-policy.js +108 -0
  50. package/dist/services/execution-platform.js +30 -0
  51. package/dist/services/file-detect.js +104 -0
  52. package/dist/services/file-resolver.js +199 -0
  53. package/dist/services/file-upload.js +126 -0
  54. package/dist/services/folder-key.js +22 -0
  55. package/dist/services/git-tools.js +429 -0
  56. package/dist/services/glob-match.js +164 -0
  57. package/dist/services/helper-bin.js +85 -0
  58. package/dist/services/ignore-rules.js +189 -0
  59. package/dist/services/instruction-resolver.js +54 -0
  60. package/dist/services/job-helper.js +328 -0
  61. package/dist/services/local-files.js +639 -0
  62. package/dist/services/local-tools.js +937 -0
  63. package/dist/services/login-flow.js +55 -17
  64. package/dist/services/meta.js +3 -1
  65. package/dist/services/mutation-coordinator.js +327 -0
  66. package/dist/services/mutation-groups.js +309 -0
  67. package/dist/services/mutation-recovery.js +159 -0
  68. package/dist/services/mutations.js +679 -0
  69. package/dist/services/open-url.js +68 -0
  70. package/dist/services/output.js +5 -2
  71. package/dist/services/packaged-update.js +403 -0
  72. package/dist/services/packaged.js +39 -0
  73. package/dist/services/permission-mode.js +60 -0
  74. package/dist/services/process-runner.js +412 -0
  75. package/dist/services/project-context.js +298 -0
  76. package/dist/services/redaction.js +201 -0
  77. package/dist/services/result-reconciliation.js +49 -0
  78. package/dist/services/secure-store.js +217 -0
  79. package/dist/services/session-resolver.js +113 -0
  80. package/dist/services/sia.js +51 -0
  81. package/dist/services/supported-runtime.js +59 -0
  82. package/dist/services/task-context.js +212 -0
  83. package/dist/services/task-snapshot.js +38 -0
  84. package/dist/services/tool-result-outbox.js +195 -0
  85. package/dist/services/update.js +311 -0
  86. package/dist/services/workspace-registry.js +310 -0
  87. package/dist/services/workspace.js +580 -0
  88. package/dist/shell/shell-chat.js +1297 -59
  89. package/dist/shell/shell-commands.js +243 -12
  90. package/dist/shell/shell-prompt.js +94 -11
  91. package/dist/shell/shell-renderer.js +8 -20
  92. package/dist/shell/shell-router.js +19 -3
  93. package/dist/shell/shell.js +252 -22
  94. package/dist/shell/task-context-view.js +40 -0
  95. package/dist/types/index.js +3 -1
  96. package/dist/ui/agent-cards.js +111 -0
  97. package/dist/ui/agent-presentation.js +131 -0
  98. package/dist/ui/approval.js +111 -0
  99. package/dist/ui/banner.js +31 -48
  100. package/dist/ui/btw-overlay.js +230 -0
  101. package/dist/ui/change-review.js +334 -0
  102. package/dist/ui/chat-renderer.js +207 -14
  103. package/dist/ui/colors.js +12 -8
  104. package/dist/ui/command-details.js +11 -0
  105. package/dist/ui/command-filter.js +26 -5
  106. package/dist/ui/command-palette.js +44 -14
  107. package/dist/ui/command-registry.js +92 -10
  108. package/dist/ui/command-review.js +187 -0
  109. package/dist/ui/composer-layout.js +48 -1
  110. package/dist/ui/conversation.js +450 -0
  111. package/dist/ui/interrupt.js +35 -0
  112. package/dist/ui/live.js +4 -2
  113. package/dist/ui/markdown.js +63 -9
  114. package/dist/ui/message.js +14 -31
  115. package/dist/ui/screen-prompt.js +181 -0
  116. package/dist/ui/screen.js +19 -11
  117. package/dist/ui/select.js +191 -29
  118. package/dist/ui/sia-qa.js +213 -0
  119. package/dist/ui/task-context-card.js +99 -0
  120. package/dist/ui/text-prompt.js +74 -0
  121. package/dist/ui/trust.js +88 -0
  122. package/dist/ui/ui.js +27 -1
  123. package/package.json +18 -4
  124. package/dist/ui/activity.js +0 -77
package/README.md CHANGED
@@ -1,16 +1,20 @@
1
1
  # Carrier OS CLI
2
2
 
3
- A Windows-first command-line client for the Carrier OS **public `/v1` API**. It
4
- proves the full developer workflow end-to-end:
3
+ A command-line client for the Carrier OS **public `/v1` API**, covering the
4
+ workflow end-to-end:
5
5
 
6
6
  ```
7
- Developer Portal → Generate API Key → Install CLI → Configure Key
8
- → Chat → Sessions → Files → Usage
7
+ Install CLI → cos login (browser) → Chat → Sessions → Files → Memory → Usage
9
8
  ```
10
9
 
11
- This is a **Proof of Concept**. It consumes the existing public API exactly like
12
- any third-party developer would — **no backend logic is duplicated**. Every
13
- command is a thin, typed wrapper over an endpoint that already exists.
10
+ Sign-in is a browser round trip, not a pasted key: `cos login` opens your
11
+ Carrier OS account, you approve the terminal once, and the CLI keeps its own
12
+ short-lived credentials. It is the same account you use on carrieros.ai — there
13
+ is no separate developer-platform login to create.
14
+
15
+ It consumes the public API exactly like any third-party developer would — **no
16
+ backend logic is duplicated**. Every command is a thin, typed wrapper over an
17
+ endpoint that already exists.
14
18
 
15
19
  ---
16
20
 
@@ -24,36 +28,33 @@ cos # primary — opens the interactive Carrier OS shell
24
28
  carrieros # full-name alias (identical)
25
29
  ```
26
30
 
27
- ### Beta (current) — install from the tarball
28
-
29
- Until the package is published, distribute the packed tarball. Build it, then
30
- install it globally exactly as a published package would install:
31
-
32
31
  ```bash
33
- npm run build
34
- npm pack # → carrieros-cli-0.1.0.tgz
35
- npm install -g carrieros-cli-0.1.0.tgz
32
+ npm install -g @carrieros/cli
36
33
 
37
- carrieros # or: cos
34
+ cos # or: carrieros
38
35
  ```
39
36
 
40
- ### Public release (future)
41
-
42
- Once `@carrieros/cli` is published, developers install it the same way as Claude
43
- Code / Vercel CLI:
37
+ ### Windows installer (no Node.js needed)
44
38
 
45
- ```bash
46
- npm install -g @carrieros/cli
39
+ Download `CarrierOS-Setup-<version>-x64.exe` from https://carrieros.ai/cli and
40
+ run it. It installs for your user only (no administrator rights), adds `cos` to
41
+ your PATH, and keeps your settings and sign-in in `%APPDATA%\CarrierOS` across
42
+ upgrades. Open a new terminal and run `cos`. Update with `cos update`;
43
+ uninstall from Settings → Apps. Details: [docs/PACKAGING.md](docs/PACKAGING.md).
47
44
 
48
- carrieros # or: cos
49
- ```
45
+ ### From source
50
46
 
51
- Publishing is a **single command** — no refactoring needed:
47
+ Working on the CLI itself, or testing an unreleased change:
52
48
 
53
49
  ```bash
54
- npm publish --access public
50
+ npm run build
51
+ npm link # `cos` now runs your working copy
55
52
  ```
56
53
 
54
+ `npm link` is preferable to `npm pack` + `npm install -g <tarball>` during
55
+ development: the tarball installs a **frozen copy**, so a rebuild does not
56
+ reach the installed command and you end up debugging stale code.
57
+
57
58
  ### Update
58
59
 
59
60
  Upgrade to the latest published version at any time:
@@ -98,19 +99,29 @@ node dist/main.js <command>
98
99
 
99
100
  ## How to use Carrier OS CLI
100
101
 
101
- **Prerequisites:** [Node.js](https://nodejs.org) **18+** (`node -v`) and a Carrier
102
- OS **API secret key** (`carrier_sk_…`) from the Developer Portal
103
- (**Projects → API keys**).
102
+ **Prerequisites:** [Node.js](https://nodejs.org) **18+** (`node -v`) and a
103
+ Carrier OS account — the same one you use on carrieros.ai. Nothing to generate
104
+ beforehand.
104
105
 
105
106
  ### 1. Sign in (one-time setup)
106
107
 
107
- Authenticate once — your key is stored on your machine
108
- (`%APPDATA%/CarrierOS/config.json`, or `~/.carrieros/config.json`), never a JWT:
109
-
110
108
  ```bash
111
- cos login # paste carrier_sk_… when prompted
109
+ cos login
112
110
  ```
113
111
 
112
+ Your browser opens on your Carrier OS account, you approve this terminal, and
113
+ the CLI stores the session it is issued
114
+ (`%APPDATA%/CarrierOS/config.json`, or `~/.carrieros/config.json`, written
115
+ `0600`). The browser never sees those credentials and the CLI never sees your
116
+ password.
117
+
118
+ Approving is a spending decision — a CLI turn draws on the same credits the
119
+ website does — so the page names the account and lists what the terminal will
120
+ be able to do before you confirm.
121
+
122
+ The session refreshes itself. You will not be asked again unless you run
123
+ `cos logout` or the session is revoked.
124
+
114
125
  Pointing at a local / self-hosted API instead of production
115
126
  (`https://api.carrieros.ai/v1`)? Pass `--url` once:
116
127
 
@@ -121,8 +132,8 @@ cos login --url http://localhost:5000/v1
121
132
  Confirm the setup:
122
133
 
123
134
  ```bash
124
- cos doctor # config, connectivity, key checks
125
- cos whoami # workspace / project / account
135
+ cos doctor # config, connectivity, session checks
136
+ cos whoami # signed-in account
126
137
  ```
127
138
 
128
139
  ### 2. Open the interactive shell
@@ -141,17 +152,90 @@ cos
141
152
 
142
153
  ❯ /model # switch the AI model (arrow-key picker)
143
154
  ❯ /mode # switch the Carrier mode (arrow-key picker)
155
+ ❯ /websearch # search the web on your next message
144
156
  ❯ /help # browse every command (arrow-navigable menu)
145
157
  ```
146
158
 
159
+ **Web search** is a capability of chat, not a separate mode. Three ways in:
160
+
161
+ ```
162
+ ❯ /websearch # arm the NEXT message, then it lapses
163
+ ❯ /websearch latest OpenAI news # search right now, changing nothing
164
+ ❯ /websearch on # standing preference until /websearch off
165
+ ```
166
+
167
+ A searching turn shows its phases, then cites what it read:
168
+
169
+ ```
170
+ ❯ /websearch
171
+ ✓ Web search enabled
172
+
173
+ Scope your next message
174
+ Mode live web
175
+
176
+ ❯ what shipped in the latest node lts?
177
+ ● Understanding your request
178
+ ● Searching the web
179
+ ● Reading sources
180
+ ⠹ Synthesizing answer…
181
+
182
+ ● Node.js 24 became Active LTS in October…
183
+
184
+ Sources · 6
185
+
186
+ [1] BBC
187
+ Trump gives Iran 10 days to respond
188
+ bbc.com
189
+
190
+ [2] Reuters
191
+ Latest developments in Iran talks
192
+ reuters.com
193
+
194
+ + 2 more · /sources
195
+
196
+ ✓ Web search · 6 sources · 3.2s
197
+ ```
198
+
199
+ `/sources` prints the full list with URLs; `/open 2` opens one in your browser.
200
+
201
+ **Conversations are numbered, not UUIDs.** `/sessions` prints an ordered list and
202
+ every session command takes that number — ids still work everywhere for scripting:
203
+
204
+ ```
205
+ ❯ /sessions
206
+ 1 Debugging the auth flow 12 msgs · 2h ago
207
+ 2 ► AWS outage research 5 msgs · 1d ago
208
+
209
+ ❯ /session 1 # continue #1
210
+ ❯ /history 2 # transcript of #2
211
+ ❯ /session delete 2 # asks before deleting
212
+ ❯ /context # what your next message is sent with
213
+ ```
214
+
215
+ **Turn shaping** — `/fast` trades refinement for latency; `/hipwr` runs High
216
+ Power's 4-pass pipeline (expansion → hardening → architecture → finalization).
217
+ High Power only applies to the `auto`, `summary`, `reasoning` and `research`
218
+ modes, and your workspace admin can disable it entirely.
219
+
220
+ Every active capability shows in the footer, so you always know what you're
221
+ about to send:
222
+
223
+ ```
224
+ ‖ Standard chat · Reasoning · GPT-5.2 · Fast · HIPWR · 🌐 Websearch
225
+ ```
226
+
147
227
  **Slash commands** (type `/` to filter them live):
148
228
 
149
229
  | Command | Does |
150
230
  |---|---|
151
231
  | `/model` · `/models` | switch / list provider models (GPT, Grok, Claude, …) |
152
232
  | `/mode` · `/modes` | switch / list Carrier modes (general, code, research, …) |
153
- | `/sessions` · `/session use [id]` · `/session delete <id>` | manage conversations |
154
- | `/history [id]` · `/clear` | print a transcript · start a fresh session |
233
+ | `/websearch [query\|on\|off\|auto\|status]` | arm the next message · search now · set the standing preference |
234
+ | `/sources` · `/open <n>` | sources from the last search · open one in the browser |
235
+ | `/fast [on\|off]` · `/hipwr [on\|off]` | fast mode (quicker) · High Power (4-pass refinement) |
236
+ | `/new [title]` · `/sessions` | start a conversation · list them, numbered |
237
+ | `/session <n>` · `/session delete <n>` | continue #n · delete #n (asks first) |
238
+ | `/history [n]` · `/context` | transcript · what your next message is sent with |
155
239
  | `/upload <file>` · `/files` | add + list context files |
156
240
  | `/whoami` · `/usage` · `/doctor` | account · usage · diagnostics |
157
241
  | `/login` · `/logout` · `/version` · `/help` · `/exit` | account · info · quit |
@@ -169,7 +253,7 @@ cos sessions # list conversations
169
253
  cos history # transcript of the active session
170
254
  cos upload ./report.pdf # upload + index a file
171
255
  cos usage # requests, tokens, estimated cost
172
- cos logout # remove the key from this machine
256
+ cos logout # remove saved CLI credentials from this machine
173
257
  ```
174
258
 
175
259
  ---
@@ -178,21 +262,27 @@ cos logout # remove the key from this machine
178
262
 
179
263
  | Command | Endpoint(s) reused | Purpose |
180
264
  |---|---|---|
181
- | `login [key] [--url]` | `POST /v1/auth/verify` | Store the secret key (only after it verifies) |
182
- | `logout` | — | Remove the stored key + session |
183
- | `whoami` | `POST /v1/auth/verify` | Show workspace / project / account |
265
+ | `login [--url] [--platform]` | `POST /cli/auth/device/{code,token}` | User-owned browser device authorization; stores the issued CLI session |
266
+ | `logout` | `POST /platform/auth/cli/logout` | Revoke the session server-side and clear it locally |
267
+ | `whoami` | `POST /v1/auth/verify` | Show your signed-in account; `--details` includes API scope |
184
268
  | `version` | `GET /v1/health` | CLI + API versions |
185
- | `doctor` | `GET /v1/health`, `POST /v1/auth/verify` | Config, connectivity, key checks |
269
+ | `doctor` | `GET /v1/health`, `POST /v1/auth/verify` | Config, connectivity, session checks |
186
270
  | *(no command)* | `POST /v1/chat` | **Default** — the interactive Carrier OS shell |
187
271
  | `chat` | `POST /v1/chat` | Focused chat REPL with a persistent session |
188
272
  | `models` | `GET /v1/models/chat` | List provider models (GPT, Grok, Claude, …) |
189
273
  | `model [id]` | — | Set the provider model (or `auto`); picker if no id |
190
274
  | `modes` | `GET /v1/models` | List Carrier modes (general, code, research, …) |
191
275
  | `mode [id]` | — | Set the Carrier mode; picker if no id |
192
- | `sessions` | `GET /v1/conversations` | List conversations |
193
- | `session use [id]` | `GET /v1/sessions/:id` | Switch active session |
194
- | `session delete <id>` | `DELETE /v1/sessions/:id` | Delete a session |
195
- | `history [id]` | `GET /v1/sessions/:id/messages` | Print a transcript |
276
+ | `websearch [on\|off\|auto]` | — | Live web search for chat turns; shows state if no arg |
277
+ | `fast [on\|off]` | — | Fast mode — shorter pipeline, quicker replies |
278
+ | `hipwr [on\|off]` | — | High Power — 4-pass refinement (admin-gated) |
279
+ | `new [title]` | `POST /v1/sessions` (only with a title) | Start a conversation |
280
+ | `sessions` | `GET /v1/conversations` | Numbered list of conversations |
281
+ | `session <n\|id>` | `GET /v1/sessions/:id` | Continue that conversation |
282
+ | `session use [n\|id]` | `GET /v1/sessions/:id` | Same — kept for compatibility |
283
+ | `session delete <n\|id>` | `DELETE /v1/sessions/:id` | Delete (asks first) |
284
+ | `history [n\|id]` | `GET /v1/sessions/:id/messages` | Print a transcript |
285
+ | `context` | `GET /v1/sessions/:id` | What the next message is sent with |
196
286
  | `clear` | — | Start a fresh session (drops the local pointer) |
197
287
  | `upload <file>` | `POST /v1/files` + `…/:id/process` | Upload and index a file |
198
288
  | `files` | — (local) | List files uploaded from this machine |
@@ -234,8 +324,9 @@ src/
234
324
  `data`, or throws a typed `ApiError` carrying the server's `{code, message}`.
235
325
  Adding an endpoint = adding one method.
236
326
  - **Single disk boundary.** `ConfigStore` owns `%APPDATA%/CarrierOS/config.json`
237
- (falls back to `~/.carrieros/config.json`). It stores **only** the secret key,
238
- the active session id, a cached scope, and recent uploads — **never a JWT**.
327
+ (falls back to `~/.carrieros/config.json`, written `0600`). It stores the
328
+ CLI's own access/refresh pair, the active session id, a cached scope, and
329
+ recent uploads — never a main-site cookie, and never your password.
239
330
  - **Dependency injection.** Every command receives a `CommandContext`
240
331
  (`config`, `client()`, `requireAuth()`), so commands are thin and don't reach
241
332
  for globals. `requireAuth()` centralizes the "not logged in" guard.
@@ -244,7 +335,7 @@ src/
244
335
  - **Strong typing.** `strict` TypeScript with `noUnusedLocals/Parameters`; the
245
336
  entire `/v1` contract is typed in `types/index.ts`.
246
337
  - **Windows-first, clean UX.** `chalk` colors, `ora` spinners, `@inquirer/prompts`
247
- for the masked key prompt and session picker, and a small built-in
338
+ for interactive selections and the session picker, and a small built-in
248
339
  Markdown→ANSI renderer (no markdown dependency).
249
340
 
250
341
  Streaming is **simulated**: the API returns the full response, which the CLI
@@ -256,22 +347,23 @@ streaming would require a backend change.
256
347
  ## Testing steps
257
348
 
258
349
  Prerequisites: the API running locally (`npm run dev` in `api.carrieros.ai`,
259
- default `http://localhost:5000`) and a `carrier_sk_` secret key from the
260
- Developer Portal (Projects → API keys).
350
+ default `http://localhost:5000`) and the main site running (default
351
+ `http://localhost:3000`) so the browser step has a page to land on. Point the
352
+ API at it with `CLI_AUTHORIZE_URL`, or set `FRONTEND_URL` and let the API append
353
+ `/cli/authorize`.
261
354
 
262
355
  ```bash
263
356
  cd carrieros-cli
264
357
  npm install && npm run build
265
358
 
266
- # Connectivity (no key needed)
267
- node dist/main.js login --url http://localhost:5000/v1
268
- node dist/main.js doctor # ✓ API reachable, ⚠ key not set
359
+ # Connectivity (no session needed)
360
+ node dist/main.js doctor # ✓ API reachable, ⚠ not signed in
269
361
  node dist/main.js version # CLI + API versions
270
362
 
271
- # Auth
272
- node dist/main.js login # paste carrier_sk_… → ✓ Logged in
273
- node dist/main.js whoami # workspace / project / account
274
- node dist/main.js doctor # now: ✓ Key valid
363
+ # Auth — opens the browser, approve there, the CLI finishes on its own
364
+ node dist/main.js login --url http://localhost:5000/v1
365
+ node dist/main.js whoami # signed-in account
366
+ node dist/main.js doctor # now: ✓ signed in
275
367
 
276
368
  # Chat + sessions
277
369
  node dist/main.js models # list Carrier modes
@@ -285,21 +377,35 @@ node dist/main.js upload ./somefile.pdf
285
377
  node dist/main.js files
286
378
  node dist/main.js usage
287
379
 
288
- node dist/main.js logout # key removed from this machine
380
+ node dist/main.js logout # saved CLI credentials removed from this machine
289
381
  ```
290
382
 
291
383
  **Negative checks**
292
384
 
293
385
  ```bash
294
386
  node dist/main.js usage # (logged out) → "Run `carrieros login` first."
295
- node dist/main.js login carrier_sk_bad # → "Invalid API key. (INVALID_API_KEY)"
387
+ node dist/main.js login --url http://localhost:1/v1 # → clean NETWORK_ERROR
296
388
  node dist/main.js login --url http://localhost:1/v1 && node dist/main.js doctor # → clean NETWORK_ERROR
297
389
  ```
298
390
 
299
391
  ---
300
392
 
301
- ## Not in this POC
393
+ ## Scope and current limitations
394
+
395
+ The CLI includes a repository-aware coding workflow. It can inspect a selected
396
+ repository, read files, propose approval-gated edits, and run separately
397
+ approved validation commands through its configured executor. File changes and
398
+ commands remain subject to the repository trust and review gates. This does not
399
+ guarantee that the agent can diagnose or fix every coding task, and a fresh
400
+ end-to-end live-model acceptance is still required for the current release.
401
+
402
+ The CLI does not provide multi-agent orchestration, an SDK, IDE integration,
403
+ plugins, or a marketplace. Native Windows executor acceptance has not yet been
404
+ completed. Browser sign-in and self-update are available through `cos login`
405
+ and `cos update`.
406
+
407
+ ### Advanced API scope
408
+
409
+ New `cos login` sessions belong directly to your CarrierOS website user and do not require a Developer Platform account, workspace, project, or API key. This checkout includes user-owned consumers for conversations, chat/streaming, files, supported memory reads, tools, models, usage and Admin attribution. These require the corresponding backend ownership migration and updated server; updating the CLI alone does not enable them. Unaudited `/search` and `/prompts` endpoints still return `CLI_USER_SESSION_NOT_ENABLED`. See the backend `docs/architecture/CLI_USER_DEVICE_SESSIONS.md` for verification and deployment limitations. Existing legacy sessions continue using their original validated scope and refresh endpoint; they are not automatically converted.
302
410
 
303
- No browser OAuth · no billing · no marketplace · no plugins · no agents · no SDK ·
304
- no IDE integration · no repo awareness · no multi-agent · no auto-updates · no
305
- `.exe` installers.
411
+ For existing legacy/API credentials only, use `cos whoami --details`, `cos workspace list`, `cos workspace use <name-or-id>`, or `cos project use <name-or-id>` only when you need a different API scope. Switching workspaces automatically selects its default project. These commands do not select a local repository: use `/repo` or `/repos` for that. Local instruction files resolve from the selected repository root. Existing CLI settings remain user-level; API scope selection does not change their location. Project environment labels describe API projects; `CARRIEROS_API_URL` separately selects the backend endpoint.
@@ -0,0 +1,45 @@
1
+ import { errorLine, info, line, success } from "../services/output.js";
2
+ import { c } from "../ui/colors.js";
3
+ /**
4
+ * `cos attach [file]` — attach a previously-uploaded file to the conversation so
5
+ * the next chat includes it. Matches by filename or file id; defaults to the most
6
+ * recent upload. Thin client: it only flips a local attachment flag (the file_id
7
+ * rides along on the next /v1/chat) — no upload, no backend change.
8
+ */
9
+ export function registerAttach(program, ctx) {
10
+ program
11
+ .command("attach")
12
+ .description("Attach a previously-uploaded file to the conversation")
13
+ .argument("[file]", "filename or id of an upload (defaults to the most recent)")
14
+ .action((fileArg) => {
15
+ const uploads = ctx.config.get("uploads") ?? [];
16
+ if (uploads.length === 0) {
17
+ errorLine("No uploads yet. Upload one with `cos upload <file>`.");
18
+ process.exitCode = 1;
19
+ return;
20
+ }
21
+ let target = uploads[0]; // most recent
22
+ if (fileArg) {
23
+ const q = fileArg.toLowerCase();
24
+ const found = uploads.find((u) => u.file_id === fileArg ||
25
+ u.file_id.startsWith(fileArg) ||
26
+ u.filename.toLowerCase() === q);
27
+ if (!found) {
28
+ errorLine(`No upload matches "${fileArg}". Run \`cos files\` to see your uploads.`);
29
+ process.exitCode = 1;
30
+ return;
31
+ }
32
+ target = found;
33
+ }
34
+ if (ctx.attachedFileIds.includes(target.file_id)) {
35
+ info(`${target.filename} is already attached.`);
36
+ return;
37
+ }
38
+ ctx.attachFile(target.file_id);
39
+ line();
40
+ success(`Attached ${target.filename}`);
41
+ line();
42
+ line(" " + c.dim("Ready to chat about it."));
43
+ line();
44
+ });
45
+ }
@@ -0,0 +1,78 @@
1
+ import { ApiError } from "../services/api.js";
2
+ import { errorLine, line } from "../services/output.js";
3
+ import { withSpinner } from "../services/spinner.js";
4
+ import { showBtwPanel } from "../ui/btw-overlay.js";
5
+ import { c } from "../ui/colors.js";
6
+ /**
7
+ * `/btw <question>` — a side question about the current conversation.
8
+ *
9
+ * Answered from the conversation's context and shown in a temporary panel. It
10
+ * is NOT a chat turn: nothing is written to the session, which is why it calls
11
+ * POST /v1/sessions/:id/ask rather than /v1/chat (that endpoint always persists
12
+ * both turns).
13
+ *
14
+ * Everything the normal chat path adds — model/mode selection, attachments,
15
+ * web search, fast mode, HIPWR — is deliberately absent from the request. The
16
+ * backend route has no access to any of it either, so a side question cannot
17
+ * quietly become a real one.
18
+ */
19
+ export async function askSideQuestion(ctx, client, question,
20
+ /**
21
+ * True while a main turn is rendering. The turn owns the transient region for
22
+ * its word-by-word reveal, so the answer is COMMITTED to the transcript
23
+ * instead of shown as a dismissible panel — two owners of that region would
24
+ * overwrite each other. It stays visually distinct either way.
25
+ */
26
+ inlineOnly = false) {
27
+ const trimmed = question.trim();
28
+ if (!trimmed) {
29
+ errorLine("Usage: /btw <question>");
30
+ line(" " + c.dim("Ask about this conversation without adding to it, e.g."));
31
+ line(" " + c.cmd("/btw which file did we decide on?"));
32
+ return;
33
+ }
34
+ const sessionId = ctx.config.get("sessionId");
35
+ if (!sessionId) {
36
+ errorLine("No active conversation to ask about.");
37
+ line(" " + c.dim("Send a message first, or pick one with ") + c.cmd("/sessions") + c.dim("."));
38
+ return;
39
+ }
40
+ // Echo the side question so the transcript shows what was asked, distinct
41
+ // from a normal turn's "❯ message".
42
+ line();
43
+ line(" " +
44
+ c.magic("↳ BTW: ") +
45
+ c.dim(trimmed) +
46
+ // Without a spinner (see below) this is the only sign it is working.
47
+ (inlineOnly ? c.dim(" · thinking…") : ""));
48
+ try {
49
+ // No spinner while a main turn is running. Its activity timeline repaints
50
+ // the transient region every 80ms and so does withSpinner — two writers
51
+ // alternating in the same region is a visible flicker for the whole
52
+ // request. The committed "↳ BTW:" line above already shows it is in flight.
53
+ const result = inlineOnly
54
+ ? await client.askAboutSession(sessionId, trimmed)
55
+ : await withSpinner(c.dim("By the way…"), () => client.askAboutSession(sessionId, trimmed));
56
+ await showBtwPanel({ answer: result.answer, note: `Answered by ${result.model}.` }, { commit: inlineOnly });
57
+ }
58
+ catch (err) {
59
+ // A failed aside must never read like a failed conversation — say plainly
60
+ // that the conversation is untouched, and let them carry on.
61
+ const message = err instanceof ApiError
62
+ ? err.code === "NETWORK_ERROR"
63
+ ? "Could not reach the API."
64
+ : err.message
65
+ : "Unable to answer this side question.";
66
+ await showBtwPanel({ answer: null, error: message }, { commit: inlineOnly });
67
+ }
68
+ }
69
+ /** `cos btw <question...>` — the same side question outside the shell. */
70
+ export function registerBtw(program, ctx) {
71
+ program
72
+ .command("btw")
73
+ .description("Ask a quick side question without adding it to the conversation")
74
+ .argument("[question...]", "what to ask about the current conversation")
75
+ .action(async (words) => {
76
+ await askSideQuestion(ctx, ctx.requireAuth(), (words ?? []).join(" "));
77
+ });
78
+ }
@@ -0,0 +1,167 @@
1
+ import crypto from "node:crypto";
2
+ import { confirm } from "@inquirer/prompts";
3
+ import { readJournal } from "../services/checkpoints.js";
4
+ import { activeRepository, inWorkspaceMode, listRepositories, resolveRepository } from "../services/workspace-registry.js";
5
+ import { APPROVAL_TIMEOUT_MS, MutationError, applyPlan, planMutation } from "../services/mutations.js";
6
+ import { errorLine, line, timeAgo } from "../services/output.js";
7
+ import { renderGroup } from "../ui/change-review.js";
8
+ import { c } from "../ui/colors.js";
9
+ import { approveInScreen, inScreen } from "../ui/screen-prompt.js";
10
+ import { sectionHeader } from "../ui/ui.js";
11
+ /**
12
+ * `cos changes` and `cos undo` — the local record of approved file changes.
13
+ *
14
+ * Both read the change journal the CLI keeps in its own app-data folder. Undo
15
+ * is itself a change: it is planned, shown as a diff and approved exactly like
16
+ * one the model proposed, and it refuses when the file has moved on since.
17
+ */
18
+ export function registerChanges(program, ctx) {
19
+ program
20
+ .command("changes")
21
+ .description("List file changes Carrier OS applied in this project")
22
+ .action(() => showChanges());
23
+ program
24
+ .command("undo")
25
+ .argument("[operation]", "operation id to undo (defaults to the latest)")
26
+ .option("--repo <repository>", "undo in a named repository instead of the active one")
27
+ .description("Undo the latest file change Carrier OS applied")
28
+ .action(async (operation, options) => {
29
+ let client;
30
+ try {
31
+ client = ctx.config.isAuthenticated ? ctx.requireAuth() : undefined;
32
+ }
33
+ catch {
34
+ client = undefined;
35
+ }
36
+ await runUndo(client, operation, options?.repo);
37
+ });
38
+ }
39
+ const VERB = {
40
+ create_file: "created",
41
+ write_file: "overwrote",
42
+ edit_file: "edited",
43
+ delete_file: "deleted",
44
+ revert_change: "reverted"
45
+ };
46
+ function entryLines(e, indent) {
47
+ const state = e.status === "ROLLED_BACK" ? c.warn("undone") : e.status === "FAILED" ? c.err("failed") : c.ok("applied");
48
+ line(indent + state + " " + c.value(VERB[e.action] ?? e.action) + " " + c.file(e.path) +
49
+ c.dim(` +${e.added} −${e.removed} · ${timeAgo(e.created_at)}`));
50
+ line(indent + " " + c.dim(e.operation_id) + (e.reverts ? c.dim(` (undid ${e.reverts})`) : ""));
51
+ }
52
+ /**
53
+ * The change journal.
54
+ *
55
+ * Each repository keeps its own journal, and the list says so rather than
56
+ * merging them: two repositories can hold the same relative path, and an undo
57
+ * only ever applies within one repository, so a single flat list would invite
58
+ * exactly the mistake the split prevents.
59
+ */
60
+ export function showChanges(limit = 20) {
61
+ const repositories = inWorkspaceMode() ? listRepositories() : [activeRepository()];
62
+ const groups = repositories
63
+ .map((repo) => ({ repo, entries: readJournal(repo.root).slice(-limit).reverse() }))
64
+ .filter((g) => g.entries.length > 0);
65
+ line(sectionHeader("Changes"));
66
+ if (groups.length === 0) {
67
+ line(" " + c.dim(inWorkspaceMode() ? "No file changes have been applied in this workspace." : "No file changes have been applied in this project."));
68
+ line();
69
+ return;
70
+ }
71
+ const multi = inWorkspaceMode();
72
+ for (const g of groups) {
73
+ if (multi) {
74
+ line(" " + c.title(g.repo.name) + (g.repo.id === activeRepository().id ? c.dim(" (active)") : ""));
75
+ for (const e of g.entries)
76
+ entryLines(e, " ");
77
+ line();
78
+ }
79
+ else {
80
+ for (const e of g.entries)
81
+ entryLines(e, " ");
82
+ }
83
+ }
84
+ if (!multi)
85
+ line();
86
+ line(" " + c.dim("Undo the latest with ") + c.cmd("/undo") + c.dim(", or a specific one with ") + c.cmd("/undo <operation id>"));
87
+ if (multi) {
88
+ line(" " + c.dim("Undo in another repository with ") + c.cmd("/undo --repo <name>") + c.dim(" — never across repositories."));
89
+ }
90
+ line();
91
+ }
92
+ /**
93
+ * Undo one applied change, with the same diff-and-approve step as any change.
94
+ *
95
+ * The repository is resolved FIRST and explicitly. `/undo` means "the latest
96
+ * change in the active repository"; undoing one somewhere else takes
97
+ * `--repo <name>`, so a change in another repository is never undone because it
98
+ * happened to be the most recent thing anywhere.
99
+ */
100
+ export async function runUndo(client, operationId, repository) {
101
+ const id = `undo_${crypto.randomBytes(12).toString("hex")}`;
102
+ let handle;
103
+ try {
104
+ handle = repository ? resolveRepository(repository) : activeRepository();
105
+ }
106
+ catch (err) {
107
+ errorLine(err.message);
108
+ return;
109
+ }
110
+ let plan;
111
+ try {
112
+ plan = planMutation({
113
+ tool_call_id: id,
114
+ name: "revert_change",
115
+ arguments: {
116
+ operation_id: operationId?.trim() || undefined,
117
+ repository: repository ? handle.name : undefined,
118
+ reason: "Undo requested with /undo."
119
+ }
120
+ });
121
+ }
122
+ catch (err) {
123
+ const e = err;
124
+ line();
125
+ line(" " + c.warn("⊘") + " " + c.dim(e.message));
126
+ line();
127
+ return;
128
+ }
129
+ for (const l of renderGroup([plan]))
130
+ line(l);
131
+ let approved;
132
+ if (inScreen()) {
133
+ approved = (await approveInScreen({ question: "Undo this change?", timeoutMs: APPROVAL_TIMEOUT_MS })) === "approve";
134
+ }
135
+ else if (process.stdin.isTTY) {
136
+ try {
137
+ approved = await confirm({ message: "Undo this change?", default: false });
138
+ }
139
+ catch {
140
+ approved = false;
141
+ }
142
+ }
143
+ else {
144
+ approved = false; // nobody to ask — never undo unattended
145
+ }
146
+ if (!approved) {
147
+ line(" " + c.warn("⊘") + " " + c.dim("Not undone — nothing changed."));
148
+ line();
149
+ return;
150
+ }
151
+ try {
152
+ const applied = applyPlan(plan);
153
+ line(" " + c.ok("✓") + " " + c.value(`Restored ${applied.rel}`) + c.dim(` (undid ${plan.reverts})`));
154
+ line();
155
+ // The server audit is best-effort and metadata-only; the undo already happened.
156
+ if (client && plan.reverts && /^ct_/.test(plan.reverts)) {
157
+ await client
158
+ .recordMutationAudit({ operation_id: plan.reverts, status: "ROLLED_BACK", checkpoint_id: applied.checkpointId })
159
+ .catch(() => undefined);
160
+ }
161
+ }
162
+ catch (err) {
163
+ const e = err instanceof MutationError ? err : new MutationError("WRITE_FAILED", err.message);
164
+ line(" " + c.err("✗") + " " + c.value(e.message));
165
+ line();
166
+ }
167
+ }