@carrieros/cli-staging 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +6 -2
  2. package/dist/commands/attach.js +45 -0
  3. package/dist/commands/auth.js +60 -0
  4. package/dist/commands/btw.js +78 -0
  5. package/dist/commands/changes.js +167 -0
  6. package/dist/commands/chat.js +182 -0
  7. package/dist/commands/context.js +200 -0
  8. package/dist/commands/doctor.js +119 -0
  9. package/dist/commands/files.js +94 -0
  10. package/dist/commands/help.js +37 -0
  11. package/dist/commands/history.js +112 -0
  12. package/dist/commands/login.js +62 -0
  13. package/dist/commands/logout.js +26 -0
  14. package/dist/commands/memory.js +162 -0
  15. package/dist/commands/mode-model.js +64 -0
  16. package/dist/commands/models.js +28 -0
  17. package/dist/commands/modes.js +30 -0
  18. package/dist/commands/permissions.js +78 -0
  19. package/dist/commands/project.js +106 -0
  20. package/dist/commands/repo.js +146 -0
  21. package/dist/commands/repos.js +61 -0
  22. package/dist/commands/review.js +92 -0
  23. package/dist/commands/scope.js +155 -0
  24. package/dist/commands/search.js +92 -0
  25. package/dist/commands/sessions.js +282 -0
  26. package/dist/commands/settings.js +160 -0
  27. package/dist/commands/update.js +285 -0
  28. package/dist/commands/upload.js +223 -0
  29. package/dist/commands/usage.js +229 -0
  30. package/dist/commands/version.js +26 -0
  31. package/dist/commands/whoami.js +44 -0
  32. package/dist/ide/editor-context.js +275 -0
  33. package/dist/ide/ide-session.js +364 -0
  34. package/dist/ide/tool-host.js +109 -0
  35. package/dist/main.js +132 -0
  36. package/dist/services/api.js +441 -0
  37. package/dist/services/auth-origin.js +20 -0
  38. package/dist/services/auto-update.js +221 -0
  39. package/dist/services/chat-stream.js +168 -0
  40. package/dist/services/checkpoints.js +278 -0
  41. package/dist/services/client-tools.js +356 -0
  42. package/dist/services/code-intel.js +243 -0
  43. package/dist/services/code-symbols.js +94 -0
  44. package/dist/services/coding-workflow.js +554 -0
  45. package/dist/services/command-coordinator.js +273 -0
  46. package/dist/services/command-policy.js +434 -0
  47. package/dist/services/config.js +384 -0
  48. package/dist/services/container-runner.js +254 -0
  49. package/dist/services/container-supervisor.js +38 -0
  50. package/dist/services/context.js +416 -0
  51. package/dist/services/device-auth.js +288 -0
  52. package/dist/services/diff.js +196 -0
  53. package/dist/services/env-policy.js +108 -0
  54. package/dist/services/execution-platform.js +30 -0
  55. package/dist/services/file-detect.js +104 -0
  56. package/dist/services/file-resolver.js +199 -0
  57. package/dist/services/file-upload.js +126 -0
  58. package/dist/services/folder-key.js +22 -0
  59. package/dist/services/git-tools.js +429 -0
  60. package/dist/services/glob-match.js +164 -0
  61. package/dist/services/helper-bin.js +85 -0
  62. package/dist/services/ignore-rules.js +189 -0
  63. package/dist/services/instruction-resolver.js +54 -0
  64. package/dist/services/job-helper.js +328 -0
  65. package/dist/services/local-files.js +639 -0
  66. package/dist/services/local-tools.js +937 -0
  67. package/dist/services/login-flow.js +156 -0
  68. package/dist/services/meta.js +42 -0
  69. package/dist/services/mutation-coordinator.js +327 -0
  70. package/dist/services/mutation-groups.js +309 -0
  71. package/dist/services/mutation-recovery.js +159 -0
  72. package/dist/services/mutations.js +679 -0
  73. package/dist/services/open-url.js +68 -0
  74. package/dist/services/output.js +62 -0
  75. package/dist/services/packaged-update.js +403 -0
  76. package/dist/services/packaged.js +39 -0
  77. package/dist/services/permission-mode.js +78 -0
  78. package/dist/services/process-runner.js +412 -0
  79. package/dist/services/project-context.js +298 -0
  80. package/dist/services/redaction.js +201 -0
  81. package/dist/services/result-reconciliation.js +49 -0
  82. package/dist/services/secure-store.js +217 -0
  83. package/dist/services/session-resolver.js +115 -0
  84. package/dist/services/sia.js +51 -0
  85. package/dist/services/spinner.js +40 -0
  86. package/dist/services/supported-runtime.js +59 -0
  87. package/dist/services/task-context.js +212 -0
  88. package/dist/services/task-snapshot.js +38 -0
  89. package/dist/services/tool-result-outbox.js +195 -0
  90. package/dist/services/update.js +730 -0
  91. package/dist/services/workspace-registry.js +310 -0
  92. package/dist/services/workspace.js +580 -0
  93. package/dist/shell/shell-chat.js +1622 -0
  94. package/dist/shell/shell-commands.js +411 -0
  95. package/dist/shell/shell-prompt.js +110 -0
  96. package/dist/shell/shell-renderer.js +51 -0
  97. package/dist/shell/shell-router.js +37 -0
  98. package/dist/shell/shell.js +414 -0
  99. package/dist/shell/task-context-view.js +40 -0
  100. package/dist/staging.js +5 -0
  101. package/dist/types/index.js +6 -0
  102. package/dist/ui/agent-cards.js +111 -0
  103. package/dist/ui/agent-presentation.js +131 -0
  104. package/dist/ui/approval.js +111 -0
  105. package/dist/ui/banner.js +56 -0
  106. package/dist/ui/btw-overlay.js +230 -0
  107. package/dist/ui/change-review.js +334 -0
  108. package/dist/ui/chat-renderer.js +463 -0
  109. package/dist/ui/code-block.js +52 -0
  110. package/dist/ui/color-picker.js +100 -0
  111. package/dist/ui/colors.js +55 -0
  112. package/dist/ui/command-details.js +11 -0
  113. package/dist/ui/command-filter.js +92 -0
  114. package/dist/ui/command-item.js +6 -0
  115. package/dist/ui/command-palette.js +383 -0
  116. package/dist/ui/command-registry.js +128 -0
  117. package/dist/ui/command-renderer.js +55 -0
  118. package/dist/ui/command-review.js +187 -0
  119. package/dist/ui/composer-layout.js +74 -0
  120. package/dist/ui/conversation.js +450 -0
  121. package/dist/ui/interrupt.js +35 -0
  122. package/dist/ui/live.js +141 -0
  123. package/dist/ui/logo.js +58 -0
  124. package/dist/ui/markdown.js +205 -0
  125. package/dist/ui/message.js +21 -0
  126. package/dist/ui/screen-prompt.js +181 -0
  127. package/dist/ui/screen.js +297 -0
  128. package/dist/ui/select.js +284 -0
  129. package/dist/ui/sia-qa.js +213 -0
  130. package/dist/ui/spinner.js +23 -0
  131. package/dist/ui/sticky-stream.js +64 -0
  132. package/dist/ui/task-context-card.js +99 -0
  133. package/dist/ui/text-prompt.js +74 -0
  134. package/dist/ui/theme.js +80 -0
  135. package/dist/ui/trust.js +88 -0
  136. package/dist/ui/ui.js +101 -0
  137. package/package.json +33 -4
@@ -0,0 +1,282 @@
1
+ import { ApiError } from "../services/api.js";
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";
5
+ import { withSpinner } from "../services/spinner.js";
6
+ import { showHistory } from "./history.js";
7
+ import { c } from "../ui/colors.js";
8
+ import { pickFromList } from "../ui/select.js";
9
+ import { emptyState, icon, sectionHeader } from "../ui/ui.js";
10
+ /**
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.
22
+ */
23
+ export function registerSessions(program, ctx) {
24
+ program
25
+ .command("sessions")
26
+ .description("List conversations in the current project")
27
+ .option("-n, --limit <n>", "how many to show", "20")
28
+ .action(async (opts) => {
29
+ const client = ctx.requireAuth();
30
+ const { conversations, total } = await listSessions(ctx, client, {
31
+ limit: clampLimit(opts.limit)
32
+ });
33
+ renderSessionList(conversations, ctx.config.get("sessionId"), total);
34
+ });
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>`.
48
+ session
49
+ .command("use")
50
+ .description("Switch the active session")
51
+ .argument("[ref]", "session number or id (prompts from the list if omitted)")
52
+ .action(async (ref) => {
53
+ const client = ctx.requireAuth();
54
+ if (!ref) {
55
+ await pickSession(ctx, client);
56
+ return;
57
+ }
58
+ await switchTo(ctx, client, ref);
59
+ });
60
+ session
61
+ .command("current")
62
+ .description("Show the active session")
63
+ .action(() => {
64
+ const sid = ctx.config.get("sessionId");
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}`);
71
+ });
72
+ session
73
+ .command("delete")
74
+ .description("Delete a session")
75
+ .argument("<ref>", "session number from `cos sessions`, or a session id")
76
+ .action(async (ref) => {
77
+ const client = ctx.requireAuth();
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);
100
+ });
101
+ program
102
+ .command("clear")
103
+ .description("Start a new session (forgets the active one locally)")
104
+ .action(() => {
105
+ clearActiveSession(ctx);
106
+ success("Cleared. Your next message starts a fresh session.");
107
+ });
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
+ }
249
+ function clampLimit(raw) {
250
+ const n = parseInt(raw, 10);
251
+ if (Number.isNaN(n))
252
+ return 20;
253
+ return Math.min(Math.max(n, 1), 100);
254
+ }
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) {
261
+ if (items.length === 0) {
262
+ for (const l of emptyState("No conversations yet.", "Type a message to start one, or run /new.")) {
263
+ line(l);
264
+ }
265
+ return;
266
+ }
267
+ line();
268
+ line(sectionHeader(`Sessions (${items.length} of ${total})`));
269
+ const w = Math.max(0, ...items.map((s) => [...s.title].length));
270
+ const nw = String(items.length).length;
271
+ items.forEach((s, i) => {
272
+ const active = s.session_id === activeId;
273
+ const num = c.dim(String(i + 1).padStart(nw));
274
+ const marker = active ? icon.active : " ";
275
+ const title = (active ? c.brand : c.value)(s.title.padEnd(w));
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>"));
281
+ line();
282
+ }
@@ -0,0 +1,160 @@
1
+ import { COMMANDS_OPT_IN_ENV, localCommandsState } from "../services/client-tools.js";
2
+ import { getPermissionMode } from "../services/permission-mode.js";
3
+ import { errorLine, line } from "../services/output.js";
4
+ import { c } from "../ui/colors.js";
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";
9
+ /**
10
+ * `cos settings` — the CLI's persisted behaviour settings, in one place.
11
+ *
12
+ * /settings show them
13
+ * /settings commands on|off allow or stop local commands (run_command)
14
+ *
15
+ * Most settings already have their own toggle (/fast, /hipwr, /sia, /websearch)
16
+ * and keep it; this command lists them together and owns the one setting that
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.
20
+ */
21
+ export function registerSettings(program, ctx) {
22
+ program
23
+ .command("settings")
24
+ .argument("[setting]", 'the setting to change, e.g. "commands"')
25
+ .argument("[value]", "on or off")
26
+ .description("Show or change CLI settings (e.g. settings commands on)")
27
+ .action((setting, value) => {
28
+ runSettings(ctx, [setting, value].filter(Boolean).join(" "));
29
+ });
30
+ }
31
+ const ON = new Set(["on", "yes", "true", "enable", "enabled"]);
32
+ const OFF = new Set(["off", "no", "false", "disable", "disabled"]);
33
+ export function runSettings(ctx, argStr) {
34
+ const [name = "", value = ""] = argStr.trim().toLowerCase().split(/\s+/);
35
+ if (!name)
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);
43
+ if (name !== "commands" && name !== "local-commands") {
44
+ errorLine(`Unknown setting "${name}". Try: /settings commands on|off, /settings updates on|off, /settings channel latest|beta|next|staging`);
45
+ return;
46
+ }
47
+ if (!ON.has(value) && !OFF.has(value)) {
48
+ errorLine("Use /settings commands on or /settings commands off.");
49
+ return;
50
+ }
51
+ const enable = ON.has(value);
52
+ ctx.config.set("localCommandsEnabled", enable);
53
+ line();
54
+ if (enable) {
55
+ line(" " + c.ok("✓") + " " + c.value("Local commands enabled."));
56
+ // Said plainly at the moment it is switched on: what a command can do.
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)
64
+ line(" " + c.dim(l));
65
+ }
66
+ else {
67
+ line(" " + c.ok("✓") + " " + c.value("Local commands disabled.") + " " + c.dim("The model can still read, search and propose file changes."));
68
+ }
69
+ line();
70
+ }
71
+ /**
72
+ * What enabling local commands means, in the user's terms. Shown when it is
73
+ * switched on — not buried in documentation — because it is the one decision
74
+ * here that lets project code run.
75
+ */
76
+ export const LOCAL_COMMANDS_NOTICE = [
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).",
81
+ "Approved project code runs as your Windows account: it can read what you can",
82
+ "read, and may open other applications through Windows file associations.",
83
+ "Turn it off again with /settings commands off."
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
+ }
133
+ function showSettings(ctx) {
134
+ const state = localCommandsState(ctx, undefined, getPermissionMode(ctx.config) === "auto");
135
+ const row = (label, value, note = "") => line(" " + c.label(label.padEnd(16)) + value + (note ? " " + c.dim(note) : ""));
136
+ line();
137
+ line(sectionHeader("Settings"));
138
+ line();
139
+ row("Local commands", state.enabled ? c.ok("enabled") : c.dim("disabled"), state.source === "env"
140
+ ? `via ${COMMANDS_OPT_IN_ENV}=1`
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");
146
+ if (state.enabled && state.blockedBy)
147
+ row("", c.warn("not active"), state.blockedBy);
148
+ row("Mode", c.value(ctx.mode));
149
+ row("Model", c.value(ctx.config.get("model") || "mode default"));
150
+ row("Fast", ctx.fast ? c.ok("on") : c.dim("off"), "/fast");
151
+ row("High Power", ctx.highPower ? c.ok("on") : c.dim("off"), "/hipwr");
152
+ row("Clarification", c.value(ctx.siaMode), "/sia");
153
+ const web = ctx.webSearch;
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>");
159
+ line();
160
+ }