@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.
- package/README.md +89 -15
- package/dist/commands/chat.js +6 -6
- package/dist/commands/context.js +40 -0
- package/dist/commands/doctor.js +34 -14
- package/dist/commands/logout.js +2 -0
- package/dist/commands/permissions.js +78 -0
- package/dist/commands/scope.js +9 -6
- package/dist/commands/sessions.js +5 -0
- package/dist/commands/settings.js +83 -10
- package/dist/commands/update.js +177 -51
- package/dist/commands/usage.js +10 -8
- package/dist/commands/version.js +1 -3
- package/dist/commands/whoami.js +12 -9
- package/dist/ide/editor-context.js +115 -12
- package/dist/ide/ide-session.js +288 -18
- package/dist/ide/tool-host.js +6 -6
- package/dist/main.js +10 -1
- package/dist/services/api.js +183 -15
- package/dist/services/auth-origin.js +20 -0
- package/dist/services/auto-update.js +221 -0
- package/dist/services/chat-stream.js +26 -3
- package/dist/services/checkpoints.js +176 -14
- package/dist/services/client-tools.js +123 -27
- package/dist/services/code-intel.js +243 -0
- package/dist/services/code-symbols.js +94 -0
- package/dist/services/coding-workflow.js +554 -0
- package/dist/services/command-coordinator.js +85 -12
- package/dist/services/command-policy.js +34 -4
- package/dist/services/config.js +96 -11
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +98 -25
- package/dist/services/device-auth.js +33 -6
- package/dist/services/execution-platform.js +30 -0
- package/dist/services/file-resolver.js +1 -1
- package/dist/services/folder-key.js +22 -0
- package/dist/services/git-tools.js +181 -0
- package/dist/services/helper-bin.js +56 -35
- package/dist/services/instruction-resolver.js +54 -0
- package/dist/services/job-helper.js +31 -10
- package/dist/services/local-files.js +148 -26
- package/dist/services/local-tools.js +540 -35
- package/dist/services/login-flow.js +44 -13
- package/dist/services/meta.js +27 -0
- package/dist/services/mutation-coordinator.js +186 -20
- package/dist/services/mutation-groups.js +309 -0
- package/dist/services/mutation-recovery.js +159 -0
- package/dist/services/mutations.js +264 -78
- package/dist/services/packaged-update.js +403 -0
- package/dist/services/packaged.js +15 -0
- package/dist/services/permission-mode.js +78 -0
- package/dist/services/process-runner.js +7 -1
- package/dist/services/project-context.js +4 -4
- package/dist/services/result-reconciliation.js +49 -0
- package/dist/services/secure-store.js +21 -1
- package/dist/services/session-resolver.js +7 -0
- package/dist/services/supported-runtime.js +59 -0
- package/dist/services/task-context.js +212 -0
- package/dist/services/task-snapshot.js +38 -0
- package/dist/services/tool-result-outbox.js +195 -0
- package/dist/services/update.js +457 -13
- package/dist/services/workspace-registry.js +4 -3
- package/dist/services/workspace.js +8 -1
- package/dist/shell/shell-chat.js +320 -34
- package/dist/shell/shell-commands.js +47 -5
- package/dist/shell/shell-prompt.js +21 -11
- package/dist/shell/shell-renderer.js +1 -1
- package/dist/shell/shell.js +107 -20
- package/dist/shell/task-context-view.js +40 -0
- package/dist/ui/agent-cards.js +111 -0
- package/dist/ui/agent-presentation.js +131 -0
- package/dist/ui/approval.js +46 -16
- package/dist/ui/banner.js +31 -87
- package/dist/ui/change-review.js +293 -46
- package/dist/ui/chat-renderer.js +6 -6
- package/dist/ui/colors.js +9 -9
- package/dist/ui/command-details.js +11 -0
- package/dist/ui/command-palette.js +27 -10
- package/dist/ui/command-registry.js +11 -4
- package/dist/ui/command-review.js +77 -28
- package/dist/ui/composer-layout.js +26 -20
- package/dist/ui/conversation.js +77 -25
- package/dist/ui/live.js +1 -1
- package/dist/ui/screen.js +19 -11
- package/dist/ui/select.js +6 -0
- package/dist/ui/task-context-card.js +99 -0
- package/dist/ui/trust.js +7 -12
- package/dist/ui/ui.js +23 -0
- package/package.json +9 -5
|
@@ -1,7 +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";
|
|
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";
|
|
5
9
|
/**
|
|
6
10
|
* `cos settings` — the CLI's persisted behaviour settings, in one place.
|
|
7
11
|
*
|
|
@@ -10,7 +14,9 @@ import { sectionHeader } from "../ui/ui.js";
|
|
|
10
14
|
*
|
|
11
15
|
* Most settings already have their own toggle (/fast, /hipwr, /sia, /websearch)
|
|
12
16
|
* and keep it; this command lists them together and owns the one setting that
|
|
13
|
-
* had no home: whether the model may propose
|
|
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.
|
|
14
20
|
*/
|
|
15
21
|
export function registerSettings(program, ctx) {
|
|
16
22
|
program
|
|
@@ -28,8 +34,14 @@ export function runSettings(ctx, argStr) {
|
|
|
28
34
|
const [name = "", value = ""] = argStr.trim().toLowerCase().split(/\s+/);
|
|
29
35
|
if (!name)
|
|
30
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);
|
|
31
43
|
if (name !== "commands" && name !== "local-commands") {
|
|
32
|
-
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`);
|
|
33
45
|
return;
|
|
34
46
|
}
|
|
35
47
|
if (!ON.has(value) && !OFF.has(value)) {
|
|
@@ -42,7 +54,13 @@ export function runSettings(ctx, argStr) {
|
|
|
42
54
|
if (enable) {
|
|
43
55
|
line(" " + c.ok("✓") + " " + c.value("Local commands enabled."));
|
|
44
56
|
// Said plainly at the moment it is switched on: what a command can do.
|
|
45
|
-
|
|
57
|
+
const notice = executionAdapter(executionPlatform()) === "windows-job" ? LOCAL_COMMANDS_NOTICE : [
|
|
58
|
+
...LOCAL_COMMANDS_NOTICE.slice(0, 3),
|
|
59
|
+
"Approved project code runs in a configured isolated Linux container.",
|
|
60
|
+
"Only the selected repository is mounted; network access is disabled.",
|
|
61
|
+
LOCAL_COMMANDS_NOTICE[LOCAL_COMMANDS_NOTICE.length - 1]
|
|
62
|
+
];
|
|
63
|
+
for (const l of notice)
|
|
46
64
|
line(" " + c.dim(l));
|
|
47
65
|
}
|
|
48
66
|
else {
|
|
@@ -56,24 +74,75 @@ export function runSettings(ctx, argStr) {
|
|
|
56
74
|
* here that lets project code run.
|
|
57
75
|
*/
|
|
58
76
|
export const LOCAL_COMMANDS_NOTICE = [
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
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).",
|
|
62
81
|
"Approved project code runs as your Windows account: it can read what you can",
|
|
63
82
|
"read, and may open other applications through Windows file associations.",
|
|
64
83
|
"Turn it off again with /settings commands off."
|
|
65
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
|
+
}
|
|
66
133
|
function showSettings(ctx) {
|
|
67
|
-
const state = localCommandsState(ctx);
|
|
134
|
+
const state = localCommandsState(ctx, undefined, getPermissionMode(ctx.config) === "auto");
|
|
68
135
|
const row = (label, value, note = "") => line(" " + c.label(label.padEnd(16)) + value + (note ? " " + c.dim(note) : ""));
|
|
69
136
|
line();
|
|
70
137
|
line(sectionHeader("Settings"));
|
|
71
138
|
line();
|
|
72
139
|
row("Local commands", state.enabled ? c.ok("enabled") : c.dim("disabled"), state.source === "env"
|
|
73
140
|
? `via ${COMMANDS_OPT_IN_ENV}=1`
|
|
74
|
-
: state.
|
|
75
|
-
? "
|
|
76
|
-
:
|
|
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");
|
|
77
146
|
if (state.enabled && state.blockedBy)
|
|
78
147
|
row("", c.warn("not active"), state.blockedBy);
|
|
79
148
|
row("Mode", c.value(ctx.mode));
|
|
@@ -83,5 +152,9 @@ function showSettings(ctx) {
|
|
|
83
152
|
row("Clarification", c.value(ctx.siaMode), "/sia");
|
|
84
153
|
const web = ctx.webSearch;
|
|
85
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>");
|
|
86
159
|
line();
|
|
87
160
|
}
|
package/dist/commands/update.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { line } from "../services/output.js";
|
|
2
2
|
import { withSpinner } from "../services/spinner.js";
|
|
3
|
-
import { isPackaged, PACKAGED_DOWNLOAD_URL } from "../services/packaged.js";
|
|
4
|
-
import {
|
|
3
|
+
import { isPackaged, isSignedRelease, PACKAGED_DOWNLOAD_URL } from "../services/packaged.js";
|
|
4
|
+
import { checkInstallerSignature, checkPackagedUpdate, downloadVerified, launchInstaller, updatesDir, UpdateError } from "../services/packaged-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";
|
|
5
7
|
import { c } from "../ui/colors.js";
|
|
6
8
|
import { pickFromList } from "../ui/select.js";
|
|
7
9
|
/**
|
|
@@ -27,7 +29,7 @@ function versions(current, latest) {
|
|
|
27
29
|
line(" " + c.dim("Latest version: ") + c.value(latest));
|
|
28
30
|
line();
|
|
29
31
|
}
|
|
30
|
-
function renderTerminalState(state) {
|
|
32
|
+
function renderTerminalState(state, manual = MANUAL) {
|
|
31
33
|
if (state.kind === "current") {
|
|
32
34
|
line();
|
|
33
35
|
line(" " + c.ok("✓") + " " + c.value("Carrier OS CLI is already up to date (v" + state.current + ")"));
|
|
@@ -48,7 +50,7 @@ function renderTerminalState(state) {
|
|
|
48
50
|
line();
|
|
49
51
|
line(" " + c.dim("npm was not found on this system."));
|
|
50
52
|
line(" " + c.dim("Update manually with:"));
|
|
51
|
-
line(" " + c.cmd(
|
|
53
|
+
line(" " + c.cmd(manual));
|
|
52
54
|
line();
|
|
53
55
|
return;
|
|
54
56
|
}
|
|
@@ -61,53 +63,95 @@ function renderTerminalState(state) {
|
|
|
61
63
|
line();
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
64
|
-
* `/update` and `cos update` — the
|
|
66
|
+
* `/update` and `cos update` — check the configured channel and, if a newer
|
|
67
|
+
* release exists, offer to install it.
|
|
65
68
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* Nothing is installed without an explicit Yes, and the process is never
|
|
72
|
-
* restarted: npm swaps files under a running Node, and re-execing through the
|
|
73
|
-
* 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.
|
|
74
74
|
*/
|
|
75
|
-
export async function runUpdate() {
|
|
76
|
-
// The packaged executable has no npm to update through.
|
|
77
|
-
// rather than running an npm command that cannot exist in that environment.
|
|
75
|
+
export async function runUpdate(opts = {}) {
|
|
76
|
+
// The packaged executable has no npm to update through.
|
|
78
77
|
if (isPackaged()) {
|
|
78
|
+
await runPackagedUpdate(opts.assumeYes === true);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Never alongside a running agent task: it may be using files npm would replace.
|
|
82
|
+
if (opts.busy) {
|
|
79
83
|
line();
|
|
80
|
-
line(" " + c.
|
|
81
|
-
line(" " + c.dim("Download the latest build from ") + c.value(PACKAGED_DOWNLOAD_URL) + c.dim("."));
|
|
84
|
+
line(" " + c.warn("⚠") + " " + c.value("An agent task is running. Run /update again when it has finished."));
|
|
82
85
|
line();
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (state.kind
|
|
89
|
-
|
|
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") + ")"));
|
|
94
|
+
line();
|
|
90
95
|
return;
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
// install replaces the symlink, silently detaching a developer's checkout.
|
|
94
|
-
if (isLinkedInstallation()) {
|
|
97
|
+
if (state.kind === "no-channel") {
|
|
95
98
|
heading();
|
|
96
|
-
|
|
97
|
-
line(" " + c.warn("⚠") + " " + c.value(
|
|
98
|
-
line();
|
|
99
|
-
line(" " + c.dim("Automatic update is disabled here — it would replace the link."));
|
|
100
|
-
line(" " + c.dim("Install a published version from npm before using /update."));
|
|
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"));
|
|
101
102
|
line();
|
|
102
103
|
return;
|
|
103
104
|
}
|
|
105
|
+
if (state.kind !== "available") {
|
|
106
|
+
renderTerminalState(state, manual);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
104
109
|
heading();
|
|
105
110
|
versions(state.current, state.latest);
|
|
106
|
-
|
|
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."));
|
|
107
151
|
line();
|
|
108
|
-
const answer = await pickFromList({
|
|
152
|
+
const answer = opts.assumeYes ? "yes" : await pickFromList({
|
|
109
153
|
title: "Update now?",
|
|
110
|
-
description: "Runs " +
|
|
154
|
+
description: "Runs npm install -g " + packageName() + "@" + state.latest,
|
|
111
155
|
choices: [
|
|
112
156
|
{ value: "yes", label: "Yes", description: "Install v" + state.latest + " now" },
|
|
113
157
|
{ value: "no", label: "No", description: "Stay on v" + state.current }
|
|
@@ -121,16 +165,25 @@ export async function runUpdate() {
|
|
|
121
165
|
line();
|
|
122
166
|
return;
|
|
123
167
|
}
|
|
124
|
-
|
|
125
|
-
|
|
168
|
+
if (dir && !acquireUpdateLock(dir)) {
|
|
169
|
+
line(" " + c.value("An update is already being installed. Try again in a moment."));
|
|
126
170
|
line();
|
|
127
|
-
|
|
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) {
|
|
128
182
|
line();
|
|
129
|
-
line(" " + c.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
line(" " + c.dim("
|
|
133
|
-
}
|
|
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."));
|
|
134
187
|
if (result.detail) {
|
|
135
188
|
line();
|
|
136
189
|
for (const l of result.detail.split("\n").slice(0, 6))
|
|
@@ -139,21 +192,94 @@ export async function runUpdate() {
|
|
|
139
192
|
line();
|
|
140
193
|
return;
|
|
141
194
|
}
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
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
|
+
}
|
|
145
200
|
line();
|
|
146
|
-
line(" " + c.ok("✓") + " " + c.value("
|
|
147
|
-
line(" " + c.dim(state.current) + c.dim(" → ") + c.value(installed));
|
|
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
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The packaged (installer) update: check the release manifest, then — only
|
|
208
|
+
* after an explicit Yes — download, verify the checksum (and the signature on
|
|
209
|
+
* a signed build), hand the installer this PID and exit. The installer waits
|
|
210
|
+
* for this process to end before replacing cos.exe, so nothing is swapped
|
|
211
|
+
* underneath a running CLI. Every failure leaves the current version intact.
|
|
212
|
+
*/
|
|
213
|
+
async function runPackagedUpdate(assumeYes) {
|
|
214
|
+
const state = await withSpinner(c.dim("Checking for updates…"), () => checkPackagedUpdate());
|
|
215
|
+
if (state.kind === "current") {
|
|
216
|
+
renderTerminalState({ kind: "current", current: state.current, latest: state.latest });
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (state.kind === "ahead") {
|
|
220
|
+
heading();
|
|
221
|
+
versions(state.current, state.latest);
|
|
222
|
+
line(" " + c.ok("✓") + " " + c.value("You are running a newer version than the latest release."));
|
|
223
|
+
line(" " + c.dim("Nothing to do — this will not downgrade."));
|
|
224
|
+
line();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (state.kind === "unreachable") {
|
|
228
|
+
heading();
|
|
229
|
+
line(" " + c.err("✗") + " " + c.value("Could not check for the latest version."));
|
|
230
|
+
line();
|
|
231
|
+
line(" " + c.dim("Your current version: ") + c.value(state.current));
|
|
232
|
+
line(" " + c.dim(state.detail));
|
|
233
|
+
line(" " + c.dim("You can also download the installer from ") + c.value(PACKAGED_DOWNLOAD_URL) + c.dim("."));
|
|
234
|
+
line();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const artifact = state.manifest.artifacts["win-x64-setup"];
|
|
238
|
+
heading();
|
|
239
|
+
versions(state.current, state.latest);
|
|
240
|
+
line(" " + c.value("A new version is available."));
|
|
150
241
|
line();
|
|
242
|
+
const answer = assumeYes ? "yes" : await pickFromList({
|
|
243
|
+
title: "Update now?",
|
|
244
|
+
description: `Downloads ${artifact.file} (${(artifact.size / 1024 / 1024).toFixed(1)} MB), verifies it, then installs it`,
|
|
245
|
+
choices: [
|
|
246
|
+
{ value: "yes", label: "Yes", description: "Install v" + state.latest + " — Carrier OS closes while it updates" },
|
|
247
|
+
{ value: "no", label: "No", description: "Stay on v" + state.current }
|
|
248
|
+
],
|
|
249
|
+
initial: 0,
|
|
250
|
+
confirmOnNumber: true
|
|
251
|
+
});
|
|
252
|
+
if (answer !== "yes") {
|
|
253
|
+
line(" " + c.dim("Update cancelled."));
|
|
254
|
+
line();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const installer = await withSpinner(c.dim("Downloading and verifying…"), () => downloadVerified(artifact, updatesDir()));
|
|
259
|
+
const sig = checkInstallerSignature(installer, artifact, isSignedRelease());
|
|
260
|
+
const log = await launchInstaller(installer);
|
|
261
|
+
line();
|
|
262
|
+
line(" " + c.ok("✓") + " " + c.value(`Verified v${state.latest}`) + c.dim(sig.verified ? " (checksum + signature)" : " (checksum)"));
|
|
263
|
+
line(" " + c.dim("Installing now. Carrier OS will close; open a new terminal when it finishes."));
|
|
264
|
+
line(" " + c.dim("Installer log: ") + c.value(log));
|
|
265
|
+
line();
|
|
266
|
+
// The installer is waiting for this PID. Exit now so it can replace cos.exe.
|
|
267
|
+
process.exit(0);
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
270
|
+
line();
|
|
271
|
+
line(" " + c.err("✗") + " " + c.value("Update failed."));
|
|
272
|
+
line(" " + c.dim(err instanceof UpdateError ? err.message : String(err?.message ?? err)));
|
|
273
|
+
line(" " + c.dim("Carrier OS CLI remains at v") + c.value(state.current) + c.dim("."));
|
|
274
|
+
line();
|
|
275
|
+
}
|
|
151
276
|
}
|
|
152
|
-
export function registerUpdate(program,
|
|
277
|
+
export function registerUpdate(program, ctx) {
|
|
153
278
|
program
|
|
154
279
|
.command("update")
|
|
155
280
|
.description("Check for and install the latest Carrier OS CLI version")
|
|
156
|
-
.
|
|
157
|
-
|
|
281
|
+
.option("-y, --yes", "install an available update without asking (for scripts)")
|
|
282
|
+
.action(async (opts) => {
|
|
283
|
+
await runUpdate({ assumeYes: opts.yes === true, config: ctx.config });
|
|
158
284
|
});
|
|
159
285
|
}
|
package/dist/commands/usage.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { heading, line } from "../services/output.js";
|
|
2
2
|
import { withSpinner } from "../services/spinner.js";
|
|
3
3
|
import { c } from "../ui/colors.js";
|
|
4
|
-
import { icon, sectionHeader, termWidth, visibleLen } from "../ui/ui.js";
|
|
4
|
+
import { formatCredits, icon, sectionHeader, termWidth, visibleLen } from "../ui/ui.js";
|
|
5
5
|
/**
|
|
6
6
|
* `cos usage` — requests, tokens and estimated cost for the current project,
|
|
7
7
|
* plus the credit balance that decides whether you can keep going, from
|
|
@@ -20,7 +20,7 @@ export function registerUsage(program, ctx) {
|
|
|
20
20
|
.action(async () => {
|
|
21
21
|
const client = ctx.requireAuth();
|
|
22
22
|
const usage = await withSpinner("Loading usage…", () => client.usage());
|
|
23
|
-
heading(`Usage · project ${usage.project_id}`);
|
|
23
|
+
heading(usage.project_id ? `Usage · project ${usage.project_id}` : "CLI usage");
|
|
24
24
|
renderActivity(usage);
|
|
25
25
|
renderCredits(usage.credits);
|
|
26
26
|
line();
|
|
@@ -121,20 +121,22 @@ export function renderCredits(credits) {
|
|
|
121
121
|
line(" " + icon.warn + c.warn(" Out of credits — buy more or upgrade your plan to continue."));
|
|
122
122
|
}
|
|
123
123
|
// Per-model pools exist only on plans that define them; an empty list is a
|
|
124
|
-
// normal state, not a failure.
|
|
124
|
+
// normal state, not a failure. An unlimited plan is never blocked by a pool, so "25 exhausted" would be false.
|
|
125
125
|
const pools = credits.models ?? [];
|
|
126
|
-
if (pools.length === 0)
|
|
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.
|
|
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
|
|
139
|
+
for (const l of grid(available.map((p) => [label(p), dec(p.remaining)]))) {
|
|
138
140
|
line(l);
|
|
139
141
|
}
|
|
140
142
|
}
|
|
@@ -146,14 +148,14 @@ 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(
|
|
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
|
}
|
|
153
155
|
}
|
|
154
156
|
/* ── Layout helpers ───────────────────────────────────────────────────────── */
|
|
155
157
|
const num = (n) => n.toLocaleString("en-US");
|
|
156
|
-
const dec =
|
|
158
|
+
const dec = formatCredits;
|
|
157
159
|
const tint = (s, color) => (color ? color(s) : s);
|
|
158
160
|
/**
|
|
159
161
|
* A label column plus right-aligned value columns. Every width is measured on
|
package/dist/commands/version.js
CHANGED
|
@@ -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
|
}
|
package/dist/commands/whoami.js
CHANGED
|
@@ -2,25 +2,26 @@ import { ApiError } from "../services/api.js";
|
|
|
2
2
|
import { heading, kv, line, warn } from "../services/output.js";
|
|
3
3
|
import { withSpinner } from "../services/spinner.js";
|
|
4
4
|
/**
|
|
5
|
-
* `cos whoami` — show the
|
|
5
|
+
* `cos whoami` — show the signed-in account. Re-verifies
|
|
6
6
|
* against the API for freshness, falling back to the cached scope if offline.
|
|
7
7
|
*/
|
|
8
8
|
export function registerWhoami(program, ctx) {
|
|
9
9
|
program
|
|
10
10
|
.command("whoami")
|
|
11
|
-
.description("Show
|
|
12
|
-
.
|
|
11
|
+
.description("Show your signed-in account")
|
|
12
|
+
.option("--details", "include advanced API workspace, project and environment details")
|
|
13
|
+
.action(async (options) => {
|
|
13
14
|
const client = ctx.requireAuth();
|
|
14
15
|
try {
|
|
15
16
|
const scope = await withSpinner("Checking…", () => client.verify());
|
|
16
17
|
ctx.config.set("scope", scope);
|
|
17
|
-
render(scope, false);
|
|
18
|
+
render(scope, false, options.details);
|
|
18
19
|
}
|
|
19
20
|
catch (err) {
|
|
20
21
|
const cached = ctx.config.get("scope");
|
|
21
22
|
if (cached) {
|
|
22
23
|
warn(`Could not reach the API (${err instanceof ApiError ? err.code : "error"}); showing cached details.`);
|
|
23
|
-
render(cached, true);
|
|
24
|
+
render(cached, true, options.details);
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
27
|
throw err;
|
|
@@ -28,11 +29,13 @@ export function registerWhoami(program, ctx) {
|
|
|
28
29
|
}
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
function render(scope, cached) {
|
|
32
|
+
function render(scope, cached, details = false) {
|
|
32
33
|
heading(cached ? "Account (cached)" : "Account");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
if (details) {
|
|
35
|
+
kv("API workspace", `${scope.workspace?.name ?? "Not required"} (${scope.workspace?.slug ?? "user session"})`);
|
|
36
|
+
kv("API project", scope.project?.name ?? "Not required");
|
|
37
|
+
kv("Project environment", scope.project?.environment ?? "Not applicable");
|
|
38
|
+
}
|
|
36
39
|
// apiKey is null for a device-flow (browser) session.
|
|
37
40
|
kv("Signed in via", scope.apiKey ? `API key · ${scope.apiKey.name}` : "Browser session");
|
|
38
41
|
if (scope.user)
|