@carrieros/cli 0.1.0 → 0.3.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.
Files changed (104) hide show
  1. package/README.md +142 -57
  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 +102 -13
  7. package/dist/commands/context.js +160 -0
  8. package/dist/commands/doctor.js +53 -8
  9. package/dist/commands/files.js +84 -23
  10. package/dist/commands/help.js +3 -1
  11. package/dist/commands/history.js +88 -23
  12. package/dist/commands/login.js +44 -41
  13. package/dist/commands/logout.js +13 -4
  14. package/dist/commands/memory.js +162 -0
  15. package/dist/commands/mode-model.js +39 -3
  16. package/dist/commands/modes.js +4 -1
  17. package/dist/commands/project.js +106 -0
  18. package/dist/commands/repo.js +146 -0
  19. package/dist/commands/repos.js +61 -0
  20. package/dist/commands/review.js +92 -0
  21. package/dist/commands/scope.js +152 -0
  22. package/dist/commands/search.js +92 -0
  23. package/dist/commands/sessions.js +219 -65
  24. package/dist/commands/settings.js +87 -0
  25. package/dist/commands/update.js +159 -0
  26. package/dist/commands/upload.js +204 -31
  27. package/dist/commands/usage.js +212 -16
  28. package/dist/commands/whoami.js +2 -1
  29. package/dist/ide/editor-context.js +172 -0
  30. package/dist/ide/ide-session.js +94 -0
  31. package/dist/ide/tool-host.js +109 -0
  32. package/dist/main.js +30 -1
  33. package/dist/services/api.js +171 -13
  34. package/dist/services/chat-stream.js +145 -0
  35. package/dist/services/checkpoints.js +116 -0
  36. package/dist/services/client-tools.js +260 -0
  37. package/dist/services/command-coordinator.js +200 -0
  38. package/dist/services/command-policy.js +404 -0
  39. package/dist/services/config.js +249 -22
  40. package/dist/services/context.js +307 -6
  41. package/dist/services/device-auth.js +261 -0
  42. package/dist/services/diff.js +196 -0
  43. package/dist/services/env-policy.js +108 -0
  44. package/dist/services/file-detect.js +104 -0
  45. package/dist/services/file-resolver.js +199 -0
  46. package/dist/services/file-upload.js +126 -0
  47. package/dist/services/git-tools.js +248 -0
  48. package/dist/services/glob-match.js +164 -0
  49. package/dist/services/helper-bin.js +64 -0
  50. package/dist/services/ignore-rules.js +189 -0
  51. package/dist/services/job-helper.js +307 -0
  52. package/dist/services/local-files.js +517 -0
  53. package/dist/services/local-tools.js +432 -0
  54. package/dist/services/login-flow.js +120 -10
  55. package/dist/services/meta.js +3 -1
  56. package/dist/services/mutation-coordinator.js +161 -0
  57. package/dist/services/mutations.js +493 -0
  58. package/dist/services/open-url.js +68 -0
  59. package/dist/services/output.js +13 -5
  60. package/dist/services/packaged.js +24 -0
  61. package/dist/services/process-runner.js +406 -0
  62. package/dist/services/project-context.js +298 -0
  63. package/dist/services/redaction.js +201 -0
  64. package/dist/services/secure-store.js +197 -0
  65. package/dist/services/session-resolver.js +108 -0
  66. package/dist/services/sia.js +51 -0
  67. package/dist/services/spinner.js +23 -1
  68. package/dist/services/update.js +286 -0
  69. package/dist/services/workspace-registry.js +309 -0
  70. package/dist/services/workspace.js +573 -0
  71. package/dist/shell/shell-chat.js +1115 -59
  72. package/dist/shell/shell-commands.js +220 -19
  73. package/dist/shell/shell-prompt.js +89 -37
  74. package/dist/shell/shell-renderer.js +19 -38
  75. package/dist/shell/shell-router.js +19 -3
  76. package/dist/shell/shell.js +232 -44
  77. package/dist/types/index.js +3 -1
  78. package/dist/ui/approval.js +81 -0
  79. package/dist/ui/banner.js +55 -13
  80. package/dist/ui/btw-overlay.js +230 -0
  81. package/dist/ui/change-review.js +87 -0
  82. package/dist/ui/chat-renderer.js +223 -29
  83. package/dist/ui/color-picker.js +21 -0
  84. package/dist/ui/colors.js +9 -1
  85. package/dist/ui/command-filter.js +40 -5
  86. package/dist/ui/command-palette.js +122 -62
  87. package/dist/ui/command-registry.js +85 -11
  88. package/dist/ui/command-review.js +138 -0
  89. package/dist/ui/composer-layout.js +41 -0
  90. package/dist/ui/conversation.js +398 -0
  91. package/dist/ui/interrupt.js +35 -0
  92. package/dist/ui/live.js +18 -1
  93. package/dist/ui/markdown.js +63 -9
  94. package/dist/ui/message.js +14 -31
  95. package/dist/ui/screen-prompt.js +181 -0
  96. package/dist/ui/screen.js +289 -0
  97. package/dist/ui/select.js +193 -29
  98. package/dist/ui/sia-qa.js +213 -0
  99. package/dist/ui/text-prompt.js +74 -0
  100. package/dist/ui/theme.js +17 -0
  101. package/dist/ui/trust.js +93 -0
  102. package/dist/ui/ui.js +4 -1
  103. package/package.json +17 -6
  104. package/dist/ui/activity.js +0 -77
@@ -1,47 +1,112 @@
1
1
  import { ApiError } from "../services/api.js";
2
2
  import { errorLine, heading, info, line } from "../services/output.js";
3
+ import { resolveSession, SessionRefError } from "../services/session-resolver.js";
4
+ import { parseSiaContext } from "../services/sia.js";
3
5
  import { withSpinner } from "../services/spinner.js";
4
6
  import { c } from "../ui/colors.js";
7
+ import { memoryMarkerLine } from "../ui/chat-renderer.js";
5
8
  import { renderMarkdown } from "../ui/markdown.js";
9
+ import { emptyState } from "../ui/ui.js";
10
+ import { isMemoryMarker } from "../types/index.js";
11
+ import { reportRefError } from "./sessions.js";
6
12
  /**
7
- * `cos history [session]` — print the full transcript of a session
8
- * (defaults to the active one) via GET /v1/sessions/:id/messages.
13
+ * `cos history [n|id]` — print a session transcript via
14
+ * GET /v1/sessions/:id/messages. The argument is a number from the last
15
+ * `cos sessions` listing or a raw session id; with neither, the active session.
9
16
  */
10
17
  export function registerHistory(program, ctx) {
11
18
  program
12
19
  .command("history")
13
20
  .description("Show the transcript of a session")
14
- .argument("[session]", "session id (defaults to the active session)")
15
- .action(async (sessionArg) => {
21
+ .argument("[ref]", "session number from `cos sessions`, or a session id")
22
+ .action(async (ref) => {
16
23
  const client = ctx.requireAuth();
17
- const sessionId = sessionArg ?? ctx.config.get("sessionId");
18
- if (!sessionId) {
19
- info("No active session. Pass a session id, or start one with `cos chat`.");
24
+ await showHistory(ctx, client, ref);
25
+ });
26
+ }
27
+ /** Shared by the standalone command and the shell's /history. */
28
+ export async function showHistory(ctx, client, ref) {
29
+ let sessionId;
30
+ let title;
31
+ if (ref && ref.trim()) {
32
+ try {
33
+ const s = await resolveSession(ctx, client, ref);
34
+ sessionId = s.session_id;
35
+ title = s.title;
36
+ }
37
+ catch (err) {
38
+ reportRefError(err);
20
39
  return;
21
40
  }
22
- try {
23
- const { messages } = await withSpinner("Loading transcript…", () => client.sessionMessages(sessionId));
24
- if (messages.length === 0) {
25
- info("This session has no messages yet.");
26
- return;
41
+ }
42
+ else {
43
+ const active = ctx.config.get("sessionId");
44
+ if (!active) {
45
+ info("No active session. Pass a session number, or start one by typing a message.");
46
+ return;
47
+ }
48
+ sessionId = active;
49
+ title = ctx.config.get("sessionTitle");
50
+ }
51
+ try {
52
+ const { messages } = await withSpinner("Loading transcript…", () => client.sessionMessages(sessionId));
53
+ if (messages.length === 0) {
54
+ for (const l of emptyState("This conversation has no messages yet.", "Type a message to start it.")) {
55
+ line(l);
27
56
  }
28
- heading(`Transcript · ${sessionId.slice(0, 8)}`);
29
- for (const m of messages) {
30
- const who = m.role === "user" ? c.title("You") : c.brand.bold("Carrier");
31
- line("\n " + who + "\n");
32
- if (m.role === "assistant") {
33
- for (const l of renderMarkdown(m.content))
34
- line(" " + l);
57
+ return;
58
+ }
59
+ heading(`Transcript · ${title ?? sessionId.slice(0, 8)}`);
60
+ // Markers are numbered in the order they appear so `/memory <n>` can open
61
+ // one straight from the transcript — the terminal equivalent of clicking
62
+ // the divider on the web.
63
+ let markerIndex = 0;
64
+ for (const m of messages) {
65
+ if (isMemoryMarker(m)) {
66
+ markerIndex += 1;
67
+ line();
68
+ line(memoryMarkerLine({ ...m, index: markerIndex }));
69
+ continue;
70
+ }
71
+ const who = m.role === "user" ? c.title("You") : c.brand.bold("Carrier");
72
+ line("\n " + who + "\n");
73
+ if (m.role === "assistant") {
74
+ for (const l of renderMarkdown(m.content))
75
+ line(" " + l);
76
+ }
77
+ else {
78
+ // A prompt that went through SIA — here or on the website — carries an
79
+ // appended [Clarification Context] block. Show the answers as their own
80
+ // lines rather than dumping the raw marker into the transcript.
81
+ const sia = parseSiaContext(m.content);
82
+ if (sia) {
83
+ line(" " + sia.displayPrompt);
84
+ for (const item of sia.items) {
85
+ line(" " + c.dim("↳ " + item.label + ": ") + c.value(item.value));
86
+ }
35
87
  }
36
88
  else {
37
89
  line(" " + m.content);
38
90
  }
39
91
  }
92
+ }
93
+ line();
94
+ if (markerIndex > 0) {
95
+ // Cyan, matching the command it names — the whole line is one affordance,
96
+ // so splitting it dim/cyan made the sentence read as two things.
97
+ line(" " + c.accent("Open a memory artifact with ") + c.cmd("/memory <n>"));
40
98
  line();
41
99
  }
42
- catch (err) {
43
- errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
44
- process.exitCode = 1;
100
+ // Remember what the numbers point at, so /memory resolves them in a later
101
+ // process the same way session ordinals already do.
102
+ ctx.config.set("memoryArtifactIds", messages.filter(isMemoryMarker).map((m) => m.artifact_id ?? ""));
103
+ }
104
+ catch (err) {
105
+ if (err instanceof SessionRefError) {
106
+ reportRefError(err);
107
+ return;
45
108
  }
46
- });
109
+ errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
110
+ process.exitCode = 1;
111
+ }
47
112
  }
@@ -1,58 +1,61 @@
1
- import { password } from "@inquirer/prompts";
2
- import { ApiError } from "../services/api.js";
3
- import { DEFAULT_API_URL } from "../services/config.js";
4
- import { verifyAndSaveKey } from "../services/login-flow.js";
5
- import { errorLine, info, kv, line, success, warn } from "../services/output.js";
6
- import { withSpinner } from "../services/spinner.js";
1
+ import { DEFAULT_API_URL, isSafeUrl } from "../services/config.js";
2
+ import { deviceLogin, renderLoginFailure } from "../services/login-flow.js";
3
+ import { errorLine, info, line } from "../services/output.js";
7
4
  /**
8
- * `cos login [key]` — API-key login (no browser OAuth in this POC).
9
- * Validates the key via POST /v1/auth/verify and, on success, stores ONLY the
10
- * secret key (never a JWT) plus a cached copy of its scope.
5
+ * `cos login` — browser-based sign-in via the OAuth 2.0 Device Authorization
6
+ * flow (like Claude Code / GitHub CLI). Opens your Carrier OS account in the
7
+ * browser, you approve this device, and the CLI stores the issued session. No
8
+ * API key to paste, and no separate developer-platform login — it is the same
9
+ * account you use on carrieros.ai.
10
+ *
11
+ * `--platform` keeps its name for existing scripts; it overrides the site that
12
+ * opens, which is now the main Carrier OS site rather than the developer
13
+ * platform.
11
14
  */
12
15
  export function registerLogin(program, ctx) {
13
16
  program
14
17
  .command("login")
15
- .description("Log in with a Carrier API secret key")
16
- .argument("[key]", "carrier_sk_… secret key (prompted if omitted)")
18
+ .description("Sign in through your browser (device authorization)")
17
19
  .option("--url <url>", "override the API base URL (e.g. http://localhost:5000/v1)")
18
- .action(async (keyArg, opts) => {
20
+ .option("--platform <url>", "override the site that opens for the browser step (e.g. http://localhost:3000)")
21
+ .action(async (opts) => {
22
+ // Reject plain-HTTP remote overrides: the CLI sends bearer + refresh tokens
23
+ // to this host, so a non-HTTPS non-loopback URL would leak credentials in
24
+ // cleartext (or to an attacker-supplied host). Loopback http is allowed for
25
+ // local dev.
26
+ for (const [flag, val] of [
27
+ ["--url", opts.url],
28
+ ["--platform", opts.platform]
29
+ ]) {
30
+ if (val && !isSafeUrl(val)) {
31
+ errorLine(`${flag} must be an https:// URL (or http://localhost for local dev). Refusing to send credentials to ${val}.`);
32
+ process.exitCode = 1;
33
+ return;
34
+ }
35
+ }
19
36
  if (opts.url)
20
37
  ctx.config.set("apiUrl", opts.url.replace(/\/+$/, ""));
38
+ if (opts.platform)
39
+ ctx.config.set("platformUrl", opts.platform.replace(/\/+$/, ""));
21
40
  const apiUrl = ctx.config.get("apiUrl") ?? DEFAULT_API_URL;
22
- const key = keyArg?.trim() ||
23
- (await password({
24
- message: "Paste your Carrier API secret key:",
25
- mask: "•",
26
- validate: (v) => (v.trim().length > 0 ? true : "A key is required.")
27
- })).trim();
28
- if (!key.startsWith("carrier_sk_")) {
29
- warn("That does not look like a secret key (expected a carrier_sk_… value).");
41
+ if (ctx.config.isAuthenticated) {
42
+ info("You are already logged in. Run `cos logout` first to switch accounts.");
43
+ return;
30
44
  }
31
45
  try {
32
- const scope = await withSpinner("Verifying key…", () => verifyAndSaveKey(ctx, apiUrl, key));
33
- success("Logged in.");
34
- line();
35
- kv("Workspace", scope.workspace.name);
36
- kv("Project", scope.project.name);
37
- kv("Key", `${scope.apiKey.name} (${scope.apiKey.type})`);
38
- if (scope.user)
39
- kv("Account", scope.user.email);
46
+ await deviceLogin(ctx, apiUrl);
40
47
  line();
41
- info("Try `cos chat` to start talking, or `cos doctor` to check your setup.");
48
+ // Only useful when logging in from a plain terminal. Inside the shell
49
+ // the user is already where this would send them, so it reads as the
50
+ // CLI not knowing where you are.
51
+ if (!ctx.inShell) {
52
+ info("Run `cos` to open the shell, or `cos chat` to start talking.");
53
+ }
42
54
  }
43
55
  catch (err) {
44
- if (err instanceof ApiError) {
45
- errorLine(`Login failed: ${err.message} (${err.code})`);
46
- // A 404 or connection error almost always means the endpoint is wrong
47
- // (e.g. still pointed at production while the API runs locally).
48
- if (err.code === "NETWORK_ERROR" || err.code.startsWith("HTTP_")) {
49
- warn(`Endpoint: ${apiUrl}`);
50
- info("For local development, run: cos login --url http://localhost:5000/v1");
51
- }
52
- }
53
- else {
54
- errorLine(`Login failed: ${err.message}`);
55
- }
56
+ const kind = renderLoginFailure(err, apiUrl);
57
+ if (kind === "denied")
58
+ line(" " + "Run `cos login` to retry.");
56
59
  process.exitCode = 1;
57
60
  }
58
61
  });
@@ -1,15 +1,24 @@
1
+ import { DEFAULT_API_URL } from "../services/config.js";
2
+ import { logoutCliSession } from "../services/device-auth.js";
1
3
  import { info, success } from "../services/output.js";
2
- /** `cos logout` — forget the stored key, session and cached scope. */
4
+ import { withSpinner } from "../services/spinner.js";
5
+ /** `cos logout` — revoke the session server-side, then forget it locally. */
3
6
  export function registerLogout(program, ctx) {
4
7
  program
5
8
  .command("logout")
6
- .description("Remove the stored API key and session")
7
- .action(() => {
9
+ .description("Sign out and revoke this device's session")
10
+ .action(async () => {
8
11
  if (!ctx.config.isAuthenticated) {
9
12
  info("You are already logged out.");
10
13
  return;
11
14
  }
15
+ const apiUrl = ctx.config.get("apiUrl") ?? DEFAULT_API_URL;
16
+ const refreshToken = ctx.config.get("auth")?.refreshToken;
17
+ if (refreshToken) {
18
+ // Best-effort server revoke so the refresh token can't be reused.
19
+ await withSpinner("Signing out…", () => logoutCliSession(apiUrl, refreshToken));
20
+ }
12
21
  ctx.config.clearAuth();
13
- success("Logged out. Your API key has been removed from this machine.");
22
+ success("Logged out. This device's session has been removed.");
14
23
  });
15
24
  }
@@ -0,0 +1,162 @@
1
+ import { ApiError } from "../services/api.js";
2
+ import { errorLine, heading, info, line, timeAgo } from "../services/output.js";
3
+ import { withSpinner } from "../services/spinner.js";
4
+ import { c } from "../ui/colors.js";
5
+ import { memoryMarkerLine } from "../ui/chat-renderer.js";
6
+ import { renderMarkdown } from "../ui/markdown.js";
7
+ import { emptyState, sectionHeader } from "../ui/ui.js";
8
+ import { isMemoryMarker } from "../types/index.js";
9
+ /**
10
+ * `cos memory` — what the engine has compressed in this conversation.
11
+ *
12
+ * Snapshots and restructures happen automatically as a chat grows; a
13
+ * restructure is billed to the account. The web shows both inline and lets you
14
+ * click through to the artifact. This is that, for a terminal: a numbered list,
15
+ * and `memory <n>` to read one in full.
16
+ *
17
+ * There is deliberately no "compact now" — no backend capability exists to
18
+ * trigger either subsystem on demand, and a client-side summary would never
19
+ * reach the engine's context.
20
+ */
21
+ export function registerMemory(program, ctx) {
22
+ program
23
+ .command("memory")
24
+ .description("Memory snapshots and restructures for the active conversation")
25
+ .argument("[n]", "artifact number from the list; omit to list them")
26
+ .action(async (n) => {
27
+ const client = ctx.requireAuth();
28
+ if (n && n.trim())
29
+ await showArtifact(ctx, client, n.trim());
30
+ else
31
+ await listMemory(ctx, client);
32
+ });
33
+ }
34
+ /** Markers for the active conversation, numbered, newest last. */
35
+ async function loadMarkers(ctx, client) {
36
+ const sessionId = ctx.config.get("sessionId");
37
+ if (!sessionId) {
38
+ info("No active conversation. Start one, or switch with /sessions.");
39
+ return null;
40
+ }
41
+ const { messages } = await withSpinner("Loading…", () => client.sessionMessages(sessionId));
42
+ const markers = messages.filter(isMemoryMarker);
43
+ // Cache the ids so `/memory <n>` resolves in a later process, the same way
44
+ // session ordinals do.
45
+ ctx.config.set("memoryArtifactIds", markers.map((m) => m.artifact_id ?? ""));
46
+ return markers;
47
+ }
48
+ /** `/memory` — the numbered list. */
49
+ export async function listMemory(ctx, client) {
50
+ let markers;
51
+ try {
52
+ markers = await loadMarkers(ctx, client);
53
+ }
54
+ catch (err) {
55
+ reportError(err);
56
+ return;
57
+ }
58
+ if (!markers)
59
+ return;
60
+ if (markers.length === 0) {
61
+ for (const l of emptyState("Nothing compressed yet.", "Snapshots start once the conversation grows; restructures are Carrier-chat only.")) {
62
+ line(l);
63
+ }
64
+ return;
65
+ }
66
+ const snapshots = markers.filter((m) => m.kind === "snapshot").length;
67
+ const restructures = markers.length - snapshots;
68
+ const cost = markers.reduce((sum, m) => sum + (m.cost_usd ?? 0), 0);
69
+ line();
70
+ line(sectionHeader(`Memory · ${snapshots} snapshot${snapshots === 1 ? "" : "s"}, ${restructures} restructure${restructures === 1 ? "" : "s"}`));
71
+ line();
72
+ markers.forEach((m, i) => {
73
+ const num = c.dim(`${String(i + 1).padStart(String(markers.length).length)}.`);
74
+ const kind = m.kind === "restructure" ? c.brand("restructure") : c.value("snapshot");
75
+ const label = `${kind} ${c.dim(m.kind === "restructure" ? `v${m.number}` : `${m.number}`)}`;
76
+ const size = m.tokens ? c.dim(`${m.tokens.toLocaleString()} tok`) : c.dim("—");
77
+ const from = m.window_tokens ? c.dim(` from ${m.window_tokens.toLocaleString()}`) : "";
78
+ const when = m.created_at ? c.dim(` · ${timeAgo(m.created_at)}`) : "";
79
+ const flag = m.failed ? " " + c.warn("failed") : "";
80
+ line(` ${num} ${label} ${size}${from}${when}${flag}`);
81
+ });
82
+ line();
83
+ // Cost is the reason this list matters: restructures bill the account, and
84
+ // until now nothing in the CLI ever said so.
85
+ if (cost > 0) {
86
+ line(" " + c.dim(`Generated on your account · $${cost.toFixed(4)} total`));
87
+ }
88
+ line(" " + c.dim("Read one with ") + c.cmd("/memory <n>"));
89
+ line();
90
+ }
91
+ /** `/memory <n>` — the full artifact. */
92
+ export async function showArtifact(ctx, client, ref) {
93
+ const ids = ctx.config.get("memoryArtifactIds") ?? [];
94
+ const n = Number.parseInt(ref, 10);
95
+ let id;
96
+ if (Number.isInteger(n) && n >= 1) {
97
+ // Refresh if nothing is cached — the list may have been built in another
98
+ // process, or not at all.
99
+ if (ids.length === 0) {
100
+ const markers = await loadMarkers(ctx, client).catch(() => null);
101
+ id = markers?.[n - 1]?.artifact_id ?? undefined;
102
+ }
103
+ else {
104
+ id = ids[n - 1];
105
+ }
106
+ if (!id) {
107
+ errorLine(`No memory artifact ${n}.`);
108
+ line(" " + c.dim("Run ") + c.cmd("/memory") + c.dim(" to see the list."));
109
+ return;
110
+ }
111
+ }
112
+ else {
113
+ id = ref; // a raw artifact id, for scripting
114
+ }
115
+ try {
116
+ const a = await withSpinner("Loading…", () => client.memoryArtifact(id));
117
+ const title = a.kind === "restructure" ? `Restructured chat context · v${a.number}` : `Chat memory snapshot ${a.number}`;
118
+ heading(title);
119
+ line();
120
+ for (const l of renderMarkdown(a.content))
121
+ line(" " + l);
122
+ line();
123
+ // Footer mirrors the web's: what produced it, and what it cost.
124
+ const bits = [
125
+ a.window.tokens ? `${a.window.tokens.toLocaleString()} tok compressed` : null,
126
+ a.total_tokens ? `${a.total_tokens.toLocaleString()} tok used` : null,
127
+ a.model,
128
+ a.cost_usd ? `$${a.cost_usd.toFixed(4)}` : null,
129
+ a.created_at ? timeAgo(a.created_at) : null
130
+ ].filter(Boolean);
131
+ line(" " + c.dim(bits.join(" · ")));
132
+ line();
133
+ }
134
+ catch (err) {
135
+ reportError(err);
136
+ }
137
+ }
138
+ function reportError(err) {
139
+ if (err instanceof ApiError) {
140
+ errorLine(err.message);
141
+ if (err.code === "NOT_FOUND") {
142
+ line(" " + c.dim("Run ") + c.cmd("/memory") + c.dim(" to refresh the list."));
143
+ }
144
+ return;
145
+ }
146
+ errorLine(err.message);
147
+ }
148
+ /** Compact marker line reused by /context. */
149
+ export function memorySummaryLine(markers) {
150
+ if (markers.length === 0)
151
+ return null;
152
+ const snapshots = markers.filter((m) => m.kind === "snapshot").length;
153
+ const restructures = markers.length - snapshots;
154
+ const parts = [];
155
+ if (snapshots)
156
+ parts.push(`${snapshots} snapshot${snapshots === 1 ? "" : "s"}`);
157
+ if (restructures)
158
+ parts.push(`${restructures} restructure${restructures === 1 ? "" : "s"}`);
159
+ return parts.join(" · ");
160
+ }
161
+ // Re-exported so the transcript and this command draw markers identically.
162
+ export { memoryMarkerLine };
@@ -1,12 +1,18 @@
1
- import { setMode, setModel } from "../shell/shell-chat.js";
1
+ import { setFast, setHighPower, setMode, setModel, setSia, setWebSearch } from "../shell/shell-chat.js";
2
2
  /**
3
- * Standalone `mode`/`model` setters that mirror the shell's /mode and /model.
4
- * They reuse the SAME shared helpers, so behavior is identical everywhere:
3
+ * Standalone `mode`/`model`/`websearch` setters that mirror the shell's /mode,
4
+ * /model and /websearch. They reuse the SAME shared helpers, so behavior is
5
+ * identical everywhere:
5
6
  * cos mode → list Carrier modes (active marked)
6
7
  * cos mode code → set the default mode
7
8
  * cos model → list provider models
8
9
  * cos model gpt-5.5 → set the model override
9
10
  * cos model auto → clear the override (use the mode default)
11
+ * cos websearch → show the current web-search setting
12
+ * cos websearch off → turn live web search off for future turns
13
+ *
14
+ * Outside the shell there is no "next message" to arm, so a bare `cos websearch`
15
+ * shows status rather than arming — the shell's /websearch owns that.
10
16
  */
11
17
  export function registerModeModel(program, ctx) {
12
18
  program
@@ -25,4 +31,34 @@ export function registerModeModel(program, ctx) {
25
31
  const client = ctx.requireAuth();
26
32
  await setModel(ctx, client, id ?? "");
27
33
  });
34
+ // No auth needed — these only write local config; the server enforces the
35
+ // workspace's own toggles on the next chat turn regardless of what's set here.
36
+ program
37
+ .command("websearch")
38
+ .description("Show or set live web search for chat turns")
39
+ .argument("[state]", "on, off, or auto (follow your workspace); omit to show")
40
+ .action((state) => {
41
+ setWebSearch(ctx, state ?? "status");
42
+ });
43
+ program
44
+ .command("fast")
45
+ .description("Toggle fast mode (shorter pipeline, quicker replies)")
46
+ .argument("[state]", "on or off; omit to toggle")
47
+ .action((state) => {
48
+ setFast(ctx, state ?? "");
49
+ });
50
+ program
51
+ .command("hipwr")
52
+ .description("Toggle High Power — the 4-pass refinement pipeline")
53
+ .argument("[state]", "on or off; omit to toggle")
54
+ .action((state) => {
55
+ setHighPower(ctx, state ?? "");
56
+ });
57
+ program
58
+ .command("sia")
59
+ .description("SIA — clarifying questions before an ambiguous prompt is sent")
60
+ .argument("[mode]", "auto, off, or status; omit to choose")
61
+ .action(async (mode) => {
62
+ await setSia(ctx, mode ?? "status");
63
+ });
28
64
  }
@@ -14,10 +14,13 @@ export function registerModes(program, ctx) {
14
14
  const client = ctx.requireAuth();
15
15
  const modes = await withSpinner("Loading modes…", () => client.models());
16
16
  const active = ctx.mode;
17
+ // Show the default mode as "General" (its API name "Carrier OS" is the
18
+ // Carrier-chat brand, but here it's just one mode among the others).
19
+ const display = (m) => m.id === "general" ? "General" : capitalize(m.name);
17
20
  heading(`Carrier modes (${modes.length})`);
18
21
  for (const m of modes) {
19
22
  const marker = m.id === active ? chalk.green("►") : " ";
20
- const name = m.id === active ? chalk.bold(capitalize(m.name)) : capitalize(m.name);
23
+ const name = m.id === active ? chalk.bold(display(m)) : display(m);
21
24
  line(` ${marker} ${name.padEnd(12)} ${chalk.dim(m.description)}`);
22
25
  }
23
26
  line();
@@ -0,0 +1,106 @@
1
+ import { errorLine, line } from "../services/output.js";
2
+ import { formatSize } from "../services/local-files.js";
3
+ import { LOCAL_TOOL_NAMES } from "../services/local-tools.js";
4
+ import { instructionStatus, refreshProjectContext, renderProjectBrief } from "../services/project-context.js";
5
+ import { branchLabel, statusLabel } from "../services/workspace.js";
6
+ import { c } from "../ui/colors.js";
7
+ import { ensureWorkspaceTrust } from "../ui/trust.js";
8
+ import { resolveRepository } from "../services/workspace-registry.js";
9
+ import { sectionHeader } from "../ui/ui.js";
10
+ /**
11
+ * `cos context project` — what Carrier OS can be told about this repository.
12
+ *
13
+ * Reached through `context` rather than a `project` command of its own, because
14
+ * `cos project` already means something else entirely: the Carrier OS developer
15
+ * project that a CLI session is scoped to. Two unrelated things called "project"
16
+ * one keystroke apart would be a genuinely bad thing to ship, and this one is a
17
+ * kind of context, so it belongs where the other context lives.
18
+ *
19
+ * Looking sends nothing. `attach` arms the brief for the next message.
20
+ */
21
+ export async function runProject(ctx, action, preview = false, repository) {
22
+ // The brief describes one repository: the named one when asked, otherwise the
23
+ // active one. Trust is checked for THAT repository, not for the folder above.
24
+ let handle;
25
+ try {
26
+ handle = resolveRepository(repository);
27
+ }
28
+ catch (err) {
29
+ errorLine(err.message);
30
+ return;
31
+ }
32
+ if (!(await ensureWorkspaceTrust(ctx.config, handle.root)))
33
+ return;
34
+ const verb = (action ?? "").trim().toLowerCase();
35
+ if (verb === "detach" || verb === "off") {
36
+ ctx.config.set("projectContextPending", false);
37
+ line();
38
+ line(" " + c.dim("Project context will not be attached."));
39
+ line();
40
+ return;
41
+ }
42
+ const pc = refreshProjectContext(handle);
43
+ if (verb === "attach" || verb === "on") {
44
+ ctx.config.set("projectContextPending", true);
45
+ line();
46
+ line(" " +
47
+ c.accent("✓") +
48
+ " " +
49
+ c.dim("Project context will be attached to your next message."));
50
+ line(" " + c.dim("It describes the project — file names, not file contents."));
51
+ line();
52
+ return;
53
+ }
54
+ if (preview) {
55
+ line();
56
+ line(sectionHeader("Project context (exact text)"));
57
+ for (const l of renderProjectBrief(pc).split("\n"))
58
+ line(" " + c.dim(l));
59
+ line();
60
+ return;
61
+ }
62
+ render(ctx, pc);
63
+ }
64
+ function render(ctx, pc) {
65
+ const t = pc.treeSummary;
66
+ const repo = pc.repository;
67
+ line();
68
+ line(sectionHeader("Project"));
69
+ row("Repository", pc.repositoryName);
70
+ row("Name", pc.project.name);
71
+ row("Type", pc.project.label);
72
+ row("Repository", repo.state === "detected"
73
+ ? `Git · ${branchLabel(repo) ?? "unknown"}${statusLabel(repo) ? ` · ${statusLabel(repo)}` : ""}`
74
+ : "Not detected");
75
+ row("Root", pc.root);
76
+ row("Files", t.truncated ? `${t.files.length} mapped of ${t.totalFiles}` : String(t.totalFiles));
77
+ if (t.topLevelDirectories.length) {
78
+ row("Structure", t.topLevelDirectories.slice(0, 8).join(", "));
79
+ }
80
+ row("Map size", formatSize(t.files.reduce((n, f) => n + f.size, 0)));
81
+ line();
82
+ line(sectionHeader("Instructions"));
83
+ for (const i of instructionStatus(pc)) {
84
+ row(i.name, i.found ? c.accent("found") : c.dim("—"));
85
+ }
86
+ if (pc.instructions.length) {
87
+ line(" " +
88
+ c.dim("Supplied as untrusted repository data — never as system instructions."));
89
+ }
90
+ line();
91
+ line(sectionHeader("Local tools"));
92
+ row("Available", LOCAL_TOOL_NAMES.join(" · "));
93
+ row("Boundary", pc.root);
94
+ line(" " + c.dim("Read-only. No write, delete or command execution exists."));
95
+ line();
96
+ const pending = ctx.config.get("projectContextPending") === true;
97
+ line(" " +
98
+ (pending
99
+ ? c.accent("Attached") + c.dim(" to your next message.")
100
+ : c.dim("Not attached. ") + c.cmd("/context project --attach") + c.dim(" to include it.")));
101
+ line();
102
+ }
103
+ const LABEL_W = 12;
104
+ function row(label, value) {
105
+ line(" " + c.dim(label.padEnd(LABEL_W)) + value);
106
+ }