@carrieros/cli 0.4.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.
package/README.md CHANGED
@@ -57,14 +57,67 @@ reach the installed command and you end up debugging stale code.
57
57
 
58
58
  ### Update
59
59
 
60
- 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:
61
95
 
62
96
  ```bash
63
97
  npm install -g @carrieros/cli@latest
64
98
  ```
65
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
+
66
111
  Check what you're running with `cos version` — it prints the CLI version
67
- 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.
68
121
 
69
122
  ### Uninstall
70
123
 
@@ -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
@@ -8,6 +8,7 @@ import { withSpinner } from "../services/spinner.js";
8
8
  import { discoverRootWithoutGit, refreshWorkspace } from "../services/workspace.js";
9
9
  import { isTrusted } from "../ui/trust.js";
10
10
  import { COMMANDS_OPT_IN_ENV, localCommandsState } from "../services/client-tools.js";
11
+ import { getPermissionMode } from "../services/permission-mode.js";
11
12
  import { executionContract } from "../services/execution-platform.js";
12
13
  function row(status, label, detail) {
13
14
  const g = status === "ok" ? glyph.ok : status === "warn" ? glyph.warn : glyph.err;
@@ -92,19 +93,23 @@ export function registerDoctor(program, ctx) {
92
93
  }
93
94
  }
94
95
  // 6) Local capabilities. Reading and file changes follow folder trust;
95
- // running commands additionally needs an explicit opt-in, so say which
96
- // 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".
97
98
  const trusted = isTrusted(ctx.config, trustRoot) || isTrusted(ctx.config);
98
99
  row(trusted ? "ok" : "warn", "Folder trust", trusted ? `trusted: ${trustRoot}` : `not trusted: ${trustRoot}`);
99
100
  // The same check the shell uses to offer run_command, so the two agree
100
101
  // on every platform (Windows Job Object; macOS/Linux isolated runtime).
101
- const commands = localCommandsState(ctx, true);
102
+ const commands = localCommandsState(ctx, true, getPermissionMode(ctx.config) === "auto");
102
103
  const runtime = executionContract().backend === "docker-engine-v1" ? "isolated Linux container" : "Windows Job Object";
103
104
  const commandState = !commands.enabled
104
- ? `off — /settings commands on, or set ${COMMANDS_OPT_IN_ENV}=1 in this terminal`
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`
105
108
  : commands.blockedBy
106
109
  ? `not active — ${commands.blockedBy}`
107
- : `on (${runtime}) — every command still needs your approval`;
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`;
108
113
  row(commands.enabled && !commands.blockedBy ? "ok" : "warn", "Local commands", commandState);
109
114
  // 7) Versions
110
115
  row("ok", "CLI version", cliVersion());
@@ -19,6 +19,7 @@ export function registerLogout(program, ctx) {
19
19
  // Best-effort server revoke so the refresh token can't be reused.
20
20
  await withSpinner("Signing out…", () => logoutCliSession(apiUrl, refreshToken));
21
21
  }
22
+ ctx.noteSessionSelectionChanged();
22
23
  ctx.config.clearAuth();
23
24
  success("Logged out. This device's session has been removed.");
24
25
  });
@@ -48,6 +48,7 @@ export async function runPermissions(ctx, arg) {
48
48
  const COMPACT_REASONS = {
49
49
  NOTHING_TO_COMPACT: "Nothing new to compact since the last summary.",
50
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.",
51
52
  BUSY: "An automatic context restructure is running for this conversation. Try /compact again in a moment.",
52
53
  SESSION_NOT_FOUND: "This conversation is no longer available. Run /sessions to pick another."
53
54
  };
@@ -1,8 +1,11 @@
1
1
  import { COMMANDS_OPT_IN_ENV, localCommandsState } from "../services/client-tools.js";
2
+ import { getPermissionMode } from "../services/permission-mode.js";
2
3
  import { errorLine, line } from "../services/output.js";
3
4
  import { c } from "../ui/colors.js";
4
5
  import { sectionHeader } from "../ui/ui.js";
5
6
  import { executionAdapter, executionPlatform } from "../services/execution-platform.js";
7
+ import { updateSettings } from "../services/auto-update.js";
8
+ import { isUpdateChannel, packageName, UPDATE_CHANNELS } from "../services/update.js";
6
9
  /**
7
10
  * `cos settings` — the CLI's persisted behaviour settings, in one place.
8
11
  *
@@ -11,7 +14,9 @@ import { executionAdapter, executionPlatform } from "../services/execution-platf
11
14
  *
12
15
  * Most settings already have their own toggle (/fast, /hipwr, /sia, /websearch)
13
16
  * and keep it; this command lists them together and owns the one setting that
14
- * had no home: whether the model may propose running commands at all.
17
+ * had no home: whether the model may propose commands in Manual/Accept Edits.
18
+ * Selecting Auto also opts in for that session; an explicit `commands off`
19
+ * remains a hard stop.
15
20
  */
16
21
  export function registerSettings(program, ctx) {
17
22
  program
@@ -29,8 +34,14 @@ export function runSettings(ctx, argStr) {
29
34
  const [name = "", value = ""] = argStr.trim().toLowerCase().split(/\s+/);
30
35
  if (!name)
31
36
  return showSettings(ctx);
37
+ if (name === "updates" || name === "auto-updates")
38
+ return setAutoUpdates(ctx, value);
39
+ if (name === "channel" || name === "update-channel")
40
+ return setChannel(ctx, value);
41
+ if (name === "update-interval")
42
+ return setUpdateInterval(ctx, value);
32
43
  if (name !== "commands" && name !== "local-commands") {
33
- errorLine(`Unknown setting "${name}". Try: /settings commands on|off`);
44
+ errorLine(`Unknown setting "${name}". Try: /settings commands on|off, /settings updates on|off, /settings channel latest|beta|next|staging`);
34
45
  return;
35
46
  }
36
47
  if (!ON.has(value) && !OFF.has(value)) {
@@ -47,7 +58,7 @@ export function runSettings(ctx, argStr) {
47
58
  ...LOCAL_COMMANDS_NOTICE.slice(0, 3),
48
59
  "Approved project code runs in a configured isolated Linux container.",
49
60
  "Only the selected repository is mounted; network access is disabled.",
50
- LOCAL_COMMANDS_NOTICE[5]
61
+ LOCAL_COMMANDS_NOTICE[LOCAL_COMMANDS_NOTICE.length - 1]
51
62
  ];
52
63
  for (const l of notice)
53
64
  line(" " + c.dim(l));
@@ -63,24 +74,75 @@ export function runSettings(ctx, argStr) {
63
74
  * here that lets project code run.
64
75
  */
65
76
  export const LOCAL_COMMANDS_NOTICE = [
66
- "The model may now PROPOSE commands such as npm test or git status.",
67
- "Every command still needs your approval, only runs in a trusted repository,",
68
- "and is limited to an allowlist (no shells, no network tools, no git writes).",
77
+ "Manual/Accept Edits may now propose local commands such as npm test or git status.",
78
+ "Manual asks before each command; Auto opts in and runs locally allowed commands without an individual prompt.",
79
+ "Commands only run in a trusted repository and remain subject to the allowlist,",
80
+ "runtime containment and cancellation checks (no shells, network tools or git writes).",
69
81
  "Approved project code runs as your Windows account: it can read what you can",
70
82
  "read, and may open other applications through Windows file associations.",
71
83
  "Turn it off again with /settings commands off."
72
84
  ];
85
+ /** Automatic background updates. /update keeps working either way. */
86
+ function setAutoUpdates(ctx, value) {
87
+ if (!ON.has(value) && !OFF.has(value)) {
88
+ errorLine("Use /settings updates on or /settings updates off.");
89
+ return;
90
+ }
91
+ const enable = ON.has(value);
92
+ ctx.config.set("autoUpdates", enable);
93
+ line();
94
+ line(" " + c.ok("✓") + " " + c.value(enable ? "Automatic updates enabled." : "Automatic updates disabled.") +
95
+ " " + c.dim(enable ? "New releases install in the background when you exit." : "Run /update to check and install manually."));
96
+ line();
97
+ }
98
+ /** Which npm dist-tag to follow. Only ever changed here, by the user. */
99
+ function setChannel(ctx, value) {
100
+ if (!isUpdateChannel(value)) {
101
+ errorLine(`Use /settings channel ${UPDATE_CHANNELS.join("|")}.`);
102
+ return;
103
+ }
104
+ if (packageName() === "@carrieros/cli-staging" && value !== "staging") {
105
+ errorLine("The staging CLI always follows its isolated staging update channel.");
106
+ return;
107
+ }
108
+ if (value === "staging" && packageName() !== "@carrieros/cli-staging") {
109
+ errorLine("The staging update channel is available only in the staging CLI package.");
110
+ return;
111
+ }
112
+ ctx.config.set("updateChannel", value);
113
+ // The cached result belongs to the previous channel.
114
+ ctx.config.set("latestCliVersion", undefined);
115
+ ctx.config.set("updateCheckAt", undefined);
116
+ ctx.config.set("updateNoticeShown", undefined);
117
+ line();
118
+ line(" " + c.ok("✓") + " " + c.value(`Update channel set to ${value}.`) + " " +
119
+ c.dim(value === "latest" ? "Stable releases only." : "Pre-releases on this channel will be offered. /update checks now."));
120
+ line();
121
+ }
122
+ function setUpdateInterval(ctx, value) {
123
+ const hours = Number(value);
124
+ if (!Number.isInteger(hours) || hours < 1 || hours > 168) {
125
+ errorLine("Use /settings update-interval <hours>, between 1 and 168.");
126
+ return;
127
+ }
128
+ ctx.config.set("updateCheckIntervalHours", hours);
129
+ line();
130
+ line(" " + c.ok("✓") + " " + c.value(`Checking for updates every ${hours} hour${hours === 1 ? "" : "s"}.`) + " " + c.dim("Applies from the next start."));
131
+ line();
132
+ }
73
133
  function showSettings(ctx) {
74
- const state = localCommandsState(ctx);
134
+ const state = localCommandsState(ctx, undefined, getPermissionMode(ctx.config) === "auto");
75
135
  const row = (label, value, note = "") => line(" " + c.label(label.padEnd(16)) + value + (note ? " " + c.dim(note) : ""));
76
136
  line();
77
137
  line(sectionHeader("Settings"));
78
138
  line();
79
139
  row("Local commands", state.enabled ? c.ok("enabled") : c.dim("disabled"), state.source === "env"
80
140
  ? `via ${COMMANDS_OPT_IN_ENV}=1`
81
- : state.enabled
82
- ? "/settings commands off to stop"
83
- : "/settings commands on to allow");
141
+ : state.source === "auto"
142
+ ? "enabled by Auto for this session"
143
+ : state.enabled
144
+ ? "/settings commands off to stop"
145
+ : "/settings commands on to allow");
84
146
  if (state.enabled && state.blockedBy)
85
147
  row("", c.warn("not active"), state.blockedBy);
86
148
  row("Mode", c.value(ctx.mode));
@@ -90,5 +152,9 @@ function showSettings(ctx) {
90
152
  row("Clarification", c.value(ctx.siaMode), "/sia");
91
153
  const web = ctx.webSearch;
92
154
  row("Web search", web === undefined ? c.dim("workspace default") : web ? c.ok("on") : c.dim("off"), "/websearch");
155
+ const updates = updateSettings(ctx.config);
156
+ row("Auto updates", updates.autoUpdates ? c.ok("on") : c.dim("off"), "/settings updates on|off");
157
+ row("Update channel", c.value(updates.channel), "/settings channel latest|beta|next|staging");
158
+ row("Update checks", c.value(`every ${updates.intervalHours}h`), "/settings update-interval <hours>");
93
159
  line();
94
160
  }
@@ -2,7 +2,8 @@ import { line } from "../services/output.js";
2
2
  import { withSpinner } from "../services/spinner.js";
3
3
  import { isPackaged, isSignedRelease, PACKAGED_DOWNLOAD_URL } from "../services/packaged.js";
4
4
  import { checkInstallerSignature, checkPackagedUpdate, downloadVerified, launchInstaller, updatesDir, UpdateError } from "../services/packaged-update.js";
5
- import { checkForUpdate, installLatest, isLinkedInstallation, PACKAGE_NAME, verifyInstallation } from "../services/update.js";
5
+ import { acquireUpdateLock, checkChannel, defaultUpdateChannel, detectInstallation, installExactVersion, manualUpdateCommand, PACKAGE_NAME, packageName, releaseUpdateLock, updateInProgress } from "../services/update.js";
6
+ import { updateSettings } from "../services/auto-update.js";
6
7
  import { c } from "../ui/colors.js";
7
8
  import { pickFromList } from "../ui/select.js";
8
9
  /**
@@ -28,7 +29,7 @@ function versions(current, latest) {
28
29
  line(" " + c.dim("Latest version: ") + c.value(latest));
29
30
  line();
30
31
  }
31
- function renderTerminalState(state) {
32
+ function renderTerminalState(state, manual = MANUAL) {
32
33
  if (state.kind === "current") {
33
34
  line();
34
35
  line(" " + c.ok("✓") + " " + c.value("Carrier OS CLI is already up to date (v" + state.current + ")"));
@@ -49,7 +50,7 @@ function renderTerminalState(state) {
49
50
  line();
50
51
  line(" " + c.dim("npm was not found on this system."));
51
52
  line(" " + c.dim("Update manually with:"));
52
- line(" " + c.cmd(MANUAL));
53
+ line(" " + c.cmd(manual));
53
54
  line();
54
55
  return;
55
56
  }
@@ -62,50 +63,95 @@ function renderTerminalState(state) {
62
63
  line();
63
64
  }
64
65
  /**
65
- * `/update` and `cos update` — the entire user-facing surface.
66
+ * `/update` and `cos update` — check the configured channel and, if a newer
67
+ * release exists, offer to install it.
66
68
  *
67
- * One command: check, and if something newer exists, offer to install it. The
68
- * check/install split exists only as functions in services/update.ts — exposing
69
- * it as subcommands would make the user choose between two things that are
70
- * really one intention.
71
- *
72
- * Nothing is installed without an explicit Yes, and the process is never
73
- * restarted: npm swaps files under a running Node, and re-execing through the
74
- * shim while the old process still holds handles is how partial installs occur.
69
+ * Nothing is installed without an explicit Yes (or --yes), never during a
70
+ * running agent turn, and never over a local, development, npx or unwritable
71
+ * install — those get the right manual command instead. The process is never
72
+ * restarted: the user is told to restart once the new version is verified on
73
+ * disk. Settings (channel) come from the CLI's own config.
75
74
  */
76
75
  export async function runUpdate(opts = {}) {
77
- // The packaged executable has no npm to update through. Point at the download
78
- // rather than running an npm command that cannot exist in that environment.
76
+ // The packaged executable has no npm to update through.
79
77
  if (isPackaged()) {
80
78
  await runPackagedUpdate(opts.assumeYes === true);
81
79
  return;
82
80
  }
83
- const state = await withSpinner(c.dim("Checking for updates…"), async () => checkForUpdate());
84
- // Up to date, ahead of the registry, npm missing, or unreachable — each says
85
- // everything it needs to, including how to update by hand.
86
- if (state.kind !== "available") {
87
- renderTerminalState(state);
81
+ // Never alongside a running agent task: it may be using files npm would replace.
82
+ if (opts.busy) {
83
+ line();
84
+ line(" " + c.warn("⚠") + " " + c.value("An agent task is running. Run /update again when it has finished."));
85
+ line();
88
86
  return;
89
87
  }
90
- // MANDATORY GUARD, before anything can write. `npm i -g` against a linked
91
- // install replaces the symlink, silently detaching a developer's checkout.
92
- if (isLinkedInstallation()) {
93
- heading();
94
- versions(state.current, state.latest);
95
- line(" " + c.warn("⚠") + " " + c.value("Running from a linked development checkout."));
88
+ const channel = opts.config ? updateSettings(opts.config).channel : defaultUpdateChannel();
89
+ const manual = manualUpdateCommand(channel);
90
+ const state = await withSpinner(c.dim("Checking for updates…"), () => checkChannel(channel));
91
+ if (state.kind === "current") {
92
+ line();
93
+ line(" " + c.ok("✓") + " " + c.value("You are using the latest version of CarrierOS CLI.") + c.dim(" (v" + state.current + (channel === "latest" ? "" : ", " + channel + " channel") + ")"));
96
94
  line();
97
- line(" " + c.dim("Automatic update is disabled here — it would replace the link."));
98
- line(" " + c.dim("Install a published version from npm before using /update."));
95
+ return;
96
+ }
97
+ if (state.kind === "no-channel") {
98
+ heading();
99
+ line(" " + c.dim("Current version: ") + c.value(state.current));
100
+ line(" " + c.warn("⚠") + " " + c.value(state.detail));
101
+ line(" " + c.dim("Switch back with: ") + c.cmd("/settings channel latest"));
99
102
  line();
100
103
  return;
101
104
  }
105
+ if (state.kind !== "available") {
106
+ renderTerminalState(state, manual);
107
+ return;
108
+ }
102
109
  heading();
103
110
  versions(state.current, state.latest);
104
- line(" " + c.value("A new version is available."));
111
+ const install = opts.installation ?? (await detectInstallation());
112
+ if (install.kind === "development") {
113
+ line(" " + c.warn("⚠") + " " + c.value("Running from a development checkout (or npm link)."));
114
+ line(" " + c.dim("Automatic update is disabled here — it would replace the link to your checkout."));
115
+ line(" " + c.dim("Install the published CLI with: ") + c.cmd(manual));
116
+ line();
117
+ return;
118
+ }
119
+ if (install.kind === "local") {
120
+ line(" " + c.value("This copy is installed as a project dependency."));
121
+ line(" " + c.dim("Update it with your package manager, e.g. ") + c.cmd("npm install " + packageName() + "@" + state.latest));
122
+ line();
123
+ return;
124
+ }
125
+ if (install.kind === "npx") {
126
+ line(" " + c.dim("Running through npx. Use the new version with: ") + c.cmd("npx " + packageName() + "@" + channel));
127
+ line();
128
+ return;
129
+ }
130
+ if (install.kind !== "global") {
131
+ line(" " + c.dim("This installation cannot be updated automatically. Update with:"));
132
+ line(" " + c.cmd(manual));
133
+ line();
134
+ return;
135
+ }
136
+ if (!install.writable) {
137
+ line(" " + c.warn("⚠") + " " + c.value("Your global npm folder is not writable by this user."));
138
+ line(" " + c.dim("Carrier OS will not request administrator rights. Update with:"));
139
+ line(" " + c.cmd(manual));
140
+ line();
141
+ return;
142
+ }
143
+ const dir = opts.config && "dir" in opts.config ? opts.config.dir : null;
144
+ if (dir && updateInProgress(dir)) {
145
+ line(" " + c.value("An update is already being installed in the background."));
146
+ line(" " + c.dim("Restart Carrier OS CLI in a moment to use it."));
147
+ line();
148
+ return;
149
+ }
150
+ line(" " + c.value("CarrierOS CLI " + state.latest + " is available."));
105
151
  line();
106
152
  const answer = opts.assumeYes ? "yes" : await pickFromList({
107
153
  title: "Update now?",
108
- description: "Runs " + MANUAL,
154
+ description: "Runs npm install -g " + packageName() + "@" + state.latest,
109
155
  choices: [
110
156
  { value: "yes", label: "Yes", description: "Install v" + state.latest + " now" },
111
157
  { value: "no", label: "No", description: "Stay on v" + state.current }
@@ -119,16 +165,25 @@ export async function runUpdate(opts = {}) {
119
165
  line();
120
166
  return;
121
167
  }
122
- const result = await withSpinner(c.dim("Updating Carrier OS CLI…"), async () => installLatest());
123
- if (!result.ok) {
168
+ if (dir && !acquireUpdateLock(dir)) {
169
+ line(" " + c.value("An update is already being installed. Try again in a moment."));
124
170
  line();
125
- line(" " + c.err("✗") + " " + c.value("Update failed."));
171
+ return;
172
+ }
173
+ let result;
174
+ try {
175
+ result = await withSpinner(c.dim("Installing CarrierOS CLI " + state.latest + "…"), () => installExactVersion(state.latest, install.globalRoot ?? null));
176
+ }
177
+ finally {
178
+ if (dir)
179
+ releaseUpdateLock(dir);
180
+ }
181
+ if (!result.ok) {
126
182
  line();
127
- line(" " + c.dim("Carrier OS CLI remains at v") + c.value(state.current) + c.dim("."));
128
- if (result.permission) {
129
- line(" " + c.dim("This looks like a permissions problem — try an elevated terminal,"));
130
- line(" " + c.dim("or run: ") + c.cmd(MANUAL));
131
- }
183
+ line(" " + c.err("✗") + " " + c.value("CarrierOS CLI could not be updated."));
184
+ line(" " + c.dim("You are still on v") + c.value(state.current) + c.dim(". Update manually with: ") + c.cmd(manual));
185
+ if (result.permission)
186
+ line(" " + c.dim("npm reported a permissions problem with the global npm folder."));
132
187
  if (result.detail) {
133
188
  line();
134
189
  for (const l of result.detail.split("\n").slice(0, 6))
@@ -137,14 +192,15 @@ export async function runUpdate(opts = {}) {
137
192
  line();
138
193
  return;
139
194
  }
140
- // Trust the disk, not this process: our own package.json was read at startup
141
- // and the old modules stay loaded, so cliVersion() cannot see the swap.
142
- const installed = verifyInstallation() ?? state.latest;
143
- line();
144
- line(" " + c.ok("✓") + " " + c.value("Carrier OS CLI updated successfully."));
145
- line(" " + c.dim(state.current) + c.dim(" → ") + c.value(installed));
195
+ // Verified on disk (installExactVersion reads the installed package.json).
196
+ if (opts.config) {
197
+ opts.config.set("pendingUpdate", undefined);
198
+ opts.config.set("updateFailedVersion", undefined);
199
+ }
146
200
  line();
147
- line(" " + c.dim("Restart Carrier OS CLI to use the new version."));
201
+ line(" " + c.ok("✓") + " " + c.value("CarrierOS CLI " + result.installed + " has been installed successfully."));
202
+ line(" " + c.dim(state.current) + c.dim(" → ") + c.value(String(result.installed)));
203
+ line(" " + c.dim("Restart the CLI to use the new version."));
148
204
  line();
149
205
  }
150
206
  /**
@@ -218,12 +274,12 @@ async function runPackagedUpdate(assumeYes) {
218
274
  line();
219
275
  }
220
276
  }
221
- export function registerUpdate(program, _ctx) {
277
+ export function registerUpdate(program, ctx) {
222
278
  program
223
279
  .command("update")
224
280
  .description("Check for and install the latest Carrier OS CLI version")
225
281
  .option("-y, --yes", "install an available update without asking (for scripts)")
226
282
  .action(async (opts) => {
227
- await runUpdate({ assumeYes: opts.yes === true });
283
+ await runUpdate({ assumeYes: opts.yes === true, config: ctx.config });
228
284
  });
229
285
  }
@@ -125,16 +125,18 @@ export function renderCredits(credits) {
125
125
  const pools = credits.models ?? [];
126
126
  if (pools.length === 0 || unlimited)
127
127
  return;
128
+ // The name the web model picker shows; the id only when the server sends none.
129
+ const label = (p) => p.display_name || p.model;
128
130
  const spent = (p) => p.status === "exceeded" || p.remaining <= 0;
129
131
  const available = pools.filter((p) => !spent(p)).sort((a, b) => b.remaining - a.remaining);
130
- const exhausted = pools.filter(spent).sort((a, b) => a.model.localeCompare(b.model));
132
+ const exhausted = pools.filter(spent).sort((a, b) => label(a).localeCompare(label(b)));
131
133
  line();
132
134
  line(sectionHeader(`Model credits (${available.length} of ${pools.length} available)`));
133
135
  line();
134
136
  // What you CAN use, with its balance, in as many columns as the terminal
135
137
  // fits — this is the actionable half, so it keeps its numbers.
136
138
  if (available.length > 0) {
137
- for (const l of grid(available.map((p) => [p.model, dec(p.remaining)]))) {
139
+ for (const l of grid(available.map((p) => [label(p), dec(p.remaining)]))) {
138
140
  line(l);
139
141
  }
140
142
  }
@@ -146,7 +148,7 @@ export function renderCredits(credits) {
146
148
  if (exhausted.length > 0) {
147
149
  line();
148
150
  line(" " + c.err("✕") + c.dim(` ${exhausted.length} exhausted`));
149
- for (const l of wrap(exhausted.map((p) => p.model).join(", "), Math.max(20, panelWidth() - 6))) {
151
+ for (const l of wrap(exhausted.map(label).join(", "), Math.max(20, panelWidth() - 6))) {
150
152
  line(" " + c.dim(l));
151
153
  }
152
154
  }
@@ -3,10 +3,9 @@ import { cliVersion } from "../services/meta.js";
3
3
  import { kv, line } from "../services/output.js";
4
4
  /**
5
5
  * `cos version` — CLI version (from package.json) + best-effort live API
6
- * version. Prints:
6
+ * version. It deliberately omits the configured API URL. Prints:
7
7
  * Carrier OS CLI 0.1.0
8
8
  * API Version v1
9
- * Endpoint http://localhost:5000/v1
10
9
  */
11
10
  export function registerVersion(program, ctx) {
12
11
  program
@@ -22,7 +21,6 @@ export function registerVersion(program, ctx) {
22
21
  catch {
23
22
  kv("API Version", chalk.dim("unreachable"));
24
23
  }
25
- kv("Endpoint", ctx.config.get("apiUrl") ?? "—");
26
24
  line();
27
25
  });
28
26
  }