@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,411 @@
1
+ import { commandDetails } from "../ui/command-details.js";
2
+ import { workspaceRoot } from "../services/local-files.js";
3
+ import { line } from "../services/output.js";
4
+ import { CommanderError } from "commander";
5
+ import { ApiError } from "../services/api.js";
6
+ import { AuthRequiredError } from "../services/context.js";
7
+ import { errorLine, info } from "../services/output.js";
8
+ import { askSideQuestion } from "../commands/btw.js";
9
+ import { runUpdate } from "../commands/update.js";
10
+ import { runSearch } from "../commands/search.js";
11
+ import { useRepository } from "../commands/repo.js";
12
+ import { showRepositories } from "../commands/repos.js";
13
+ import { runSettings } from "../commands/settings.js";
14
+ import { runReview } from "../commands/review.js";
15
+ import { runUndo, showChanges } from "../commands/changes.js";
16
+ import { runProject } from "../commands/project.js";
17
+ import { showContext } from "../commands/context.js";
18
+ import { listMemory, showArtifact } from "../commands/memory.js";
19
+ import { showHistory } from "../commands/history.js";
20
+ import { deleteSession, newSession, pickSession, switchTo } from "../commands/sessions.js";
21
+ import { clearActiveSession } from "../services/session-resolver.js";
22
+ import { runCompact, runPermissions } from "../commands/permissions.js";
23
+ import { parsePermissionMode } from "../services/permission-mode.js";
24
+ import { visibleCommands } from "../ui/command-item.js";
25
+ import { confirmColor, pickColor } from "../ui/color-picker.js";
26
+ import { pickFromList } from "../ui/select.js";
27
+ import { isThemeColor, setAccent, THEME_ORDER } from "../ui/theme.js";
28
+ import { armWebSearch, chatTurn, isWebSearchStateArg, openSource, pickChatType, pickMode, pickModel, searchNow, setChatType, setFast, setHighPower, setSia, setMode, setModel, setWebSearch, showSources, fastInEffect } from "./shell-chat.js";
29
+ import { c } from "../ui/colors.js";
30
+ import { buildFooter } from "./shell-prompt.js";
31
+ import { printShellHelp } from "./shell-renderer.js";
32
+ const STAY = { exit: false };
33
+ /**
34
+ * Invoke an existing command through the SAME Commander program, so the shell
35
+ * reuses each command's real implementation instead of duplicating it. Errors
36
+ * are caught (rather than exiting the process) so the shell survives them.
37
+ */
38
+ async function route(program, argv) {
39
+ try {
40
+ await program.parseAsync(argv, { from: "user" });
41
+ }
42
+ catch (err) {
43
+ if (err instanceof AuthRequiredError)
44
+ errorLine(err.message);
45
+ else if (err instanceof ApiError)
46
+ errorLine(`${err.message} (${err.code})`);
47
+ else if (err instanceof CommanderError) {
48
+ /* Commander already printed its message; keep the shell alive. */
49
+ }
50
+ else
51
+ errorLine(err.message);
52
+ }
53
+ finally {
54
+ // A routed command may set a non-zero exit code on error — don't let it
55
+ // leak out of the long-lived shell process.
56
+ process.exitCode = 0;
57
+ }
58
+ }
59
+ /** Handle a `/…` line. Returns { exit } to tell the loop whether to stop. */
60
+ export async function handleSlash(ctx, program, client, input) {
61
+ const body = input.slice(1); // drop the leading '/'
62
+ const parts = body.split(/\s+/).filter(Boolean);
63
+ const cmd = (parts[0] ?? "").toLowerCase();
64
+ const rest = parts.slice(1);
65
+ const argStr = body.slice((parts[0] ?? "").length).trim();
66
+ switch (cmd) {
67
+ case "exit":
68
+ case "quit":
69
+ return { exit: true };
70
+ case "details":
71
+ for (const row of commandDetails(ctx, JSON.stringify([client.mutationRecoveryScope(), ctx.config.get("sessionId"), workspaceRoot()])))
72
+ line(row);
73
+ return STAY;
74
+ case "help":
75
+ // In a TTY, /help is an arrow-navigable menu (Enter runs the picked
76
+ // command); piped/non-interactive falls back to the static list.
77
+ if (!process.stdin.isTTY) {
78
+ printShellHelp();
79
+ return STAY;
80
+ }
81
+ return runHelpMenu(ctx, program, client);
82
+ // Accent theme (also /theme). `/color <name>` applies directly; bare
83
+ // `/color` opens the inline selector. Applied on Enter and persisted.
84
+ case "color":
85
+ case "theme": {
86
+ const arg = argStr.trim().toLowerCase();
87
+ if (arg) {
88
+ if (isThemeColor(arg)) {
89
+ setAccent(arg);
90
+ ctx.config.set("theme", { accent: arg });
91
+ confirmColor(arg);
92
+ }
93
+ else {
94
+ errorLine(`Unknown color "${arg}". Try: ${THEME_ORDER.join(", ")}.`);
95
+ }
96
+ return STAY;
97
+ }
98
+ const chosen = await pickColor();
99
+ if (chosen) {
100
+ ctx.config.set("theme", { accent: chosen });
101
+ confirmColor(chosen);
102
+ }
103
+ return STAY;
104
+ }
105
+ // `/chat` selects the chat experience: bare shows current, `/chat carrier`
106
+ // and `/chat standard` switch. `/chat <other text>` still sends a message
107
+ // (you're already in the shell, so typing directly also works).
108
+ case "chat": {
109
+ const t = argStr.trim().toLowerCase();
110
+ const isTypeArg = ["", "carrier", "carrieros", "standard", "plain", "normal"].includes(t);
111
+ if (isTypeArg)
112
+ setChatType(ctx, argStr);
113
+ else
114
+ await chatTurn(ctx, client, argStr, { footer: buildFooter(ctx) });
115
+ return STAY;
116
+ }
117
+ // `/switch` — arrow-key picker for the chat experience (Carrier ⇄ Standard).
118
+ // An explicit arg (`/switch standard`) sets it directly.
119
+ case "switch":
120
+ if (argStr.trim())
121
+ setChatType(ctx, argStr);
122
+ else
123
+ await pickChatType(ctx);
124
+ return STAY;
125
+ // ── Chat behavior — handled here so the prompt reflects it immediately ────
126
+ case "modes":
127
+ await pickMode(ctx, client);
128
+ return STAY;
129
+ case "models":
130
+ await pickModel(ctx, client);
131
+ return STAY;
132
+ case "mode":
133
+ // `/mode manual|plan|accept-edits` is the permission mode; any other
134
+ // argument (general, code, …) is the Carrier chat mode, as before.
135
+ // "auto" stays the chat mode's Auto here — the Auto PERMISSION mode is
136
+ // `/permissions auto`, so an existing `/mode auto` never grants change authority.
137
+ if (parsePermissionMode(argStr) && parsePermissionMode(argStr) !== "auto")
138
+ await runPermissions(ctx, argStr);
139
+ else
140
+ await setMode(ctx, client, argStr);
141
+ return STAY;
142
+ case "permissions":
143
+ await runPermissions(ctx, argStr);
144
+ return STAY;
145
+ case "plan":
146
+ await runPermissions(ctx, "plan");
147
+ return STAY;
148
+ case "compact":
149
+ await runCompact(ctx, client);
150
+ return STAY;
151
+ case "model":
152
+ await setModel(ctx, client, argStr);
153
+ return STAY;
154
+ // One command, three jobs — the argument decides which:
155
+ // /websearch arm the next message
156
+ // /websearch on|off|auto|status change or show the standing preference
157
+ // /websearch <anything else> search for it right now
158
+ // Anything that isn't a recognised state word is treated as a query, so
159
+ // "/websearch latest AI news" does what it looks like it should.
160
+ case "websearch":
161
+ case "web": {
162
+ const arg = argStr.trim();
163
+ if (!arg)
164
+ armWebSearch(ctx);
165
+ else if (isWebSearchStateArg(arg))
166
+ setWebSearch(ctx, arg);
167
+ else
168
+ await searchNow(ctx, client, arg, buildFooter(ctx));
169
+ return STAY;
170
+ }
171
+ // Turn shaping. Bare toggles; an explicit on|off sets.
172
+ case "fast":
173
+ await setFast(ctx, argStr, client);
174
+ return STAY;
175
+ case "hipwr":
176
+ case "highpower":
177
+ setHighPower(ctx, argStr);
178
+ return STAY;
179
+ case "sia":
180
+ await setSia(ctx, argStr);
181
+ return STAY;
182
+ // A side question about this conversation. Never becomes a turn — see
183
+ // commands/btw.ts and POST /v1/sessions/:id/ask.
184
+ case "btw":
185
+ // While a main turn renders, it owns the transient region — the answer is
186
+ // committed to the transcript instead of shown as a dismissible panel.
187
+ await askSideQuestion(ctx, client, argStr, ctx.mainTurnRunning);
188
+ return STAY;
189
+ // One command: checks, and offers to install when something newer exists.
190
+ case "update":
191
+ await runUpdate({ config: ctx.config, busy: ctx.mainTurnRunning === true });
192
+ return STAY;
193
+ case "sources":
194
+ showSources(ctx);
195
+ return STAY;
196
+ case "open":
197
+ if (rest.length === 0) {
198
+ errorLine("Usage: /open <n> (see /sources)");
199
+ return STAY;
200
+ }
201
+ openSource(ctx, rest[0]);
202
+ return STAY;
203
+ // `/new` is the preferred form; `/clear` stays as the original spelling.
204
+ // A title needs POST /v1/sessions, which only creates Standard chats — the
205
+ // command says so rather than downgrading a Carrier chat silently.
206
+ case "new":
207
+ await newSession(ctx, argStr.trim());
208
+ return STAY;
209
+ // A new task: the current one stays in history (/sessions), with its audit
210
+ // and recovery records; attachments, Plan and Accept Edits do not carry over.
211
+ case "clear":
212
+ clearActiveSession(ctx);
213
+ ctx.clearAttachments();
214
+ info("New task. Your next message starts it — the previous one is kept in /sessions; permissions are back to Manual.");
215
+ return STAY;
216
+ case "context":
217
+ if ((rest[0] ?? "").toLowerCase() === "project") {
218
+ // `/context project [attach|detach|--preview] [--repo <name>]`
219
+ const flags = rest.slice(1);
220
+ const repoAt = flags.findIndex((f) => f === "--repo" || f === "-r");
221
+ const repository = repoAt !== -1 ? flags[repoAt + 1] : undefined;
222
+ const verb = flags.find((f) => !f.startsWith("-") && f !== repository);
223
+ await runProject(ctx, verb, flags.includes("--preview"), repository);
224
+ return STAY;
225
+ }
226
+ await showContext(ctx, client);
227
+ return STAY;
228
+ // `/memory` lists what the engine has compressed; `/memory 2` reads one.
229
+ case "memory":
230
+ if (argStr.trim())
231
+ await showArtifact(ctx, client, argStr.trim());
232
+ else
233
+ await listMemory(ctx, client);
234
+ return STAY;
235
+ // ── Routed to the existing command implementations ───────────────────────
236
+ case "whoami":
237
+ await route(program, ["whoami"]);
238
+ return STAY;
239
+ case "repo": {
240
+ const [verb, target] = rest;
241
+ if ((verb ?? "").toLowerCase() === "use") {
242
+ await useRepository(ctx, target);
243
+ return STAY;
244
+ }
245
+ await route(program, ["repo"]);
246
+ return STAY;
247
+ }
248
+ case "repos":
249
+ showRepositories();
250
+ return STAY;
251
+ case "settings":
252
+ runSettings(ctx, argStr);
253
+ return STAY;
254
+ case "review":
255
+ // A review shares the keyboard with a running turn's approvals — wait.
256
+ if (ctx.mainTurnRunning) {
257
+ errorLine("Wait for the current response to finish before starting a review.");
258
+ return STAY;
259
+ }
260
+ await runReview(ctx, client, rest[0], buildFooter(ctx));
261
+ return STAY;
262
+ case "doctor":
263
+ await route(program, ["doctor"]);
264
+ return STAY;
265
+ case "usage":
266
+ await route(program, ["usage"]);
267
+ return STAY;
268
+ case "files":
269
+ await route(program, ["files", ...rest]);
270
+ return STAY;
271
+ case "changes":
272
+ showChanges();
273
+ return STAY;
274
+ case "undo":
275
+ // The undo prompt and a running turn's change review would fight over
276
+ // the keyboard, and the turn may be about to touch the same file.
277
+ if (ctx.mainTurnRunning) {
278
+ errorLine("Wait for the current response to finish before undoing.");
279
+ return STAY;
280
+ }
281
+ {
282
+ // `/undo [operation] [--repo <name>]` — the repository is explicit or
283
+ // it is the active one; there is no "latest anywhere".
284
+ const repoAt = rest.findIndex((t) => t === "--repo" || t === "-r");
285
+ const repository = repoAt !== -1 ? rest[repoAt + 1] : undefined;
286
+ const operation = rest.find((t, i) => !t.startsWith("-") && i !== repoAt + 1);
287
+ await runUndo(client, operation, repository);
288
+ }
289
+ return STAY;
290
+ case "search":
291
+ if (!argStr.trim()) {
292
+ errorLine("Usage: /search <text>");
293
+ return STAY;
294
+ }
295
+ await runSearch(ctx, argStr.trim());
296
+ return STAY;
297
+ case "version":
298
+ await route(program, ["version"]);
299
+ return STAY;
300
+ case "logout":
301
+ await route(program, ["logout"]);
302
+ return STAY;
303
+ case "login":
304
+ await route(program, ["login", ...rest]);
305
+ return STAY;
306
+ // In a TTY the list IS the picker — printing a numbered list you can't act
307
+ // on just forces a second command. Matches /modes and /models, which are
308
+ // both pickers. Piped output, or an explicit flag like `-n 50`, still gets
309
+ // the plain printed list.
310
+ case "resume":
311
+ case "sessions":
312
+ if (rest.length === 0 && process.stdin.isTTY)
313
+ await pickSession(ctx, client);
314
+ else
315
+ await route(program, ["sessions", ...rest]);
316
+ return STAY;
317
+ // `/history`, `/history 2`, `/history <id>` — the resolver handles all three.
318
+ case "history":
319
+ await showHistory(ctx, client, rest[0]);
320
+ return STAY;
321
+ case "upload":
322
+ if (refuseFilesInFastMode(ctx))
323
+ return STAY;
324
+ if (rest.length === 0) {
325
+ errorLine("Usage: /upload <file>");
326
+ return STAY;
327
+ }
328
+ // In the shell the upload command uploads + auto-attaches + prints "Ready.".
329
+ await route(program, ["upload", ...rest]);
330
+ return STAY;
331
+ case "attach": {
332
+ if (refuseFilesInFastMode(ctx))
333
+ return STAY;
334
+ const uploads = ctx.config.get("uploads") ?? [];
335
+ let target = rest[0];
336
+ if (!target) {
337
+ if (uploads.length === 0) {
338
+ errorLine("No uploads yet. Run /upload <file> first.");
339
+ return STAY;
340
+ }
341
+ target = uploads[0].file_id; // most recent
342
+ }
343
+ ctx.attachFile(target);
344
+ const named = uploads.find((u) => u.file_id === target);
345
+ info(`Attached ${named ? `"${named.filename}"` : target}. ` +
346
+ `${ctx.attachedFileIds.length} file(s) will ride along; /detach to clear.`);
347
+ return STAY;
348
+ }
349
+ case "detach":
350
+ ctx.clearAttachments();
351
+ info("Cleared attached files.");
352
+ return STAY;
353
+ // `/session` picker · `/session 2` · `/session <id>` · and the original
354
+ // `/session use|current|delete|rename …` sub-verbs, all still working.
355
+ case "session": {
356
+ const sub = (rest[0] ?? "").toLowerCase();
357
+ if (rest.length === 0) {
358
+ await pickSession(ctx, client);
359
+ return STAY;
360
+ }
361
+ if (sub === "delete") {
362
+ if (!rest[1]) {
363
+ errorLine("Usage: /session delete <n> (see /sessions)");
364
+ return STAY;
365
+ }
366
+ await deleteSession(ctx, client, rest[1]);
367
+ return STAY;
368
+ }
369
+ if (sub === "use") {
370
+ if (!rest[1])
371
+ await pickSession(ctx, client);
372
+ else
373
+ await switchTo(ctx, client, rest[1]);
374
+ return STAY;
375
+ }
376
+ if (sub === "current" || sub === "rename") {
377
+ await route(program, ["session", ...rest]);
378
+ return STAY;
379
+ }
380
+ // Bare reference: a number from /sessions, or an id.
381
+ await switchTo(ctx, client, rest[0]);
382
+ return STAY;
383
+ }
384
+ default:
385
+ errorLine(`Unknown command: /${cmd}. Type /help for the list.`);
386
+ return STAY;
387
+ }
388
+ }
389
+ /** Interactive /help: browse every command with ↑/↓ and run the chosen one. */
390
+ async function runHelpMenu(ctx, program, client) {
391
+ const chosen = await pickFromList({
392
+ title: "Commands",
393
+ description: "Type a message to chat, or pick a command to run.",
394
+ choices: visibleCommands().map((entry) => ({
395
+ value: entry.name,
396
+ label: entry.name,
397
+ description: entry.desc
398
+ }))
399
+ });
400
+ if (chosen == null || chosen === "/help")
401
+ return STAY; // Esc, or avoid reopening
402
+ return handleSlash(ctx, program, client, chosen);
403
+ }
404
+ /** Fast Mode's model can't read files — as the web disables its paperclip. True when refused. */
405
+ function refuseFilesInFastMode(ctx) {
406
+ if (!fastInEffect(ctx))
407
+ return false;
408
+ errorLine("Fast mode can't read files — its model is text-only.");
409
+ line(" " + c.dim("Run ") + c.cmd("/fast off") + c.dim(" to attach files."));
410
+ return true;
411
+ }
@@ -0,0 +1,110 @@
1
+ import { getPermissionMode, permissionModeLabel } from "../services/permission-mode.js";
2
+ import { attachedFilenames } from "../services/file-upload.js";
3
+ import { branchLabel, peekWorkspace } from "../services/workspace.js";
4
+ import { activeRepository, inWorkspaceMode, peekRepositoryDetails } from "../services/workspace-registry.js";
5
+ import { c } from "../ui/colors.js";
6
+ import { modeLabelShort, modelLabelShort, turnShapeLabels, webSearchLabelShort } from "./shell-chat.js";
7
+ /** The green caret the shell prompt uses (non-TTY fallback). */
8
+ export const CARET = c.brand("›") + " ";
9
+ /** Light purple used for the "Standard chat" footer label (distinct from the
10
+ * accent-green Carrier Chat label). */
11
+ const STANDARD_LABEL = c.value;
12
+ /**
13
+ * The dim status footer shown directly beneath the input box, Claude-style:
14
+ * ‖ Carrier OS chat · Grok 4.1 Fast
15
+ * The active chat/mode leads (accent), and the model (yellow) trails. Hidden
16
+ * while the palette is open.
17
+ */
18
+ export function buildFooter(ctx) {
19
+ if (ctx.chatType === "carrier" && ctx.carrierMaintenance !== false) {
20
+ const state = ctx.carrierMaintenance === true ? "Carrier Chat paused" : "Carrier Chat status unavailable";
21
+ return repoPart() + c.dim(" · ") + c.warn(state) + c.dim(" · /switch standard");
22
+ }
23
+ const mode = modeLabelShort(ctx);
24
+ const model = modelLabelShort(ctx);
25
+ // The leading token reflects the CHAT TYPE:
26
+ // • carrier → "Carrier OS chat" (brand, theme-light green). Carrier chat
27
+ // always uses the General mode, so the mode is NOT shown.
28
+ // • standard → "Standard chat" (light purple) followed by the active mode,
29
+ // since Standard chat is where modes actually vary.
30
+ const isStandard = ctx.chatType === "standard";
31
+ const label = isStandard ? "Standard" : "Carrier OS";
32
+ const paintLabel = isStandard ? STANDARD_LABEL : c.brand;
33
+ const dot = c.dim(" · ");
34
+ // Show the active mode ONLY in standard chat: "Standard chat · Code · Grok".
35
+ const modePart = isStandard ? dot + c.value(mode) : "";
36
+ const context = paintLabel(label) + c.dim(" chat") + modePart + dot + c.file(model);
37
+ // Web search rides in the footer as a capability chip next to the model —
38
+ // the point is that you can tell at a glance whether the NEXT message will
39
+ // search. Silent on the workspace default and when explicitly off: the CLI
40
+ // can't see the workspace toggle, so claiming a state there would be a lie,
41
+ // and "off" is the quiet baseline that needs no chip.
42
+ const webLabel = webSearchLabelShort(ctx);
43
+ const webPart = webLabel ? dot + c.accent(webLabel) : "";
44
+ // Turn-shaping toggles (Fast, HIPWR) — shown only when on, so the default
45
+ // footer stays quiet and an enabled one actually stands out.
46
+ // Already coloured by turnShapeLabels — each chip carries its own meaning.
47
+ const shapePart = turnShapeLabels(ctx)
48
+ .map((l) => dot + l)
49
+ .join("");
50
+ // Active conversation. Set apart from the dot-chain on purpose: everything
51
+ // before it is a SETTING for the next message, while this is WHERE you are.
52
+ // Chained with a dot in matching weight it reads as another setting — which
53
+ // is exactly how a title like "AWS outage research" gets mistaken for a mode.
54
+ // Only shown once the title is known (from /sessions, /session or /new); a
55
+ // fresh chat has none until the backend generates one, and a placeholder
56
+ // would be worse than saying nothing.
57
+ // Quoted, because titles are auto-generated from the first message and are
58
+ // often a short lowercase phrase — unquoted, `in hi` reads as a broken
59
+ // sentence rather than the name of a conversation. Matches how the session
60
+ // commands already refer to them ("Switched to “hi”.").
61
+ const title = ctx.config.get("sessionTitle");
62
+ const convo = title ? " " + c.dim(`in “${clip(title, 26)}”`) : "";
63
+ // Attachment indicator: one file shows its name, several show a compact count.
64
+ const names = attachedFilenames(ctx);
65
+ const attach = names.length === 1
66
+ ? dot + c.accent(`Attached: ${names[0]}`)
67
+ : names.length > 1
68
+ ? dot + c.accent(`${names.length} attached`)
69
+ : "";
70
+ // Permission mode: always shown, so what the next message may do is never a guess.
71
+ const permission = getPermissionMode(ctx.config);
72
+ const paintPermission = permission === "auto" ? c.err : permission === "accept_edits" ? c.warn : permission === "plan" ? c.accent : c.dim;
73
+ const permissionPart = dot + paintPermission(permissionModeLabel(permission));
74
+ return repoPart() + c.dim(" · ") + (ctx.mainTurnRunning ? c.dim("Working · Ctrl+C stops") + permissionPart : context + permissionPart + convo + shapePart + webPart + attach);
75
+ }
76
+ /**
77
+ * Where you are on disk, trailing the footer: "my-app · main".
78
+ *
79
+ * peek, not get: this runs on every keystroke, and the workspace must never be
80
+ * something the composer can spawn a Git process for. The descriptor is built
81
+ * once at startup; if it somehow is not there, the footer simply says nothing.
82
+ *
83
+ * Omitted entirely outside a repository. The project name alone would just
84
+ * repeat the folder you can already see in your own prompt, and a footer earns
85
+ * its width by telling you something you would otherwise have to ask for —
86
+ * which branch you are about to work against.
87
+ */
88
+ function repoPart() {
89
+ // A workspace names the repository you are acting on; that is the thing that
90
+ // changes under you, and the one fact a stray `/repo use` would make stale.
91
+ if (inWorkspaceMode()) {
92
+ const active = activeRepository();
93
+ const details = peekRepositoryDetails(active);
94
+ const branch = (process.stdout.columns ?? 80) >= 80 && details?.branch ? ` · ${clip(details.branch, 20)}` : "";
95
+ return " " + c.dim(`${clip(active.name, 24)}${branch}`);
96
+ }
97
+ const ws = peekWorkspace();
98
+ if (!ws)
99
+ return "";
100
+ if (ws.repository.state !== "detected")
101
+ return " " + c.dim(clip(ws.project.name, 24));
102
+ const branch = branchLabel(ws.repository);
103
+ if (!branch)
104
+ return "";
105
+ return " " + c.dim(`${clip(ws.project.name, 20)}${(process.stdout.columns ?? 80) >= 80 ? ` · ${clip(branch, 22)}` : ""}`);
106
+ }
107
+ /** Trim a title to keep the footer on one row. */
108
+ function clip(s, max) {
109
+ return [...s].length <= max ? s : [...s].slice(0, max - 1).join("") + "…";
110
+ }
@@ -0,0 +1,51 @@
1
+ import chalk from "chalk";
2
+ import { kv, line } from "../services/output.js";
3
+ import { renderBrandmark } from "../ui/banner.js";
4
+ import { c } from "../ui/colors.js";
5
+ import { byGroupThenRank, visibleCommands } from "../ui/command-item.js";
6
+ import { twoCol } from "../ui/ui.js";
7
+ /** First-run welcome shown when there's no session — just the brandmark; the
8
+ * device-login flow prints the "Welcome to Carrier OS" line + guidance. */
9
+ export function printWelcome() {
10
+ line();
11
+ for (const l of renderBrandmark())
12
+ line(l);
13
+ line();
14
+ }
15
+ /** The post-login welcome screen (Claude-style boxed header + account summary),
16
+ * shown right before the shell opens. */
17
+ export function renderWelcomeBack(_scope, developerName) {
18
+ const title = "Welcome to Carrier OS";
19
+ const inner = ` ${title} `;
20
+ const rule = "─".repeat(inner.length);
21
+ line();
22
+ line(" " + c.brand("┌" + rule + "┐"));
23
+ line(" " + c.brand("│") + chalk.bold(inner) + c.brand("│"));
24
+ line(" " + c.brand("└" + rule + "┘"));
25
+ line();
26
+ kv("User", developerName);
27
+ line();
28
+ }
29
+ export function printShellHelp() {
30
+ // Generated from the same registry the palette uses, so this list can't drift
31
+ // out of sync with the commands that actually exist — and it hides whatever
32
+ // doesn't apply to the current chat type, exactly as the palette does.
33
+ const rows = visibleCommands()
34
+ .sort(byGroupThenRank)
35
+ .map((cmd) => [cmd.name, cmd.desc]);
36
+ line();
37
+ line(" " + c.dim("Type a message to chat, or run a slash command:"));
38
+ line();
39
+ for (const l of twoCol(rows, c.value, c.dim))
40
+ line(l);
41
+ line();
42
+ line(" " +
43
+ c.dim("Keys ") +
44
+ c.key("↑↓") +
45
+ c.dim(" history ") +
46
+ c.key("Tab") +
47
+ c.dim(" complete ") +
48
+ c.key("Ctrl+C") +
49
+ c.dim(" twice to exit"));
50
+ line();
51
+ }
@@ -0,0 +1,37 @@
1
+ import { chatInputWithFiles } from "./shell-chat.js";
2
+ import { handleSlash } from "./shell-commands.js";
3
+ import { buildFooter } from "./shell-prompt.js";
4
+ /**
5
+ * Route one line of shell input: a `/…` line goes to the slash-command handler;
6
+ * anything else is a chat message sent through the shared chat turn.
7
+ */
8
+ /**
9
+ * True when `input` starts a MAIN conversation turn (a chat message) rather
10
+ * than a command. The shell needs to know before dispatching, because a main
11
+ * turn runs in the background while commands stay awaited — and this must use
12
+ * exactly the same rules as dispatchLine below, or the two would disagree about
13
+ * what a line is.
14
+ */
15
+ export function isMainTurn(input) {
16
+ const prefixed = input.match(/^(?:cos|carrieros)\s+(.+)$/i);
17
+ const line = prefixed ? prefixed[1].trim() : input;
18
+ return !line.startsWith("/") && !prefixed;
19
+ }
20
+ export async function dispatchLine(ctx, program, client, input,
21
+ /** Abort handle for the main turn; the shell owns Ctrl+C. */
22
+ signal) {
23
+ // Forgive users who type the binary name inside the shell, e.g.
24
+ // "cos models" → treat it as the "/models" command.
25
+ const prefixed = input.match(/^(?:cos|carrieros)\s+(.+)$/i);
26
+ if (prefixed) {
27
+ const rest = prefixed[1].trim();
28
+ return handleSlash(ctx, program, client, rest.startsWith("/") ? rest : `/${rest}`);
29
+ }
30
+ if (input.startsWith("/")) {
31
+ return handleSlash(ctx, program, client, input);
32
+ }
33
+ // Chat: intelligently detect a leading/quoted local file path, upload+attach
34
+ // it, and strip it from the prompt before sending (the model never sees paths).
35
+ await chatInputWithFiles(ctx, client, input, buildFooter(ctx), signal);
36
+ return { exit: false };
37
+ }