@carrieros/cli 0.3.0 → 0.4.1

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 (89) hide show
  1. package/README.md +89 -15
  2. package/dist/commands/chat.js +6 -6
  3. package/dist/commands/context.js +40 -0
  4. package/dist/commands/doctor.js +34 -14
  5. package/dist/commands/logout.js +2 -0
  6. package/dist/commands/permissions.js +78 -0
  7. package/dist/commands/scope.js +9 -6
  8. package/dist/commands/sessions.js +5 -0
  9. package/dist/commands/settings.js +83 -10
  10. package/dist/commands/update.js +177 -51
  11. package/dist/commands/usage.js +10 -8
  12. package/dist/commands/version.js +1 -3
  13. package/dist/commands/whoami.js +12 -9
  14. package/dist/ide/editor-context.js +115 -12
  15. package/dist/ide/ide-session.js +288 -18
  16. package/dist/ide/tool-host.js +6 -6
  17. package/dist/main.js +10 -1
  18. package/dist/services/api.js +183 -15
  19. package/dist/services/auth-origin.js +20 -0
  20. package/dist/services/auto-update.js +221 -0
  21. package/dist/services/chat-stream.js +26 -3
  22. package/dist/services/checkpoints.js +176 -14
  23. package/dist/services/client-tools.js +123 -27
  24. package/dist/services/code-intel.js +243 -0
  25. package/dist/services/code-symbols.js +94 -0
  26. package/dist/services/coding-workflow.js +554 -0
  27. package/dist/services/command-coordinator.js +85 -12
  28. package/dist/services/command-policy.js +34 -4
  29. package/dist/services/config.js +96 -11
  30. package/dist/services/container-runner.js +254 -0
  31. package/dist/services/container-supervisor.js +38 -0
  32. package/dist/services/context.js +98 -25
  33. package/dist/services/device-auth.js +33 -6
  34. package/dist/services/execution-platform.js +30 -0
  35. package/dist/services/file-resolver.js +1 -1
  36. package/dist/services/folder-key.js +22 -0
  37. package/dist/services/git-tools.js +181 -0
  38. package/dist/services/helper-bin.js +56 -35
  39. package/dist/services/instruction-resolver.js +54 -0
  40. package/dist/services/job-helper.js +31 -10
  41. package/dist/services/local-files.js +148 -26
  42. package/dist/services/local-tools.js +540 -35
  43. package/dist/services/login-flow.js +44 -13
  44. package/dist/services/meta.js +27 -0
  45. package/dist/services/mutation-coordinator.js +186 -20
  46. package/dist/services/mutation-groups.js +309 -0
  47. package/dist/services/mutation-recovery.js +159 -0
  48. package/dist/services/mutations.js +264 -78
  49. package/dist/services/packaged-update.js +403 -0
  50. package/dist/services/packaged.js +15 -0
  51. package/dist/services/permission-mode.js +78 -0
  52. package/dist/services/process-runner.js +7 -1
  53. package/dist/services/project-context.js +4 -4
  54. package/dist/services/result-reconciliation.js +49 -0
  55. package/dist/services/secure-store.js +21 -1
  56. package/dist/services/session-resolver.js +7 -0
  57. package/dist/services/supported-runtime.js +59 -0
  58. package/dist/services/task-context.js +212 -0
  59. package/dist/services/task-snapshot.js +38 -0
  60. package/dist/services/tool-result-outbox.js +195 -0
  61. package/dist/services/update.js +457 -13
  62. package/dist/services/workspace-registry.js +4 -3
  63. package/dist/services/workspace.js +8 -1
  64. package/dist/shell/shell-chat.js +320 -34
  65. package/dist/shell/shell-commands.js +47 -5
  66. package/dist/shell/shell-prompt.js +21 -11
  67. package/dist/shell/shell-renderer.js +1 -1
  68. package/dist/shell/shell.js +107 -20
  69. package/dist/shell/task-context-view.js +40 -0
  70. package/dist/ui/agent-cards.js +111 -0
  71. package/dist/ui/agent-presentation.js +131 -0
  72. package/dist/ui/approval.js +46 -16
  73. package/dist/ui/banner.js +31 -87
  74. package/dist/ui/change-review.js +293 -46
  75. package/dist/ui/chat-renderer.js +6 -6
  76. package/dist/ui/colors.js +9 -9
  77. package/dist/ui/command-details.js +11 -0
  78. package/dist/ui/command-palette.js +27 -10
  79. package/dist/ui/command-registry.js +11 -4
  80. package/dist/ui/command-review.js +77 -28
  81. package/dist/ui/composer-layout.js +26 -20
  82. package/dist/ui/conversation.js +77 -25
  83. package/dist/ui/live.js +1 -1
  84. package/dist/ui/screen.js +19 -11
  85. package/dist/ui/select.js +6 -0
  86. package/dist/ui/task-context-card.js +99 -0
  87. package/dist/ui/trust.js +7 -12
  88. package/dist/ui/ui.js +23 -0
  89. package/package.json +9 -5
package/README.md CHANGED
@@ -34,6 +34,14 @@ npm install -g @carrieros/cli
34
34
  cos # or: carrieros
35
35
  ```
36
36
 
37
+ ### Windows installer (no Node.js needed)
38
+
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).
44
+
37
45
  ### From source
38
46
 
39
47
  Working on the CLI itself, or testing an unreleased change:
@@ -49,14 +57,67 @@ reach the installed command and you end up debugging stale code.
49
57
 
50
58
  ### Update
51
59
 
52
- Upgrade to the latest published version at any time:
60
+ Carrier OS CLI keeps itself up to date.
61
+
62
+ **Automatic updates (npm global install).** The shell checks for a new release
63
+ when it starts and then every few hours (6 by default), without slowing anything
64
+ down. When one is found you see, once:
65
+
66
+ > CarrierOS CLI 0.4.1 is available. You are currently using 0.4.0. It will be
67
+ > installed in the background when you exit.
68
+
69
+ When you leave the shell (and no other Carrier OS CLI window is open) it runs
70
+ `npm install -g @carrieros/cli@<that exact version>` in the background. Your
71
+ running session is never changed underneath you. The next time you start
72
+ `cos` it confirms the result — "CarrierOS CLI 0.4.1 has been installed
73
+ successfully" — or, if the install failed, gives you the manual command and does
74
+ not retry that version automatically. Your sign-in, settings, trusted folders
75
+ and projects are untouched (they live in your user config folder, not in the
76
+ package).
77
+
78
+ **Update now.** Run `/update` in the shell (or `cos update`, `cos update --yes`
79
+ in scripts). It shows your version and the latest, asks before installing, verifies
80
+ the installed version, and tells you to restart the CLI to use it. It is refused
81
+ while an agent task is running.
82
+
83
+ **Settings** (`/settings` shows them):
84
+
85
+ | Command | Effect |
86
+ |---|---|
87
+ | `/settings updates off` | Stop automatic background updates (`/update` still works). `on` to resume. |
88
+ | `/settings channel latest\|beta\|next` | Release channel to follow — production installs use `latest` (stable), `beta` or `next`; the isolated staging CLI always follows its own `staging` tag. |
89
+ | `/settings update-interval <hours>` | How often to check while running (1–168, default 6). |
90
+
91
+ `CARRIEROS_DISABLE_AUTOUPDATE=1` turns automatic updates off for one environment
92
+ (e.g. CI).
93
+
94
+ **Manual update** at any time:
53
95
 
54
96
  ```bash
55
97
  npm install -g @carrieros/cli@latest
56
98
  ```
57
99
 
100
+ **What is updated automatically:**
101
+
102
+ | Installed as | Automatic update |
103
+ |---|---|
104
+ | `npm install -g @carrieros/cli` | Yes, in the background on exit (if your global npm folder is writable — Carrier OS never asks for administrator rights; otherwise it shows the command to run). |
105
+ | Project dependency (`node_modules`) | No — update it with your package manager, e.g. `npm install @carrieros/cli@latest`. |
106
+ | `npx @carrieros/cli` | No — run `npx @carrieros/cli@latest`. |
107
+ | Development checkout / `npm link` | No — never overwritten. |
108
+ | Windows installer (`cos.exe`) | Its own verified updater: `/update` downloads, checks the checksum and signature, and installs. |
109
+ | Staging build (`@carrieros/cli-staging`) | Updates only from its own package, never from the production one. |
110
+
58
111
  Check what you're running with `cos version` — it prints the CLI version
59
- alongside the API version it's talking to.
112
+ alongside the API version it's talking to. Every API request also carries an
113
+ `X-CarrierOS-Client: cli/<version>` header (and `X-CarrierOS-Channel`), so the
114
+ server can tell which client version it is serving.
115
+
116
+ **Releasing (maintainers).** Publishing is release-gated (`.github/workflows/publish.yml`).
117
+ The npm dist-tag follows the version: `1.2.3` publishes to `latest`, `1.2.3-beta.N` to
118
+ `beta`, `1.2.3-next.N` or `-rc.N` to `next`; any other pre-release fails the job.
119
+ Bump `package.json`'s version — installed CLIs compare versions, so a republish
120
+ of the same version is never offered.
60
121
 
61
122
  ### Uninstall
62
123
 
@@ -124,8 +185,8 @@ cos login --url http://localhost:5000/v1
124
185
  Confirm the setup:
125
186
 
126
187
  ```bash
127
- cos doctor # config, connectivity, key checks
128
- cos whoami # workspace / project / account
188
+ cos doctor # config, connectivity, session checks
189
+ cos whoami # signed-in account
129
190
  ```
130
191
 
131
192
  ### 2. Open the interactive shell
@@ -245,7 +306,7 @@ cos sessions # list conversations
245
306
  cos history # transcript of the active session
246
307
  cos upload ./report.pdf # upload + index a file
247
308
  cos usage # requests, tokens, estimated cost
248
- cos logout # remove the key from this machine
309
+ cos logout # remove saved CLI credentials from this machine
249
310
  ```
250
311
 
251
312
  ---
@@ -254,11 +315,11 @@ cos logout # remove the key from this machine
254
315
 
255
316
  | Command | Endpoint(s) reused | Purpose |
256
317
  |---|---|---|
257
- | `login [--url] [--platform]` | `POST /platform/auth/device/{code,token}` | Browser device authorization; stores the issued session |
318
+ | `login [--url] [--platform]` | `POST /cli/auth/device/{code,token}` | User-owned browser device authorization; stores the issued CLI session |
258
319
  | `logout` | `POST /platform/auth/cli/logout` | Revoke the session server-side and clear it locally |
259
- | `whoami` | `POST /v1/auth/verify` | Show workspace / project / account |
320
+ | `whoami` | `POST /v1/auth/verify` | Show your signed-in account; `--details` includes API scope |
260
321
  | `version` | `GET /v1/health` | CLI + API versions |
261
- | `doctor` | `GET /v1/health`, `POST /v1/auth/verify` | Config, connectivity, key checks |
322
+ | `doctor` | `GET /v1/health`, `POST /v1/auth/verify` | Config, connectivity, session checks |
262
323
  | *(no command)* | `POST /v1/chat` | **Default** — the interactive Carrier OS shell |
263
324
  | `chat` | `POST /v1/chat` | Focused chat REPL with a persistent session |
264
325
  | `models` | `GET /v1/models/chat` | List provider models (GPT, Grok, Claude, …) |
@@ -327,7 +388,7 @@ src/
327
388
  - **Strong typing.** `strict` TypeScript with `noUnusedLocals/Parameters`; the
328
389
  entire `/v1` contract is typed in `types/index.ts`.
329
390
  - **Windows-first, clean UX.** `chalk` colors, `ora` spinners, `@inquirer/prompts`
330
- for the masked key prompt and session picker, and a small built-in
391
+ for interactive selections and the session picker, and a small built-in
331
392
  Markdown→ANSI renderer (no markdown dependency).
332
393
 
333
394
  Streaming is **simulated**: the API returns the full response, which the CLI
@@ -354,7 +415,7 @@ node dist/main.js version # CLI + API versions
354
415
 
355
416
  # Auth — opens the browser, approve there, the CLI finishes on its own
356
417
  node dist/main.js login --url http://localhost:5000/v1
357
- node dist/main.js whoami # workspace / project / account
418
+ node dist/main.js whoami # signed-in account
358
419
  node dist/main.js doctor # now: ✓ signed in
359
420
 
360
421
  # Chat + sessions
@@ -369,7 +430,7 @@ node dist/main.js upload ./somefile.pdf
369
430
  node dist/main.js files
370
431
  node dist/main.js usage
371
432
 
372
- node dist/main.js logout # key removed from this machine
433
+ node dist/main.js logout # saved CLI credentials removed from this machine
373
434
  ```
374
435
 
375
436
  **Negative checks**
@@ -382,9 +443,22 @@ node dist/main.js login --url http://localhost:1/v1 && node dist/main.js doctor
382
443
 
383
444
  ---
384
445
 
385
- ## Not in scope yet
446
+ ## Scope and current limitations
447
+
448
+ The CLI includes a repository-aware coding workflow. It can inspect a selected
449
+ repository, read files, propose approval-gated edits, and run separately
450
+ approved validation commands through its configured executor. File changes and
451
+ commands remain subject to the repository trust and review gates. This does not
452
+ guarantee that the agent can diagnose or fix every coding task, and a fresh
453
+ end-to-end live-model acceptance is still required for the current release.
454
+
455
+ The CLI does not provide multi-agent orchestration, an SDK, IDE integration,
456
+ plugins, or a marketplace. Native Windows executor acceptance has not yet been
457
+ completed. Browser sign-in and self-update are available through `cos login`
458
+ and `cos update`.
459
+
460
+ ### Advanced API scope
386
461
 
387
- No billing · no marketplace · no plugins · no agents · no SDK · no IDE
388
- integration · no repo awareness · no multi-agent · no `.exe` installers.
462
+ 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.
389
463
 
390
- Browser sign-in and self-update both landed — `cos login` and `cos update`.
464
+ 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.
@@ -5,7 +5,7 @@ import { clearActiveSession, listSessions } from "../services/session-resolver.j
5
5
  import { showContext } from "./context.js";
6
6
  import { showHistory } from "./history.js";
7
7
  import { newSession, pickSession, renderSessionList, switchTo } from "./sessions.js";
8
- import { chatTurn, chatTypeLabelShort, loadModels, loadModes, modeLabelShort, modelLabelShort, armWebSearch, isWebSearchStateArg, openSource, pickChatType, pickMode, pickModel, searchNow, setChatType, setFast, setHighPower, setMode, setModel, setWebSearch, showSources } from "../shell/shell-chat.js";
8
+ import { chatTurn, chatTypeLabelShort, loadModels, loadModes, modeLabelShort, modelLabelShort, armWebSearch, isWebSearchStateArg, openSource, pickChatType, pickMode, pickModel, searchNow, setChatType, setFast, setHighPower, setMode, setModel, setWebSearch, showSources, loadFastModel } from "../shell/shell-chat.js";
9
9
  /**
10
10
  * `cos chat` — a focused interactive REPL over POST /v1/chat. (The full
11
11
  * shell — `cos` with no command — is a superset with every slash command.)
@@ -18,7 +18,7 @@ export function registerChat(program, ctx) {
18
18
  .argument("[message...]", "an optional first message to send immediately (uses attached files)")
19
19
  .option("-m, --mode <mode>", "Carrier mode (general, code, research, …)")
20
20
  .option("--model <model>", "provider model override (e.g. gpt-5.5); 'auto' to clear")
21
- .option("--standard", "start in Standard chat instead of Carrier Chat")
21
+ .option("--standard", "start in Standard chat (the default)")
22
22
  .action(async (messageParts, opts) => {
23
23
  // Mode follows the chat type (Carrier → General, Standard → saved or
24
24
  // Auto); an explicit -m flag overrides it for this run.
@@ -26,8 +26,8 @@ export function registerChat(program, ctx) {
26
26
  ctx.config.set("mode", opts.mode);
27
27
  if (opts.model !== undefined)
28
28
  ctx.config.set("model", opts.model === "auto" ? "" : opts.model);
29
- // Chat type defaults to Carrier Chat (the persisted default is carrier);
30
- // --standard opts into a plain chat for this run onward.
29
+ // Standard is the default; --standard explicitly clears the active
30
+ // session so its next message starts a fresh Standard conversation.
31
31
  if (opts.standard)
32
32
  ctx.setChatType("standard");
33
33
  // e.g. `cos chat "Summarize this file"` — send it right away (with any
@@ -39,7 +39,7 @@ export function registerChat(program, ctx) {
39
39
  export async function runChat(ctx, initialMessage) {
40
40
  const client = ctx.requireAuth();
41
41
  // Preload modes + models so the banner can show friendly labels (best-effort).
42
- await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => [])]);
42
+ await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => []), loadFastModel(client)]);
43
43
  printBanner(ctx.config.get("scope"), modeLabelShort(ctx), modelLabelShort(ctx));
44
44
  info(`${chatTypeLabelShort(ctx)} · type /chat to switch (carrier / standard)`);
45
45
  // A message passed on the command line (`cos chat "…"`) is sent immediately —
@@ -136,7 +136,7 @@ export async function runChat(ctx, initialMessage) {
136
136
  continue;
137
137
  }
138
138
  if (cmdWord === "/fast") {
139
- setFast(ctx, argStr);
139
+ await setFast(ctx, argStr, client);
140
140
  continue;
141
141
  }
142
142
  if (cmdWord === "/hipwr" || cmdWord === "/highpower") {
@@ -1,3 +1,5 @@
1
+ import { getPermissionMode, permissionModeExplanation, permissionModeLabel } from "../services/permission-mode.js";
2
+ import { taskSnapshot } from "../services/task-snapshot.js";
1
3
  import { ApiError } from "../services/api.js";
2
4
  import { errorLine, line, timeAgo } from "../services/output.js";
3
5
  import { ordinalOf } from "../services/session-resolver.js";
@@ -94,6 +96,8 @@ export async function showContext(ctx, client) {
94
96
  if (ctx.modeIsSelectable)
95
97
  row("Mode", c.value(modeLabelShort(ctx)));
96
98
  row("Model", c.value(modelLabelShort(ctx)));
99
+ const mode = getPermissionMode(ctx.config);
100
+ row("Permissions", c.value(permissionModeLabel(mode)) + c.dim(` · ${permissionModeExplanation(mode)}`));
97
101
  const on = [];
98
102
  if (ctx.fast)
99
103
  on.push("Fast");
@@ -126,6 +130,16 @@ export async function showContext(ctx, client) {
126
130
  /* memory is supplementary — a failure here shouldn't blank the view */
127
131
  }
128
132
  }
133
+ // ── The current coding task (the platform's Task Context) ────────────────
134
+ if (sessionId && typeof client.taskContext === "function") {
135
+ const snap = taskSnapshot(await client.taskContext(sessionId).catch(() => null));
136
+ if (snap) {
137
+ line();
138
+ line(" " + c.dim("Task"));
139
+ for (const [label, value] of taskSnapshotRows(snap))
140
+ row(label, value);
141
+ }
142
+ }
129
143
  // ── The local project ─────────────────────────────────────────────────────
130
144
  // Peek rather than build: /context is a status view, and it should not be the
131
145
  // thing that decides to walk a monorepo. When nothing has built a snapshot
@@ -158,3 +172,29 @@ export function contextUnavailable() {
158
172
  line(l);
159
173
  }
160
174
  }
175
+ /** The task snapshot as label/value rows — the same facts the IDE's /context card shows. */
176
+ export function taskSnapshotRows(t) {
177
+ const list = (items, total = items.length) => (items.length ? items.join(", ") + (total > items.length ? c.dim(` (+${total - items.length} more)`) : "") : c.dim("none"));
178
+ const rows = [
179
+ ["Task", c.value(t.title)],
180
+ ["Status", c.value(t.status) + (t.verified !== t.status ? c.dim(` · verified: ${t.verified}`) : "")],
181
+ ["Investigation", c.value(`${t.investigation.searches} searches · ${t.inspected.total} files read · ${t.investigation.symbols.length} symbols traced · ${t.investigation.relationships.length} relationships followed`)],
182
+ ["Inspected", list(t.inspected.files, t.inspected.total)],
183
+ ...(t.symptom ? [["Symptom", c.value(t.symptom)]] : []),
184
+ ...(t.executionPath.length ? [["Path", t.executionPath.join(c.dim(" → "))]] : []),
185
+ ["Root cause", t.rootCause ? c.value(t.rootCause) : c.dim("not established yet")],
186
+ ...(t.changeLocation ? [["Change at", c.value(t.changeLocation)]] : []),
187
+ ...(t.evidence.length ? [["Evidence", t.evidence.join("; ")]] : []),
188
+ ...(t.ruledOut.length ? [["Ruled out", t.ruledOut.join("; ")]] : []),
189
+ ...(t.plan ? [["Plan", c.value(t.plan)]] : []),
190
+ ["Modified", list(t.modified)],
191
+ ["Created", list(t.created)],
192
+ ["Deleted", list(t.deleted)],
193
+ ["Unresolved", t.unresolved.length ? c.warn(t.unresolved.join(", ") + " — may still be on disk; review before continuing") : c.dim("none")]
194
+ ];
195
+ if (t.pendingOperations.length)
196
+ rows.push(["Interrupted", c.warn(t.pendingOperations.join(", ") + " — never resumed automatically")]);
197
+ rows.push(["Corrections", t.corrections ? c.value(String(t.corrections)) + (t.lastCorrection ? c.dim(` · ${t.lastCorrection.slice(0, 80)}`) : "") : c.dim("none")]);
198
+ rows.push(["Tests", t.tests.length ? t.tests.map((r) => `${r.command} → ${r.outcome}`).join("; ") : c.dim("none run")]);
199
+ return rows;
200
+ }
@@ -1,10 +1,15 @@
1
+ import path from "node:path";
1
2
  import { ApiError } from "../services/api.js";
2
3
  import { cliVersion } from "../services/meta.js";
4
+ import { findPrebuiltHelper } from "../services/helper-bin.js";
5
+ import { isPackaged, isSignedRelease } from "../services/packaged.js";
3
6
  import { glyph, heading, line } from "../services/output.js";
4
7
  import { withSpinner } from "../services/spinner.js";
5
8
  import { discoverRootWithoutGit, refreshWorkspace } from "../services/workspace.js";
6
9
  import { isTrusted } from "../ui/trust.js";
7
- import { COMMANDS_OPT_IN_ENV } from "../services/client-tools.js";
10
+ import { COMMANDS_OPT_IN_ENV, localCommandsState } from "../services/client-tools.js";
11
+ import { getPermissionMode } from "../services/permission-mode.js";
12
+ import { executionContract } from "../services/execution-platform.js";
8
13
  function row(status, label, detail) {
9
14
  const g = status === "ok" ? glyph.ok : status === "warn" ? glyph.warn : glyph.err;
10
15
  line(` ${g} ${label.padEnd(20)} ${detail}`);
@@ -21,6 +26,16 @@ export function registerDoctor(program, ctx) {
21
26
  const client = ctx.client();
22
27
  const apiUrl = ctx.config.get("apiUrl") ?? "—";
23
28
  heading("Carrier OS — diagnostics");
29
+ // 0) Installation — only the packaged .exe has one to check. A helper that
30
+ // fails its baked hash is reported here rather than discovered mid-login.
31
+ if (isPackaged()) {
32
+ row("ok", "Installation", `v${cliVersion()} · ${path.dirname(process.execPath)}`);
33
+ row(isSignedRelease() ? "ok" : "warn", "Build", isSignedRelease() ? "signed release" : "unsigned build");
34
+ for (const helper of ["cos-dpapi", "cos-job-runner"]) {
35
+ const found = findPrebuiltHelper(helper);
36
+ row(found ? "ok" : "err", helper, found ? "verified" : "missing or damaged — reinstall Carrier OS");
37
+ }
38
+ }
24
39
  // 1) Configuration
25
40
  row("ok", "Configuration", `${ctx.config.file}`);
26
41
  row("ok", "Endpoint", apiUrl);
@@ -29,7 +44,7 @@ export function registerDoctor(program, ctx) {
29
44
  try {
30
45
  const health = await withSpinner("Pinging API…", () => client.health());
31
46
  apiVersion = health.version;
32
- row("ok", "API reachable", `${health.status} · ${health.version} · ${health.environment}`);
47
+ row("ok", "API reachable", [health.status, health.version, health.environment].filter(Boolean).join(" · "));
33
48
  }
34
49
  catch (err) {
35
50
  row("err", "API reachable", err instanceof ApiError ? err.message : "unreachable");
@@ -43,7 +58,7 @@ export function registerDoctor(program, ctx) {
43
58
  // 4) Session valid?
44
59
  try {
45
60
  const scope = await withSpinner("Verifying session…", () => client.verify());
46
- row("ok", "Session valid", `${scope.workspace.name} / ${scope.project.name}`);
61
+ row("ok", "Session valid", scope.user?.email ?? "CLI device session");
47
62
  }
48
63
  catch (err) {
49
64
  row("err", "Session valid", err instanceof ApiError ? `${err.message} (${err.code})` : "failed");
@@ -78,19 +93,24 @@ export function registerDoctor(program, ctx) {
78
93
  }
79
94
  }
80
95
  // 6) Local capabilities. Reading and file changes follow folder trust;
81
- // running commands additionally needs an explicit opt-in, so say which
82
- // of those is missing rather than just "off".
96
+ // running commands needs Auto or the explicit setting, plus containment;
97
+ // report the precise missing gate rather than just "off".
83
98
  const trusted = isTrusted(ctx.config, trustRoot) || isTrusted(ctx.config);
84
99
  row(trusted ? "ok" : "warn", "Folder trust", trusted ? `trusted: ${trustRoot}` : `not trusted: ${trustRoot}`);
85
- const optedIn = process.env[COMMANDS_OPT_IN_ENV] === "1";
86
- const commandState = !optedIn
87
- ? `off — set ${COMMANDS_OPT_IN_ENV}=1 in this terminal to offer them`
88
- : process.platform !== "win32"
89
- ? "off — local commands are Windows-only for now"
90
- : !trusted
91
- ? "off — this folder is not trusted"
92
- : "on for this terminal — every command still needs your approval";
93
- row(optedIn && trusted && process.platform === "win32" ? "ok" : "warn", "Local commands", commandState);
100
+ // The same check the shell uses to offer run_command, so the two agree
101
+ // on every platform (Windows Job Object; macOS/Linux isolated runtime).
102
+ const commands = localCommandsState(ctx, true, getPermissionMode(ctx.config) === "auto");
103
+ const runtime = executionContract().backend === "docker-engine-v1" ? "isolated Linux container" : "Windows Job Object";
104
+ const commandState = !commands.enabled
105
+ ? ctx.config.get("localCommandsEnabled") === false
106
+ ? "off — explicitly disabled with /settings commands off"
107
+ : `off — /settings commands on (or select Auto), or set ${COMMANDS_OPT_IN_ENV}=1 in this terminal`
108
+ : commands.blockedBy
109
+ ? `not active — ${commands.blockedBy}`
110
+ : getPermissionMode(ctx.config) === "auto"
111
+ ? `on (${runtime}) — Auto runs locally permitted commands without individual prompts`
112
+ : `on (${runtime}) — Manual/Accept Edits ask before each command`;
113
+ row(commands.enabled && !commands.blockedBy ? "ok" : "warn", "Local commands", commandState);
94
114
  // 7) Versions
95
115
  row("ok", "CLI version", cliVersion());
96
116
  row("ok", "API version", apiVersion);
@@ -14,10 +14,12 @@ export function registerLogout(program, ctx) {
14
14
  }
15
15
  const apiUrl = ctx.config.get("apiUrl") ?? DEFAULT_API_URL;
16
16
  const refreshToken = ctx.config.get("auth")?.refreshToken;
17
+ ctx.validateCredentialOrigin(apiUrl);
17
18
  if (refreshToken) {
18
19
  // Best-effort server revoke so the refresh token can't be reused.
19
20
  await withSpinner("Signing out…", () => logoutCliSession(apiUrl, refreshToken));
20
21
  }
22
+ ctx.noteSessionSelectionChanged();
21
23
  ctx.config.clearAuth();
22
24
  success("Logged out. This device's session has been removed.");
23
25
  });
@@ -0,0 +1,78 @@
1
+ import { ApiError } from "../services/api.js";
2
+ import { errorLine, info, line, success } from "../services/output.js";
3
+ import { PERMISSION_MODES, getPermissionMode, parsePermissionMode, permissionModeExplanation, permissionModeLabel, setPermissionMode } from "../services/permission-mode.js";
4
+ import { withSpinner } from "../services/spinner.js";
5
+ import { c } from "../ui/colors.js";
6
+ import { pickFromList } from "../ui/select.js";
7
+ /** "Permission mode changed: Accept Edits" plus what it means. */
8
+ function confirm(mode) {
9
+ success(`Permission mode changed: ${permissionModeLabel(mode)}`);
10
+ line(" " + c.dim(permissionModeExplanation(mode)));
11
+ }
12
+ /**
13
+ * `/permissions` (and `/mode manual|plan|accept-edits`, `/plan`): show or set
14
+ * the session's permission mode. Bare in a terminal opens the picker; piped, it
15
+ * prints the current mode. Applies from the next message.
16
+ */
17
+ export async function runPermissions(ctx, arg) {
18
+ const current = getPermissionMode(ctx.config);
19
+ if (arg.trim()) {
20
+ const mode = parsePermissionMode(arg);
21
+ if (!mode) {
22
+ errorLine(`Unknown permission mode "${arg.trim()}". Use manual, plan, accept-edits or auto.`);
23
+ return;
24
+ }
25
+ if (mode === current) {
26
+ info(`Permission mode is already ${permissionModeLabel(mode)}.`);
27
+ return;
28
+ }
29
+ setPermissionMode(ctx.config, mode);
30
+ confirm(mode);
31
+ return;
32
+ }
33
+ if (!process.stdin.isTTY) {
34
+ line(`Permission mode: ${permissionModeLabel(current)} — ${permissionModeExplanation(current)}`);
35
+ return;
36
+ }
37
+ const chosen = parsePermissionMode(await pickFromList({
38
+ title: "Permission mode",
39
+ description: "Applies from your next message. Trust, freshness, checkpoints and recovery checks always run.",
40
+ choices: PERMISSION_MODES.map((m) => ({ value: m, label: permissionModeLabel(m) + (m === current ? " (current)" : ""), description: permissionModeExplanation(m) })),
41
+ initial: PERMISSION_MODES.indexOf(current)
42
+ }));
43
+ if (chosen && chosen !== current) {
44
+ setPermissionMode(ctx.config, chosen);
45
+ confirm(chosen);
46
+ }
47
+ }
48
+ const COMPACT_REASONS = {
49
+ NOTHING_TO_COMPACT: "Nothing new to compact since the last summary.",
50
+ RESTRUCTURING_DISABLED: "Chat restructuring is turned off in your preferences, so a summary would not be used. Turn it on in Settings → Performance to compact.",
51
+ SNAPSHOTS_DISABLED: "Memory snapshots are turned off in your preferences, so a summary would not be used. Turn them on in Settings → Performance to compact.",
52
+ BUSY: "An automatic context restructure is running for this conversation. Try /compact again in a moment.",
53
+ SESSION_NOT_FOUND: "This conversation is no longer available. Run /sessions to pick another."
54
+ };
55
+ /**
56
+ * `/compact`: replace the conversation's earlier messages in the model's
57
+ * context with a bounded summary of its state. Same conversation, same task,
58
+ * same permission mode; nothing is deleted locally or on the server.
59
+ */
60
+ export async function runCompact(ctx, client) {
61
+ const sessionId = ctx.config.get("sessionId");
62
+ if (!sessionId) {
63
+ info("No active conversation to compact. Start one, or resume one with /sessions.");
64
+ return;
65
+ }
66
+ try {
67
+ const r = await withSpinner("Compacting…", () => client.compactSession(sessionId, getPermissionMode(ctx.config)));
68
+ if (!r.compacted) {
69
+ info(COMPACT_REASONS[r.reason ?? ""] ?? "Nothing was compacted.");
70
+ return;
71
+ }
72
+ success(`Compacted ${r.messages ?? 0} earlier message${r.messages === 1 ? "" : "s"} into a summary (v${r.version}).`);
73
+ line(" " + c.dim(`Kept: ${r.task_context ? "the task, plan, inspected and changed files, tests, corrections, " : ""}your requests and the permission mode. Nothing was deleted — /context shows the task.`));
74
+ }
75
+ catch (err) {
76
+ errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
77
+ }
78
+ }
@@ -11,7 +11,7 @@ import { screenActive } from "../ui/screen.js";
11
11
  * scope. `target` may be an id or a name; omit it for an interactive picker.
12
12
  */
13
13
  export function registerScope(program, ctx) {
14
- const workspace = program.command("workspace").description("Manage the active workspace");
14
+ const workspace = program.command("workspace").description("Advanced: manage API workspace scope (not local repositories)");
15
15
  workspace
16
16
  .command("list")
17
17
  .description("List your workspaces")
@@ -22,11 +22,11 @@ export function registerScope(program, ctx) {
22
22
  });
23
23
  workspace
24
24
  .command("use [target]")
25
- .description("Switch the active workspace (and pick a project in it)")
25
+ .description("Switch API workspace and automatically select its default project")
26
26
  .action(async (target) => {
27
27
  await useWorkspace(ctx, target);
28
28
  });
29
- const project = program.command("project").description("Manage the active project");
29
+ const project = program.command("project").description("Advanced: manage API project scope (not local repositories)");
30
30
  project
31
31
  .command("list")
32
32
  .description("List projects in the active workspace")
@@ -51,15 +51,16 @@ async function useWorkspace(ctx, target) {
51
51
  if (!ws)
52
52
  return unresolved("workspace", workspaces, activeWorkspaceId(ctx), (w) => `${w.name} ${dim(w.slug)}`);
53
53
  // A workspace switch needs a project in that workspace — pick its default, or
54
- // prompt when interactive.
54
+ // use the server-provided default ordering without a second prompt.
55
55
  const { projects } = await withSpinner("Loading projects…", () => listCliProjects(apiUrl, provider, ws.id));
56
56
  if (projects.length === 0) {
57
57
  errorLine(`Workspace "${ws.name}" has no projects. Create one in the dashboard first.`);
58
58
  process.exitCode = 1;
59
59
  return;
60
60
  }
61
- const proj = (await resolve(projects, undefined, `Select a project in ${ws.name}:`, (p) => `${p.name} (${p.environment})`)) ??
62
- projects[0];
61
+ // The API lists the default project first. Keep a valid current selection
62
+ // when reselecting the same workspace; otherwise use that server ordering.
63
+ const proj = projects.find((p) => p.id === activeProjectId(ctx)) ?? projects[0];
63
64
  await applyScope(ctx, apiUrl, provider, ws.id, proj.id);
64
65
  }
65
66
  async function useProject(ctx, target) {
@@ -97,6 +98,8 @@ async function resolve(items, target, message, labelFn) {
97
98
  return undefined;
98
99
  if (items.length === 0)
99
100
  return undefined;
101
+ if (items.length === 1)
102
+ return items[0];
100
103
  const id = await select({
101
104
  message,
102
105
  choices: items.map((i) => ({ name: labelFn(i), value: i.id }))
@@ -1,5 +1,6 @@
1
1
  import { ApiError } from "../services/api.js";
2
2
  import { errorLine, info, line, success, timeAgo } from "../services/output.js";
3
+ import { showTaskContext } from "../shell/task-context-view.js";
3
4
  import { clearActiveSession, listSessions, resolveSession, SessionRefError, setActiveSession } from "../services/session-resolver.js";
4
5
  import { withSpinner } from "../services/spinner.js";
5
6
  import { showHistory } from "./history.js";
@@ -117,6 +118,10 @@ export async function switchTo(ctx, client, ref) {
117
118
  // full context, so the person should too. Reuses /history's renderer, so
118
119
  // memory markers and clarification blocks render identically.
119
120
  await showHistory(ctx, client, s.session_id);
121
+ // Earlier coding work in that conversation, as context only (shell/task-context-view.ts).
122
+ if (typeof client.mutationRecoveryScope === "function") {
123
+ await showTaskContext(client, s.session_id);
124
+ }
120
125
  }
121
126
  catch (err) {
122
127
  reportRefError(err);