@carrieros/cli 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -64
- package/dist/commands/attach.js +45 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +81 -15
- package/dist/commands/context.js +200 -0
- package/dist/commands/doctor.js +63 -3
- package/dist/commands/files.js +84 -23
- package/dist/commands/help.js +1 -0
- package/dist/commands/history.js +88 -23
- package/dist/commands/login.js +31 -7
- package/dist/commands/logout.js +1 -0
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +39 -3
- package/dist/commands/modes.js +4 -1
- package/dist/commands/permissions.js +77 -0
- package/dist/commands/project.js +106 -0
- package/dist/commands/repo.js +146 -0
- package/dist/commands/repos.js +61 -0
- package/dist/commands/review.js +92 -0
- package/dist/commands/scope.js +9 -6
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +224 -65
- package/dist/commands/settings.js +94 -0
- package/dist/commands/update.js +229 -0
- package/dist/commands/upload.js +204 -31
- package/dist/commands/usage.js +213 -17
- package/dist/commands/whoami.js +12 -9
- package/dist/ide/editor-context.js +275 -0
- package/dist/ide/ide-session.js +355 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +26 -1
- package/dist/services/api.js +315 -15
- package/dist/services/auth-origin.js +20 -0
- package/dist/services/chat-stream.js +168 -0
- package/dist/services/checkpoints.js +278 -0
- package/dist/services/client-tools.js +352 -0
- 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 +273 -0
- package/dist/services/command-policy.js +434 -0
- package/dist/services/config.js +311 -24
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +296 -23
- package/dist/services/device-auth.js +72 -35
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -0
- package/dist/services/execution-platform.js +30 -0
- package/dist/services/file-detect.js +104 -0
- package/dist/services/file-resolver.js +199 -0
- package/dist/services/file-upload.js +126 -0
- package/dist/services/folder-key.js +22 -0
- package/dist/services/git-tools.js +429 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +85 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/instruction-resolver.js +54 -0
- package/dist/services/job-helper.js +328 -0
- package/dist/services/local-files.js +639 -0
- package/dist/services/local-tools.js +937 -0
- package/dist/services/login-flow.js +55 -17
- package/dist/services/meta.js +3 -1
- package/dist/services/mutation-coordinator.js +327 -0
- package/dist/services/mutation-groups.js +309 -0
- package/dist/services/mutation-recovery.js +159 -0
- package/dist/services/mutations.js +679 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +5 -2
- package/dist/services/packaged-update.js +403 -0
- package/dist/services/packaged.js +39 -0
- package/dist/services/permission-mode.js +60 -0
- package/dist/services/process-runner.js +412 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/result-reconciliation.js +49 -0
- package/dist/services/secure-store.js +217 -0
- package/dist/services/session-resolver.js +113 -0
- package/dist/services/sia.js +51 -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 +311 -0
- package/dist/services/workspace-registry.js +310 -0
- package/dist/services/workspace.js +580 -0
- package/dist/shell/shell-chat.js +1297 -59
- package/dist/shell/shell-commands.js +243 -12
- package/dist/shell/shell-prompt.js +94 -11
- package/dist/shell/shell-renderer.js +8 -20
- package/dist/shell/shell-router.js +19 -3
- package/dist/shell/shell.js +252 -22
- package/dist/shell/task-context-view.js +40 -0
- package/dist/types/index.js +3 -1
- package/dist/ui/agent-cards.js +111 -0
- package/dist/ui/agent-presentation.js +131 -0
- package/dist/ui/approval.js +111 -0
- package/dist/ui/banner.js +31 -48
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +334 -0
- package/dist/ui/chat-renderer.js +207 -14
- package/dist/ui/colors.js +12 -8
- package/dist/ui/command-details.js +11 -0
- package/dist/ui/command-filter.js +26 -5
- package/dist/ui/command-palette.js +44 -14
- package/dist/ui/command-registry.js +92 -10
- package/dist/ui/command-review.js +187 -0
- package/dist/ui/composer-layout.js +48 -1
- package/dist/ui/conversation.js +450 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +4 -2
- package/dist/ui/markdown.js +63 -9
- package/dist/ui/message.js +14 -31
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +19 -11
- package/dist/ui/select.js +191 -29
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/task-context-card.js +99 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/trust.js +88 -0
- package/dist/ui/ui.js +27 -1
- package/package.json +18 -4
- package/dist/ui/activity.js +0 -77
|
@@ -1,16 +1,24 @@
|
|
|
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";
|
|
4
|
+
import { clearActiveSession, listSessions, resolveSession, SessionRefError, setActiveSession } from "../services/session-resolver.js";
|
|
3
5
|
import { withSpinner } from "../services/spinner.js";
|
|
6
|
+
import { showHistory } from "./history.js";
|
|
4
7
|
import { c } from "../ui/colors.js";
|
|
5
8
|
import { pickFromList } from "../ui/select.js";
|
|
6
9
|
import { emptyState, icon, sectionHeader } from "../ui/ui.js";
|
|
7
10
|
/**
|
|
8
|
-
* Session management
|
|
9
|
-
*
|
|
10
|
-
* cos sessions
|
|
11
|
-
* cos session
|
|
12
|
-
* cos session
|
|
13
|
-
* cos
|
|
11
|
+
* Session management over GET /v1/conversations, GET|DELETE /v1/sessions/:id and
|
|
12
|
+
* POST /v1/sessions:
|
|
13
|
+
* cos sessions numbered list
|
|
14
|
+
* cos session <n|id> continue that conversation
|
|
15
|
+
* cos session use [n|id] same, kept for backward compatibility
|
|
16
|
+
* cos session delete <n|id> delete (asks first)
|
|
17
|
+
* cos new [title] start a fresh conversation
|
|
18
|
+
* cos clear forget the active session locally
|
|
19
|
+
*
|
|
20
|
+
* Numbers come from the last `cos sessions` listing and are resolved in exactly
|
|
21
|
+
* one place (services/session-resolver.ts); ids keep working everywhere.
|
|
14
22
|
*/
|
|
15
23
|
export function registerSessions(program, ctx) {
|
|
16
24
|
program
|
|
@@ -19,105 +27,256 @@ export function registerSessions(program, ctx) {
|
|
|
19
27
|
.option("-n, --limit <n>", "how many to show", "20")
|
|
20
28
|
.action(async (opts) => {
|
|
21
29
|
const client = ctx.requireAuth();
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
const { conversations, total } = await listSessions(ctx, client, {
|
|
31
|
+
limit: clampLimit(opts.limit)
|
|
32
|
+
});
|
|
33
|
+
renderSessionList(conversations, ctx.config.get("sessionId"), total);
|
|
25
34
|
});
|
|
26
35
|
const session = program.command("session").description("Inspect or switch the active session");
|
|
36
|
+
// `cos session 2` / `cos session <id>` — the shortest path, no sub-verb.
|
|
37
|
+
session
|
|
38
|
+
.argument("[ref]", "session number from `cos sessions`, or a session id")
|
|
39
|
+
.action(async (ref) => {
|
|
40
|
+
const client = ctx.requireAuth();
|
|
41
|
+
if (!ref) {
|
|
42
|
+
await pickSession(ctx, client);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
await switchTo(ctx, client, ref);
|
|
46
|
+
});
|
|
47
|
+
// Kept verbatim for backward compatibility with `cos session use <id>`.
|
|
27
48
|
session
|
|
28
49
|
.command("use")
|
|
29
50
|
.description("Switch the active session")
|
|
30
|
-
.argument("[
|
|
31
|
-
.action(async (
|
|
51
|
+
.argument("[ref]", "session number or id (prompts from the list if omitted)")
|
|
52
|
+
.action(async (ref) => {
|
|
32
53
|
const client = ctx.requireAuth();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (conversations.length === 0) {
|
|
37
|
-
for (const l of emptyState("No conversations yet.", "Start chatting to create one.")) {
|
|
38
|
-
line(l);
|
|
39
|
-
}
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const activeId = ctx.config.get("sessionId");
|
|
43
|
-
const chosen = await pickFromList({
|
|
44
|
-
title: "Select a session",
|
|
45
|
-
description: "Switch the active conversation.",
|
|
46
|
-
initial: Math.max(0, conversations.findIndex((cv) => cv.session_id === activeId)),
|
|
47
|
-
choices: conversations.map((cv) => ({
|
|
48
|
-
value: cv.session_id,
|
|
49
|
-
label: cv.title,
|
|
50
|
-
description: `${cv.message_count} msgs · ${timeAgo(cv.last_activity)}`,
|
|
51
|
-
current: cv.session_id === activeId
|
|
52
|
-
}))
|
|
53
|
-
});
|
|
54
|
-
if (chosen == null)
|
|
55
|
-
return; // Esc / Ctrl+C — leave the session unchanged
|
|
56
|
-
target = chosen;
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const info_ = await withSpinner("Opening…", () => client.session(target));
|
|
60
|
-
ctx.config.set("sessionId", info_.session_id);
|
|
61
|
-
success(`Switched to “${info_.title}”.`);
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
|
|
65
|
-
process.exitCode = 1;
|
|
54
|
+
if (!ref) {
|
|
55
|
+
await pickSession(ctx, client);
|
|
56
|
+
return;
|
|
66
57
|
}
|
|
58
|
+
await switchTo(ctx, client, ref);
|
|
67
59
|
});
|
|
68
60
|
session
|
|
69
61
|
.command("current")
|
|
70
|
-
.description("Show the active session
|
|
62
|
+
.description("Show the active session")
|
|
71
63
|
.action(() => {
|
|
72
64
|
const sid = ctx.config.get("sessionId");
|
|
73
|
-
|
|
65
|
+
if (!sid) {
|
|
66
|
+
info("No active session (a new one starts on your next message).");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const title = ctx.config.get("sessionTitle");
|
|
70
|
+
info(title ? `Current session: ${title} (${sid})` : `Current session: ${sid}`);
|
|
74
71
|
});
|
|
75
72
|
session
|
|
76
73
|
.command("delete")
|
|
77
74
|
.description("Delete a session")
|
|
78
|
-
.argument("<
|
|
79
|
-
.action(async (
|
|
75
|
+
.argument("<ref>", "session number from `cos sessions`, or a session id")
|
|
76
|
+
.action(async (ref) => {
|
|
80
77
|
const client = ctx.requireAuth();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
await deleteSession(ctx, client, ref);
|
|
79
|
+
});
|
|
80
|
+
// Rename has no /v1 endpoint yet. Registered so the command reports the real
|
|
81
|
+
// reason rather than "unknown command", but deliberately NOT advertised in the
|
|
82
|
+
// palette — and it never invents a CLI-only title.
|
|
83
|
+
session
|
|
84
|
+
.command("rename")
|
|
85
|
+
.description("Rename a session (not yet supported by the API)")
|
|
86
|
+
.argument("[ref]", "session number or id")
|
|
87
|
+
.argument("[title...]", "new title")
|
|
88
|
+
.action(() => {
|
|
89
|
+
errorLine("Renaming isn't supported by the API yet.");
|
|
90
|
+
line(" " + c.dim("The /v1 surface has no update endpoint for a session."));
|
|
91
|
+
process.exitCode = 1;
|
|
92
|
+
});
|
|
93
|
+
program
|
|
94
|
+
.command("new")
|
|
95
|
+
.description("Start a new conversation")
|
|
96
|
+
.argument("[title...]", "optional title (Standard chat only)")
|
|
97
|
+
.action(async (titleParts) => {
|
|
98
|
+
const title = (titleParts ?? []).join(" ").trim();
|
|
99
|
+
await newSession(ctx, title);
|
|
91
100
|
});
|
|
92
101
|
program
|
|
93
102
|
.command("clear")
|
|
94
103
|
.description("Start a new session (forgets the active one locally)")
|
|
95
104
|
.action(() => {
|
|
96
|
-
ctx
|
|
105
|
+
clearActiveSession(ctx);
|
|
97
106
|
success("Cleared. Your next message starts a fresh session.");
|
|
98
107
|
});
|
|
99
108
|
}
|
|
109
|
+
// ── Shared operations (the shell routes straight to these) ───────────────────
|
|
110
|
+
/** Switch the active conversation by ordinal or id. */
|
|
111
|
+
export async function switchTo(ctx, client, ref) {
|
|
112
|
+
try {
|
|
113
|
+
const s = await withSpinner("Opening…", () => resolveSession(ctx, client, ref));
|
|
114
|
+
setActiveSession(ctx, s.session_id, s.title);
|
|
115
|
+
success(`Switched to “${s.title}”.`);
|
|
116
|
+
// Replay the conversation you just opened. Switching without it left you
|
|
117
|
+
// typing into a thread whose contents you could not see — the model has the
|
|
118
|
+
// full context, so the person should too. Reuses /history's renderer, so
|
|
119
|
+
// memory markers and clarification blocks render identically.
|
|
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
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
reportRefError(err);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Arrow-key picker over the current conversations. */
|
|
131
|
+
export async function pickSession(ctx, client) {
|
|
132
|
+
const { conversations } = await listSessions(ctx, client, { limit: 25 });
|
|
133
|
+
if (conversations.length === 0) {
|
|
134
|
+
for (const l of emptyState("No conversations yet.", "Start chatting to create one."))
|
|
135
|
+
line(l);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const activeId = ctx.config.get("sessionId");
|
|
139
|
+
// Numbers are padded and titles column-aligned so the picker reads like the
|
|
140
|
+
// printed list — the number shown here is the same one `/session <n>` takes,
|
|
141
|
+
// so switching between the two ways of choosing never means re-counting.
|
|
142
|
+
const nw = String(conversations.length).length;
|
|
143
|
+
const tw = Math.min(38, Math.max(...conversations.map((cv) => [...cv.title].length)));
|
|
144
|
+
const chosen = await pickFromList({
|
|
145
|
+
title: "Sessions",
|
|
146
|
+
description: "↑↓ to choose · Enter to continue that conversation · Esc to cancel",
|
|
147
|
+
initial: Math.max(0, conversations.findIndex((cv) => cv.session_id === activeId)),
|
|
148
|
+
choices: conversations.map((cv, i) => ({
|
|
149
|
+
value: cv.session_id,
|
|
150
|
+
label: `${String(i + 1).padStart(nw)} ${clipTitle(cv.title, tw)}`,
|
|
151
|
+
description: `${cv.message_count} msgs · ${timeAgo(cv.last_activity)}`,
|
|
152
|
+
current: cv.session_id === activeId
|
|
153
|
+
}))
|
|
154
|
+
});
|
|
155
|
+
if (chosen == null)
|
|
156
|
+
return; // Esc / Ctrl+C — leave the session unchanged
|
|
157
|
+
await switchTo(ctx, client, chosen);
|
|
158
|
+
}
|
|
159
|
+
/** Delete a conversation after an explicit confirmation. */
|
|
160
|
+
export async function deleteSession(ctx, client, ref) {
|
|
161
|
+
let target;
|
|
162
|
+
try {
|
|
163
|
+
target = await withSpinner("Loading…", () => resolveSession(ctx, client, ref));
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
reportRefError(err);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// Deletion is irreversible and there is no undo in a terminal, so name what
|
|
170
|
+
// will be lost. `initial: 0` = "Keep" so a non-TTY (piped/CI) run declines
|
|
171
|
+
// rather than silently deleting.
|
|
172
|
+
const answer = await pickFromList({
|
|
173
|
+
title: "Delete this conversation?",
|
|
174
|
+
description: `“${target.title}” — this cannot be undone.`,
|
|
175
|
+
initial: 0,
|
|
176
|
+
confirmOnNumber: true,
|
|
177
|
+
choices: [
|
|
178
|
+
{ value: "no", label: "Keep it" },
|
|
179
|
+
{ value: "yes", label: "Delete" }
|
|
180
|
+
]
|
|
181
|
+
});
|
|
182
|
+
if (answer !== "yes") {
|
|
183
|
+
info("Left it alone.");
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
await withSpinner("Deleting…", () => client.deleteSession(target.session_id));
|
|
188
|
+
if (ctx.config.get("sessionId") === target.session_id)
|
|
189
|
+
clearActiveSession(ctx);
|
|
190
|
+
success(`Deleted “${target.title}”.`);
|
|
191
|
+
// The ordinals just shifted — refresh so the next number means what the user
|
|
192
|
+
// last saw, rather than pointing one place further down the list.
|
|
193
|
+
await listSessions(ctx, client, { spinner: false }).catch(() => undefined);
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
|
|
197
|
+
process.exitCode = 1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Start a fresh conversation.
|
|
202
|
+
*
|
|
203
|
+
* Without a title this just drops the local pointer — the next message creates
|
|
204
|
+
* the conversation with the CORRECT chat type (Carrier or Standard) through the
|
|
205
|
+
* normal chat flow. With a title we must call POST /v1/sessions, which hardcodes
|
|
206
|
+
* `type: "regular"`, so a titled new chat is Standard-only; in Carrier chat we
|
|
207
|
+
* say so instead of silently downgrading the conversation type.
|
|
208
|
+
*/
|
|
209
|
+
export async function newSession(ctx, title) {
|
|
210
|
+
if (!title) {
|
|
211
|
+
clearActiveSession(ctx);
|
|
212
|
+
success("New conversation. Your next message starts it.");
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (ctx.chatType === "carrier") {
|
|
216
|
+
errorLine("Titles are Standard chat only — the API creates titled sessions as Standard.");
|
|
217
|
+
line(" " + c.dim("Run /new without a title to start a Carrier chat, or /switch standard."));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const client = ctx.requireAuth();
|
|
221
|
+
try {
|
|
222
|
+
const s = await withSpinner("Creating…", () => client.createSession(title));
|
|
223
|
+
setActiveSession(ctx, s.session_id, s.title);
|
|
224
|
+
success(`Started “${s.title}”.`);
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
|
|
228
|
+
process.exitCode = 1;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/** Consistent, actionable output for a bad/stale reference. */
|
|
232
|
+
export function reportRefError(err) {
|
|
233
|
+
if (err instanceof SessionRefError) {
|
|
234
|
+
errorLine(err.message);
|
|
235
|
+
if (err.hint)
|
|
236
|
+
line(" " + c.dim(err.hint));
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
|
|
240
|
+
process.exitCode = 1;
|
|
241
|
+
}
|
|
242
|
+
/** Pad to `width`, or clip with an ellipsis when the title is longer. */
|
|
243
|
+
function clipTitle(title, width) {
|
|
244
|
+
const chars = [...title];
|
|
245
|
+
if (chars.length <= width)
|
|
246
|
+
return title.padEnd(width);
|
|
247
|
+
return chars.slice(0, width - 1).join("") + "…";
|
|
248
|
+
}
|
|
100
249
|
function clampLimit(raw) {
|
|
101
250
|
const n = parseInt(raw, 10);
|
|
102
251
|
if (Number.isNaN(n))
|
|
103
252
|
return 20;
|
|
104
253
|
return Math.min(Math.max(n, 1), 100);
|
|
105
254
|
}
|
|
106
|
-
|
|
255
|
+
/**
|
|
256
|
+
* The numbered listing. The number is the handle for every other command, so it
|
|
257
|
+
* leads the row; the id is dropped entirely — it was only ever there to be
|
|
258
|
+
* copied, which is what the numbers now replace.
|
|
259
|
+
*/
|
|
260
|
+
export function renderSessionList(items, activeId, total) {
|
|
107
261
|
if (items.length === 0) {
|
|
108
|
-
for (const l of emptyState("No conversations yet.", "
|
|
262
|
+
for (const l of emptyState("No conversations yet.", "Type a message to start one, or run /new.")) {
|
|
109
263
|
line(l);
|
|
264
|
+
}
|
|
110
265
|
return;
|
|
111
266
|
}
|
|
112
267
|
line();
|
|
113
268
|
line(sectionHeader(`Sessions (${items.length} of ${total})`));
|
|
114
269
|
const w = Math.max(0, ...items.map((s) => [...s.title].length));
|
|
115
|
-
|
|
270
|
+
const nw = String(items.length).length;
|
|
271
|
+
items.forEach((s, i) => {
|
|
116
272
|
const active = s.session_id === activeId;
|
|
273
|
+
const num = c.dim(String(i + 1).padStart(nw));
|
|
117
274
|
const marker = active ? icon.active : " ";
|
|
118
275
|
const title = (active ? c.brand : c.value)(s.title.padEnd(w));
|
|
119
|
-
const meta = c.dim(`${s.message_count} msgs · ${timeAgo(s.last_activity)}
|
|
120
|
-
line(` ${marker} ${title} ${meta}`);
|
|
121
|
-
}
|
|
276
|
+
const meta = c.dim(`${s.message_count} msgs · ${timeAgo(s.last_activity)}`);
|
|
277
|
+
line(` ${num} ${marker} ${title} ${meta}`);
|
|
278
|
+
});
|
|
279
|
+
line();
|
|
280
|
+
line(" " + c.dim("Continue one with ") + c.cmd("/session <n>"));
|
|
122
281
|
line();
|
|
123
282
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { COMMANDS_OPT_IN_ENV, localCommandsState } from "../services/client-tools.js";
|
|
2
|
+
import { errorLine, line } from "../services/output.js";
|
|
3
|
+
import { c } from "../ui/colors.js";
|
|
4
|
+
import { sectionHeader } from "../ui/ui.js";
|
|
5
|
+
import { executionAdapter, executionPlatform } from "../services/execution-platform.js";
|
|
6
|
+
/**
|
|
7
|
+
* `cos settings` — the CLI's persisted behaviour settings, in one place.
|
|
8
|
+
*
|
|
9
|
+
* /settings show them
|
|
10
|
+
* /settings commands on|off allow or stop local commands (run_command)
|
|
11
|
+
*
|
|
12
|
+
* Most settings already have their own toggle (/fast, /hipwr, /sia, /websearch)
|
|
13
|
+
* 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.
|
|
15
|
+
*/
|
|
16
|
+
export function registerSettings(program, ctx) {
|
|
17
|
+
program
|
|
18
|
+
.command("settings")
|
|
19
|
+
.argument("[setting]", 'the setting to change, e.g. "commands"')
|
|
20
|
+
.argument("[value]", "on or off")
|
|
21
|
+
.description("Show or change CLI settings (e.g. settings commands on)")
|
|
22
|
+
.action((setting, value) => {
|
|
23
|
+
runSettings(ctx, [setting, value].filter(Boolean).join(" "));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const ON = new Set(["on", "yes", "true", "enable", "enabled"]);
|
|
27
|
+
const OFF = new Set(["off", "no", "false", "disable", "disabled"]);
|
|
28
|
+
export function runSettings(ctx, argStr) {
|
|
29
|
+
const [name = "", value = ""] = argStr.trim().toLowerCase().split(/\s+/);
|
|
30
|
+
if (!name)
|
|
31
|
+
return showSettings(ctx);
|
|
32
|
+
if (name !== "commands" && name !== "local-commands") {
|
|
33
|
+
errorLine(`Unknown setting "${name}". Try: /settings commands on|off`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!ON.has(value) && !OFF.has(value)) {
|
|
37
|
+
errorLine("Use /settings commands on or /settings commands off.");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const enable = ON.has(value);
|
|
41
|
+
ctx.config.set("localCommandsEnabled", enable);
|
|
42
|
+
line();
|
|
43
|
+
if (enable) {
|
|
44
|
+
line(" " + c.ok("✓") + " " + c.value("Local commands enabled."));
|
|
45
|
+
// Said plainly at the moment it is switched on: what a command can do.
|
|
46
|
+
const notice = executionAdapter(executionPlatform()) === "windows-job" ? LOCAL_COMMANDS_NOTICE : [
|
|
47
|
+
...LOCAL_COMMANDS_NOTICE.slice(0, 3),
|
|
48
|
+
"Approved project code runs in a configured isolated Linux container.",
|
|
49
|
+
"Only the selected repository is mounted; network access is disabled.",
|
|
50
|
+
LOCAL_COMMANDS_NOTICE[5]
|
|
51
|
+
];
|
|
52
|
+
for (const l of notice)
|
|
53
|
+
line(" " + c.dim(l));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
line(" " + c.ok("✓") + " " + c.value("Local commands disabled.") + " " + c.dim("The model can still read, search and propose file changes."));
|
|
57
|
+
}
|
|
58
|
+
line();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* What enabling local commands means, in the user's terms. Shown when it is
|
|
62
|
+
* switched on — not buried in documentation — because it is the one decision
|
|
63
|
+
* here that lets project code run.
|
|
64
|
+
*/
|
|
65
|
+
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).",
|
|
69
|
+
"Approved project code runs as your Windows account: it can read what you can",
|
|
70
|
+
"read, and may open other applications through Windows file associations.",
|
|
71
|
+
"Turn it off again with /settings commands off."
|
|
72
|
+
];
|
|
73
|
+
function showSettings(ctx) {
|
|
74
|
+
const state = localCommandsState(ctx);
|
|
75
|
+
const row = (label, value, note = "") => line(" " + c.label(label.padEnd(16)) + value + (note ? " " + c.dim(note) : ""));
|
|
76
|
+
line();
|
|
77
|
+
line(sectionHeader("Settings"));
|
|
78
|
+
line();
|
|
79
|
+
row("Local commands", state.enabled ? c.ok("enabled") : c.dim("disabled"), state.source === "env"
|
|
80
|
+
? `via ${COMMANDS_OPT_IN_ENV}=1`
|
|
81
|
+
: state.enabled
|
|
82
|
+
? "/settings commands off to stop"
|
|
83
|
+
: "/settings commands on to allow");
|
|
84
|
+
if (state.enabled && state.blockedBy)
|
|
85
|
+
row("", c.warn("not active"), state.blockedBy);
|
|
86
|
+
row("Mode", c.value(ctx.mode));
|
|
87
|
+
row("Model", c.value(ctx.config.get("model") || "mode default"));
|
|
88
|
+
row("Fast", ctx.fast ? c.ok("on") : c.dim("off"), "/fast");
|
|
89
|
+
row("High Power", ctx.highPower ? c.ok("on") : c.dim("off"), "/hipwr");
|
|
90
|
+
row("Clarification", c.value(ctx.siaMode), "/sia");
|
|
91
|
+
const web = ctx.webSearch;
|
|
92
|
+
row("Web search", web === undefined ? c.dim("workspace default") : web ? c.ok("on") : c.dim("off"), "/websearch");
|
|
93
|
+
line();
|
|
94
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { line } from "../services/output.js";
|
|
2
|
+
import { withSpinner } from "../services/spinner.js";
|
|
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 { checkForUpdate, installLatest, isLinkedInstallation, PACKAGE_NAME, verifyInstallation } from "../services/update.js";
|
|
6
|
+
import { c } from "../ui/colors.js";
|
|
7
|
+
import { pickFromList } from "../ui/select.js";
|
|
8
|
+
/**
|
|
9
|
+
* `/update` and `cos update` — check for, and install, a newer CLI.
|
|
10
|
+
*
|
|
11
|
+
* Bare `/update` NEVER mutates the installation; `/update install` is the only
|
|
12
|
+
* path that changes anything, and only after an explicit confirmation. The
|
|
13
|
+
* process is never restarted: npm swaps files under a running Node, and
|
|
14
|
+
* re-execing through the shim while the old process still holds handles is how
|
|
15
|
+
* partial installs happen. The user is told to restart instead.
|
|
16
|
+
*
|
|
17
|
+
* This file owns every message. services/update.ts owns the logic, so the shell
|
|
18
|
+
* command and the standalone command cannot drift apart.
|
|
19
|
+
*/
|
|
20
|
+
const MANUAL = "npm install -g " + PACKAGE_NAME + "@latest";
|
|
21
|
+
function heading() {
|
|
22
|
+
line();
|
|
23
|
+
line(" " + c.title("Carrier OS CLI"));
|
|
24
|
+
line();
|
|
25
|
+
}
|
|
26
|
+
function versions(current, latest) {
|
|
27
|
+
line(" " + c.dim("Current version: ") + c.value(current));
|
|
28
|
+
line(" " + c.dim("Latest version: ") + c.value(latest));
|
|
29
|
+
line();
|
|
30
|
+
}
|
|
31
|
+
function renderTerminalState(state) {
|
|
32
|
+
if (state.kind === "current") {
|
|
33
|
+
line();
|
|
34
|
+
line(" " + c.ok("✓") + " " + c.value("Carrier OS CLI is already up to date (v" + state.current + ")"));
|
|
35
|
+
line();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (state.kind === "ahead") {
|
|
39
|
+
heading();
|
|
40
|
+
versions(state.current, state.latest);
|
|
41
|
+
line(" " + c.ok("✓") + " " + c.value("You are running a newer version than npm's latest."));
|
|
42
|
+
line(" " + c.dim("Nothing to do — this will not downgrade."));
|
|
43
|
+
line();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (state.kind === "no-npm") {
|
|
47
|
+
heading();
|
|
48
|
+
line(" " + c.err("✗") + " " + c.value("Unable to check for updates."));
|
|
49
|
+
line();
|
|
50
|
+
line(" " + c.dim("npm was not found on this system."));
|
|
51
|
+
line(" " + c.dim("Update manually with:"));
|
|
52
|
+
line(" " + c.cmd(MANUAL));
|
|
53
|
+
line();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// unreachable
|
|
57
|
+
heading();
|
|
58
|
+
line(" " + c.err("✗") + " " + c.value("Could not check for the latest version."));
|
|
59
|
+
line();
|
|
60
|
+
line(" " + c.dim("Your current version: ") + c.value(state.current));
|
|
61
|
+
line(" " + c.dim(state.detail));
|
|
62
|
+
line();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* `/update` and `cos update` — the entire user-facing surface.
|
|
66
|
+
*
|
|
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.
|
|
75
|
+
*/
|
|
76
|
+
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.
|
|
79
|
+
if (isPackaged()) {
|
|
80
|
+
await runPackagedUpdate(opts.assumeYes === true);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
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);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
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."));
|
|
96
|
+
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."));
|
|
99
|
+
line();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
heading();
|
|
103
|
+
versions(state.current, state.latest);
|
|
104
|
+
line(" " + c.value("A new version is available."));
|
|
105
|
+
line();
|
|
106
|
+
const answer = opts.assumeYes ? "yes" : await pickFromList({
|
|
107
|
+
title: "Update now?",
|
|
108
|
+
description: "Runs " + MANUAL,
|
|
109
|
+
choices: [
|
|
110
|
+
{ value: "yes", label: "Yes", description: "Install v" + state.latest + " now" },
|
|
111
|
+
{ value: "no", label: "No", description: "Stay on v" + state.current }
|
|
112
|
+
],
|
|
113
|
+
initial: 0,
|
|
114
|
+
confirmOnNumber: true
|
|
115
|
+
});
|
|
116
|
+
// Esc resolves null — a dismissed prompt must never install anything.
|
|
117
|
+
if (answer !== "yes") {
|
|
118
|
+
line(" " + c.dim("Update cancelled."));
|
|
119
|
+
line();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const result = await withSpinner(c.dim("Updating Carrier OS CLI…"), async () => installLatest());
|
|
123
|
+
if (!result.ok) {
|
|
124
|
+
line();
|
|
125
|
+
line(" " + c.err("✗") + " " + c.value("Update failed."));
|
|
126
|
+
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
|
+
}
|
|
132
|
+
if (result.detail) {
|
|
133
|
+
line();
|
|
134
|
+
for (const l of result.detail.split("\n").slice(0, 6))
|
|
135
|
+
line(" " + c.dim(l));
|
|
136
|
+
}
|
|
137
|
+
line();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
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));
|
|
146
|
+
line();
|
|
147
|
+
line(" " + c.dim("Restart Carrier OS CLI to use the new version."));
|
|
148
|
+
line();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The packaged (installer) update: check the release manifest, then — only
|
|
152
|
+
* after an explicit Yes — download, verify the checksum (and the signature on
|
|
153
|
+
* a signed build), hand the installer this PID and exit. The installer waits
|
|
154
|
+
* for this process to end before replacing cos.exe, so nothing is swapped
|
|
155
|
+
* underneath a running CLI. Every failure leaves the current version intact.
|
|
156
|
+
*/
|
|
157
|
+
async function runPackagedUpdate(assumeYes) {
|
|
158
|
+
const state = await withSpinner(c.dim("Checking for updates…"), () => checkPackagedUpdate());
|
|
159
|
+
if (state.kind === "current") {
|
|
160
|
+
renderTerminalState({ kind: "current", current: state.current, latest: state.latest });
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (state.kind === "ahead") {
|
|
164
|
+
heading();
|
|
165
|
+
versions(state.current, state.latest);
|
|
166
|
+
line(" " + c.ok("✓") + " " + c.value("You are running a newer version than the latest release."));
|
|
167
|
+
line(" " + c.dim("Nothing to do — this will not downgrade."));
|
|
168
|
+
line();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (state.kind === "unreachable") {
|
|
172
|
+
heading();
|
|
173
|
+
line(" " + c.err("✗") + " " + c.value("Could not check for the latest version."));
|
|
174
|
+
line();
|
|
175
|
+
line(" " + c.dim("Your current version: ") + c.value(state.current));
|
|
176
|
+
line(" " + c.dim(state.detail));
|
|
177
|
+
line(" " + c.dim("You can also download the installer from ") + c.value(PACKAGED_DOWNLOAD_URL) + c.dim("."));
|
|
178
|
+
line();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const artifact = state.manifest.artifacts["win-x64-setup"];
|
|
182
|
+
heading();
|
|
183
|
+
versions(state.current, state.latest);
|
|
184
|
+
line(" " + c.value("A new version is available."));
|
|
185
|
+
line();
|
|
186
|
+
const answer = assumeYes ? "yes" : await pickFromList({
|
|
187
|
+
title: "Update now?",
|
|
188
|
+
description: `Downloads ${artifact.file} (${(artifact.size / 1024 / 1024).toFixed(1)} MB), verifies it, then installs it`,
|
|
189
|
+
choices: [
|
|
190
|
+
{ value: "yes", label: "Yes", description: "Install v" + state.latest + " — Carrier OS closes while it updates" },
|
|
191
|
+
{ value: "no", label: "No", description: "Stay on v" + state.current }
|
|
192
|
+
],
|
|
193
|
+
initial: 0,
|
|
194
|
+
confirmOnNumber: true
|
|
195
|
+
});
|
|
196
|
+
if (answer !== "yes") {
|
|
197
|
+
line(" " + c.dim("Update cancelled."));
|
|
198
|
+
line();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const installer = await withSpinner(c.dim("Downloading and verifying…"), () => downloadVerified(artifact, updatesDir()));
|
|
203
|
+
const sig = checkInstallerSignature(installer, artifact, isSignedRelease());
|
|
204
|
+
const log = await launchInstaller(installer);
|
|
205
|
+
line();
|
|
206
|
+
line(" " + c.ok("✓") + " " + c.value(`Verified v${state.latest}`) + c.dim(sig.verified ? " (checksum + signature)" : " (checksum)"));
|
|
207
|
+
line(" " + c.dim("Installing now. Carrier OS will close; open a new terminal when it finishes."));
|
|
208
|
+
line(" " + c.dim("Installer log: ") + c.value(log));
|
|
209
|
+
line();
|
|
210
|
+
// The installer is waiting for this PID. Exit now so it can replace cos.exe.
|
|
211
|
+
process.exit(0);
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
line();
|
|
215
|
+
line(" " + c.err("✗") + " " + c.value("Update failed."));
|
|
216
|
+
line(" " + c.dim(err instanceof UpdateError ? err.message : String(err?.message ?? err)));
|
|
217
|
+
line(" " + c.dim("Carrier OS CLI remains at v") + c.value(state.current) + c.dim("."));
|
|
218
|
+
line();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
export function registerUpdate(program, _ctx) {
|
|
222
|
+
program
|
|
223
|
+
.command("update")
|
|
224
|
+
.description("Check for and install the latest Carrier OS CLI version")
|
|
225
|
+
.option("-y, --yes", "install an available update without asking (for scripts)")
|
|
226
|
+
.action(async (opts) => {
|
|
227
|
+
await runUpdate({ assumeYes: opts.yes === true });
|
|
228
|
+
});
|
|
229
|
+
}
|