@carrieros/cli 0.2.0 → 0.3.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.
- package/README.md +142 -57
- package/dist/commands/attach.js +45 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +80 -14
- package/dist/commands/context.js +160 -0
- package/dist/commands/doctor.js +46 -1
- package/dist/commands/files.js +84 -23
- package/dist/commands/help.js +1 -0
- package/dist/commands/history.js +88 -23
- package/dist/commands/login.js +31 -7
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +39 -3
- package/dist/commands/modes.js +4 -1
- package/dist/commands/project.js +106 -0
- package/dist/commands/repo.js +146 -0
- package/dist/commands/repos.js +61 -0
- package/dist/commands/review.js +92 -0
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +219 -65
- package/dist/commands/settings.js +87 -0
- package/dist/commands/update.js +159 -0
- package/dist/commands/upload.js +204 -31
- package/dist/commands/usage.js +212 -16
- package/dist/ide/editor-context.js +172 -0
- package/dist/ide/ide-session.js +94 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +26 -1
- package/dist/services/api.js +140 -6
- package/dist/services/chat-stream.js +145 -0
- package/dist/services/checkpoints.js +116 -0
- package/dist/services/client-tools.js +260 -0
- package/dist/services/command-coordinator.js +200 -0
- package/dist/services/command-policy.js +404 -0
- package/dist/services/config.js +247 -22
- package/dist/services/context.js +265 -20
- package/dist/services/device-auth.js +42 -30
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -0
- package/dist/services/file-detect.js +104 -0
- package/dist/services/file-resolver.js +199 -0
- package/dist/services/file-upload.js +126 -0
- package/dist/services/git-tools.js +248 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +64 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/job-helper.js +307 -0
- package/dist/services/local-files.js +517 -0
- package/dist/services/local-tools.js +432 -0
- package/dist/services/login-flow.js +15 -8
- package/dist/services/meta.js +3 -1
- package/dist/services/mutation-coordinator.js +161 -0
- package/dist/services/mutations.js +493 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +5 -2
- package/dist/services/packaged.js +24 -0
- package/dist/services/process-runner.js +406 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/secure-store.js +197 -0
- package/dist/services/session-resolver.js +108 -0
- package/dist/services/sia.js +51 -0
- package/dist/services/update.js +286 -0
- package/dist/services/workspace-registry.js +309 -0
- package/dist/services/workspace.js +573 -0
- package/dist/shell/shell-chat.js +1028 -57
- package/dist/shell/shell-commands.js +200 -11
- package/dist/shell/shell-prompt.js +81 -8
- package/dist/shell/shell-renderer.js +7 -19
- package/dist/shell/shell-router.js +19 -3
- package/dist/shell/shell.js +185 -17
- package/dist/types/index.js +3 -1
- package/dist/ui/approval.js +81 -0
- package/dist/ui/banner.js +39 -0
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +87 -0
- package/dist/ui/chat-renderer.js +206 -13
- package/dist/ui/colors.js +4 -0
- package/dist/ui/command-filter.js +26 -5
- package/dist/ui/command-palette.js +17 -4
- package/dist/ui/command-registry.js +84 -9
- package/dist/ui/command-review.js +138 -0
- package/dist/ui/composer-layout.js +41 -0
- package/dist/ui/conversation.js +398 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +3 -1
- package/dist/ui/markdown.js +63 -9
- package/dist/ui/message.js +14 -31
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +1 -1
- package/dist/ui/select.js +185 -29
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/trust.js +93 -0
- package/dist/ui/ui.js +4 -1
- package/package.json +13 -2
- package/dist/ui/activity.js +0 -77
package/README.md
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
# Carrier OS CLI
|
|
2
2
|
|
|
3
|
-
A
|
|
4
|
-
|
|
3
|
+
A command-line client for the Carrier OS **public `/v1` API**, covering the
|
|
4
|
+
workflow end-to-end:
|
|
5
5
|
|
|
6
6
|
```
|
|
7
|
-
|
|
8
|
-
→ Chat → Sessions → Files → Usage
|
|
7
|
+
Install CLI → cos login (browser) → Chat → Sessions → Files → Memory → Usage
|
|
9
8
|
```
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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,35 +28,24 @@ 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
|
|
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
|
-
|
|
34
|
+
cos # or: carrieros
|
|
38
35
|
```
|
|
39
36
|
|
|
40
|
-
###
|
|
37
|
+
### From source
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
Code / Vercel CLI:
|
|
39
|
+
Working on the CLI itself, or testing an unreleased change:
|
|
44
40
|
|
|
45
41
|
```bash
|
|
46
|
-
npm
|
|
47
|
-
|
|
48
|
-
carrieros # or: cos
|
|
42
|
+
npm run build
|
|
43
|
+
npm link # `cos` now runs your working copy
|
|
49
44
|
```
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
npm publish --access public
|
|
55
|
-
```
|
|
46
|
+
`npm link` is preferable to `npm pack` + `npm install -g <tarball>` during
|
|
47
|
+
development: the tarball installs a **frozen copy**, so a rebuild does not
|
|
48
|
+
reach the installed command and you end up debugging stale code.
|
|
56
49
|
|
|
57
50
|
### Update
|
|
58
51
|
|
|
@@ -98,19 +91,29 @@ node dist/main.js <command>
|
|
|
98
91
|
|
|
99
92
|
## How to use Carrier OS CLI
|
|
100
93
|
|
|
101
|
-
**Prerequisites:** [Node.js](https://nodejs.org) **18+** (`node -v`) and a
|
|
102
|
-
OS
|
|
103
|
-
|
|
94
|
+
**Prerequisites:** [Node.js](https://nodejs.org) **18+** (`node -v`) and a
|
|
95
|
+
Carrier OS account — the same one you use on carrieros.ai. Nothing to generate
|
|
96
|
+
beforehand.
|
|
104
97
|
|
|
105
98
|
### 1. Sign in (one-time setup)
|
|
106
99
|
|
|
107
|
-
Authenticate once — your key is stored on your machine
|
|
108
|
-
(`%APPDATA%/CarrierOS/config.json`, or `~/.carrieros/config.json`), never a JWT:
|
|
109
|
-
|
|
110
100
|
```bash
|
|
111
|
-
cos login
|
|
101
|
+
cos login
|
|
112
102
|
```
|
|
113
103
|
|
|
104
|
+
Your browser opens on your Carrier OS account, you approve this terminal, and
|
|
105
|
+
the CLI stores the session it is issued
|
|
106
|
+
(`%APPDATA%/CarrierOS/config.json`, or `~/.carrieros/config.json`, written
|
|
107
|
+
`0600`). The browser never sees those credentials and the CLI never sees your
|
|
108
|
+
password.
|
|
109
|
+
|
|
110
|
+
Approving is a spending decision — a CLI turn draws on the same credits the
|
|
111
|
+
website does — so the page names the account and lists what the terminal will
|
|
112
|
+
be able to do before you confirm.
|
|
113
|
+
|
|
114
|
+
The session refreshes itself. You will not be asked again unless you run
|
|
115
|
+
`cos logout` or the session is revoked.
|
|
116
|
+
|
|
114
117
|
Pointing at a local / self-hosted API instead of production
|
|
115
118
|
(`https://api.carrieros.ai/v1`)? Pass `--url` once:
|
|
116
119
|
|
|
@@ -141,17 +144,90 @@ cos
|
|
|
141
144
|
|
|
142
145
|
❯ /model # switch the AI model (arrow-key picker)
|
|
143
146
|
❯ /mode # switch the Carrier mode (arrow-key picker)
|
|
147
|
+
❯ /websearch # search the web on your next message
|
|
144
148
|
❯ /help # browse every command (arrow-navigable menu)
|
|
145
149
|
```
|
|
146
150
|
|
|
151
|
+
**Web search** is a capability of chat, not a separate mode. Three ways in:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
❯ /websearch # arm the NEXT message, then it lapses
|
|
155
|
+
❯ /websearch latest OpenAI news # search right now, changing nothing
|
|
156
|
+
❯ /websearch on # standing preference until /websearch off
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
A searching turn shows its phases, then cites what it read:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
❯ /websearch
|
|
163
|
+
✓ Web search enabled
|
|
164
|
+
|
|
165
|
+
Scope your next message
|
|
166
|
+
Mode live web
|
|
167
|
+
|
|
168
|
+
❯ what shipped in the latest node lts?
|
|
169
|
+
● Understanding your request
|
|
170
|
+
● Searching the web
|
|
171
|
+
● Reading sources
|
|
172
|
+
⠹ Synthesizing answer…
|
|
173
|
+
|
|
174
|
+
● Node.js 24 became Active LTS in October…
|
|
175
|
+
|
|
176
|
+
Sources · 6
|
|
177
|
+
|
|
178
|
+
[1] BBC
|
|
179
|
+
Trump gives Iran 10 days to respond
|
|
180
|
+
bbc.com
|
|
181
|
+
|
|
182
|
+
[2] Reuters
|
|
183
|
+
Latest developments in Iran talks
|
|
184
|
+
reuters.com
|
|
185
|
+
|
|
186
|
+
+ 2 more · /sources
|
|
187
|
+
|
|
188
|
+
✓ Web search · 6 sources · 3.2s
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`/sources` prints the full list with URLs; `/open 2` opens one in your browser.
|
|
192
|
+
|
|
193
|
+
**Conversations are numbered, not UUIDs.** `/sessions` prints an ordered list and
|
|
194
|
+
every session command takes that number — ids still work everywhere for scripting:
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
❯ /sessions
|
|
198
|
+
1 Debugging the auth flow 12 msgs · 2h ago
|
|
199
|
+
2 ► AWS outage research 5 msgs · 1d ago
|
|
200
|
+
|
|
201
|
+
❯ /session 1 # continue #1
|
|
202
|
+
❯ /history 2 # transcript of #2
|
|
203
|
+
❯ /session delete 2 # asks before deleting
|
|
204
|
+
❯ /context # what your next message is sent with
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Turn shaping** — `/fast` trades refinement for latency; `/hipwr` runs High
|
|
208
|
+
Power's 4-pass pipeline (expansion → hardening → architecture → finalization).
|
|
209
|
+
High Power only applies to the `auto`, `summary`, `reasoning` and `research`
|
|
210
|
+
modes, and your workspace admin can disable it entirely.
|
|
211
|
+
|
|
212
|
+
Every active capability shows in the footer, so you always know what you're
|
|
213
|
+
about to send:
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
‖ Standard chat · Reasoning · GPT-5.2 · Fast · HIPWR · 🌐 Websearch
|
|
217
|
+
```
|
|
218
|
+
|
|
147
219
|
**Slash commands** (type `/` to filter them live):
|
|
148
220
|
|
|
149
221
|
| Command | Does |
|
|
150
222
|
|---|---|
|
|
151
223
|
| `/model` · `/models` | switch / list provider models (GPT, Grok, Claude, …) |
|
|
152
224
|
| `/mode` · `/modes` | switch / list Carrier modes (general, code, research, …) |
|
|
153
|
-
| `/
|
|
154
|
-
| `/
|
|
225
|
+
| `/websearch [query\|on\|off\|auto\|status]` | arm the next message · search now · set the standing preference |
|
|
226
|
+
| `/sources` · `/open <n>` | sources from the last search · open one in the browser |
|
|
227
|
+
| `/fast [on\|off]` · `/hipwr [on\|off]` | fast mode (quicker) · High Power (4-pass refinement) |
|
|
228
|
+
| `/new [title]` · `/sessions` | start a conversation · list them, numbered |
|
|
229
|
+
| `/session <n>` · `/session delete <n>` | continue #n · delete #n (asks first) |
|
|
230
|
+
| `/history [n]` · `/context` | transcript · what your next message is sent with |
|
|
155
231
|
| `/upload <file>` · `/files` | add + list context files |
|
|
156
232
|
| `/whoami` · `/usage` · `/doctor` | account · usage · diagnostics |
|
|
157
233
|
| `/login` · `/logout` · `/version` · `/help` · `/exit` | account · info · quit |
|
|
@@ -178,8 +254,8 @@ cos logout # remove the key from this machine
|
|
|
178
254
|
|
|
179
255
|
| Command | Endpoint(s) reused | Purpose |
|
|
180
256
|
|---|---|---|
|
|
181
|
-
| `login [
|
|
182
|
-
| `logout` |
|
|
257
|
+
| `login [--url] [--platform]` | `POST /platform/auth/device/{code,token}` | Browser device authorization; stores the issued session |
|
|
258
|
+
| `logout` | `POST /platform/auth/cli/logout` | Revoke the session server-side and clear it locally |
|
|
183
259
|
| `whoami` | `POST /v1/auth/verify` | Show workspace / project / account |
|
|
184
260
|
| `version` | `GET /v1/health` | CLI + API versions |
|
|
185
261
|
| `doctor` | `GET /v1/health`, `POST /v1/auth/verify` | Config, connectivity, key checks |
|
|
@@ -189,10 +265,16 @@ cos logout # remove the key from this machine
|
|
|
189
265
|
| `model [id]` | — | Set the provider model (or `auto`); picker if no id |
|
|
190
266
|
| `modes` | `GET /v1/models` | List Carrier modes (general, code, research, …) |
|
|
191
267
|
| `mode [id]` | — | Set the Carrier mode; picker if no id |
|
|
192
|
-
| `
|
|
193
|
-
| `
|
|
194
|
-
| `
|
|
195
|
-
| `
|
|
268
|
+
| `websearch [on\|off\|auto]` | — | Live web search for chat turns; shows state if no arg |
|
|
269
|
+
| `fast [on\|off]` | — | Fast mode — shorter pipeline, quicker replies |
|
|
270
|
+
| `hipwr [on\|off]` | — | High Power — 4-pass refinement (admin-gated) |
|
|
271
|
+
| `new [title]` | `POST /v1/sessions` (only with a title) | Start a conversation |
|
|
272
|
+
| `sessions` | `GET /v1/conversations` | Numbered list of conversations |
|
|
273
|
+
| `session <n\|id>` | `GET /v1/sessions/:id` | Continue that conversation |
|
|
274
|
+
| `session use [n\|id]` | `GET /v1/sessions/:id` | Same — kept for compatibility |
|
|
275
|
+
| `session delete <n\|id>` | `DELETE /v1/sessions/:id` | Delete (asks first) |
|
|
276
|
+
| `history [n\|id]` | `GET /v1/sessions/:id/messages` | Print a transcript |
|
|
277
|
+
| `context` | `GET /v1/sessions/:id` | What the next message is sent with |
|
|
196
278
|
| `clear` | — | Start a fresh session (drops the local pointer) |
|
|
197
279
|
| `upload <file>` | `POST /v1/files` + `…/:id/process` | Upload and index a file |
|
|
198
280
|
| `files` | — (local) | List files uploaded from this machine |
|
|
@@ -234,8 +316,9 @@ src/
|
|
|
234
316
|
`data`, or throws a typed `ApiError` carrying the server's `{code, message}`.
|
|
235
317
|
Adding an endpoint = adding one method.
|
|
236
318
|
- **Single disk boundary.** `ConfigStore` owns `%APPDATA%/CarrierOS/config.json`
|
|
237
|
-
(falls back to `~/.carrieros/config.json`). It stores
|
|
238
|
-
the active session id, a cached scope, and
|
|
319
|
+
(falls back to `~/.carrieros/config.json`, written `0600`). It stores the
|
|
320
|
+
CLI's own access/refresh pair, the active session id, a cached scope, and
|
|
321
|
+
recent uploads — never a main-site cookie, and never your password.
|
|
239
322
|
- **Dependency injection.** Every command receives a `CommandContext`
|
|
240
323
|
(`config`, `client()`, `requireAuth()`), so commands are thin and don't reach
|
|
241
324
|
for globals. `requireAuth()` centralizes the "not logged in" guard.
|
|
@@ -256,22 +339,23 @@ streaming would require a backend change.
|
|
|
256
339
|
## Testing steps
|
|
257
340
|
|
|
258
341
|
Prerequisites: the API running locally (`npm run dev` in `api.carrieros.ai`,
|
|
259
|
-
default `http://localhost:5000`) and
|
|
260
|
-
|
|
342
|
+
default `http://localhost:5000`) and the main site running (default
|
|
343
|
+
`http://localhost:3000`) so the browser step has a page to land on. Point the
|
|
344
|
+
API at it with `CLI_AUTHORIZE_URL`, or set `FRONTEND_URL` and let the API append
|
|
345
|
+
`/cli/authorize`.
|
|
261
346
|
|
|
262
347
|
```bash
|
|
263
348
|
cd carrieros-cli
|
|
264
349
|
npm install && npm run build
|
|
265
350
|
|
|
266
|
-
# Connectivity (no
|
|
267
|
-
node dist/main.js
|
|
268
|
-
node dist/main.js doctor # ✓ API reachable, ⚠ key not set
|
|
351
|
+
# Connectivity (no session needed)
|
|
352
|
+
node dist/main.js doctor # ✓ API reachable, ⚠ not signed in
|
|
269
353
|
node dist/main.js version # CLI + API versions
|
|
270
354
|
|
|
271
|
-
# Auth
|
|
272
|
-
node dist/main.js login
|
|
355
|
+
# Auth — opens the browser, approve there, the CLI finishes on its own
|
|
356
|
+
node dist/main.js login --url http://localhost:5000/v1
|
|
273
357
|
node dist/main.js whoami # workspace / project / account
|
|
274
|
-
node dist/main.js doctor # now: ✓
|
|
358
|
+
node dist/main.js doctor # now: ✓ signed in
|
|
275
359
|
|
|
276
360
|
# Chat + sessions
|
|
277
361
|
node dist/main.js models # list Carrier modes
|
|
@@ -292,14 +376,15 @@ node dist/main.js logout # key removed from this machine
|
|
|
292
376
|
|
|
293
377
|
```bash
|
|
294
378
|
node dist/main.js usage # (logged out) → "Run `carrieros login` first."
|
|
295
|
-
node dist/main.js login
|
|
379
|
+
node dist/main.js login --url http://localhost:1/v1 # → clean NETWORK_ERROR
|
|
296
380
|
node dist/main.js login --url http://localhost:1/v1 && node dist/main.js doctor # → clean NETWORK_ERROR
|
|
297
381
|
```
|
|
298
382
|
|
|
299
383
|
---
|
|
300
384
|
|
|
301
|
-
## Not in
|
|
385
|
+
## Not in scope yet
|
|
386
|
+
|
|
387
|
+
No billing · no marketplace · no plugins · no agents · no SDK · no IDE
|
|
388
|
+
integration · no repo awareness · no multi-agent · no `.exe` installers.
|
|
302
389
|
|
|
303
|
-
|
|
304
|
-
no IDE integration · no repo awareness · no multi-agent · no auto-updates · no
|
|
305
|
-
`.exe` installers.
|
|
390
|
+
Browser sign-in and self-update both landed — `cos login` and `cos update`.
|
|
@@ -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
|
+
}
|