@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,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 };
@@ -0,0 +1,64 @@
1
+ import { setFast, setHighPower, setMode, setModel, setSia, setWebSearch } from "../shell/shell-chat.js";
2
+ /**
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:
6
+ * cos mode → list Carrier modes (active marked)
7
+ * cos mode code → set the default mode
8
+ * cos model → list provider models
9
+ * cos model gpt-5.5 → set the model override
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.
16
+ */
17
+ export function registerModeModel(program, ctx) {
18
+ program
19
+ .command("mode")
20
+ .description("Show or set the default Carrier mode")
21
+ .argument("[id]", "mode id (e.g. code); omit to list")
22
+ .action(async (id) => {
23
+ const client = ctx.requireAuth();
24
+ await setMode(ctx, client, id ?? "");
25
+ });
26
+ program
27
+ .command("model")
28
+ .description("Show or set the provider model override")
29
+ .argument("[id]", "model id (e.g. gpt-5.5) or 'auto'; omit to list")
30
+ .action(async (id) => {
31
+ const client = ctx.requireAuth();
32
+ await setModel(ctx, client, id ?? "");
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
+ });
64
+ }
@@ -0,0 +1,28 @@
1
+ import chalk from "chalk";
2
+ import { heading, line } from "../services/output.js";
3
+ import { withSpinner } from "../services/spinner.js";
4
+ /**
5
+ * `cos models` — list the provider models a developer may request via the
6
+ * chat `model` override (GET /v1/models/chat). See `cos modes` for the
7
+ * Carrier behavior modes.
8
+ */
9
+ export function registerModels(program, ctx) {
10
+ program
11
+ .command("models")
12
+ .description("List provider models available for the chat model override")
13
+ .action(async () => {
14
+ const client = ctx.requireAuth();
15
+ const models = await withSpinner("Loading models…", () => client.chatModels());
16
+ const active = ctx.config.get("model") ?? "";
17
+ heading(`Provider models (${models.length})`);
18
+ line(` ${active === "" ? chalk.green("►") : " "} ${chalk.bold("Auto (mode default)")}`);
19
+ for (const m of models) {
20
+ const on = m.id === active;
21
+ const label = on ? chalk.bold(m.label) : m.label;
22
+ line(` ${on ? chalk.green("►") : " "} ${label.padEnd(28)} ${chalk.dim(m.id)}`);
23
+ }
24
+ line();
25
+ line(chalk.dim(" Use one with `cos chat --model <id>`, or /model in chat."));
26
+ line();
27
+ });
28
+ }
@@ -0,0 +1,30 @@
1
+ import chalk from "chalk";
2
+ import { capitalize, heading, line } from "../services/output.js";
3
+ import { withSpinner } from "../services/spinner.js";
4
+ /**
5
+ * `cos modes` — list the Carrier behavior modes from GET /v1/models
6
+ * (general, reasoning, code, research, …). Each mode maps to a default provider
7
+ * model server-side; use `cos models` to see/override the provider model.
8
+ */
9
+ export function registerModes(program, ctx) {
10
+ program
11
+ .command("modes")
12
+ .description("List Carrier modes (behavior presets)")
13
+ .action(async () => {
14
+ const client = ctx.requireAuth();
15
+ const modes = await withSpinner("Loading modes…", () => client.models());
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);
20
+ heading(`Carrier modes (${modes.length})`);
21
+ for (const m of modes) {
22
+ const marker = m.id === active ? chalk.green("►") : " ";
23
+ const name = m.id === active ? chalk.bold(display(m)) : display(m);
24
+ line(` ${marker} ${name.padEnd(12)} ${chalk.dim(m.description)}`);
25
+ }
26
+ line();
27
+ line(chalk.dim(" Set a default with `cos chat --mode <id>`, or /mode in chat."));
28
+ line();
29
+ });
30
+ }
@@ -0,0 +1,78 @@
1
+ import { ApiError } from "../services/api.js";
2
+ import { errorLine, info, line, success } from "../services/output.js";
3
+ import { PERMISSION_MODES, getPermissionMode, parsePermissionMode, permissionModeExplanation, permissionModeLabel, setPermissionMode } from "../services/permission-mode.js";
4
+ import { withSpinner } from "../services/spinner.js";
5
+ import { c } from "../ui/colors.js";
6
+ import { pickFromList } from "../ui/select.js";
7
+ /** "Permission mode changed: Accept Edits" plus what it means. */
8
+ function confirm(mode) {
9
+ success(`Permission mode changed: ${permissionModeLabel(mode)}`);
10
+ line(" " + c.dim(permissionModeExplanation(mode)));
11
+ }
12
+ /**
13
+ * `/permissions` (and `/mode manual|plan|accept-edits`, `/plan`): show or set
14
+ * the session's permission mode. Bare in a terminal opens the picker; piped, it
15
+ * prints the current mode. Applies from the next message.
16
+ */
17
+ export async function runPermissions(ctx, arg) {
18
+ const current = getPermissionMode(ctx.config);
19
+ if (arg.trim()) {
20
+ const mode = parsePermissionMode(arg);
21
+ if (!mode) {
22
+ errorLine(`Unknown permission mode "${arg.trim()}". Use manual, plan, accept-edits or auto.`);
23
+ return;
24
+ }
25
+ if (mode === current) {
26
+ info(`Permission mode is already ${permissionModeLabel(mode)}.`);
27
+ return;
28
+ }
29
+ setPermissionMode(ctx.config, mode);
30
+ confirm(mode);
31
+ return;
32
+ }
33
+ if (!process.stdin.isTTY) {
34
+ line(`Permission mode: ${permissionModeLabel(current)} — ${permissionModeExplanation(current)}`);
35
+ return;
36
+ }
37
+ const chosen = parsePermissionMode(await pickFromList({
38
+ title: "Permission mode",
39
+ description: "Applies from your next message. Trust, freshness, checkpoints and recovery checks always run.",
40
+ choices: PERMISSION_MODES.map((m) => ({ value: m, label: permissionModeLabel(m) + (m === current ? " (current)" : ""), description: permissionModeExplanation(m) })),
41
+ initial: PERMISSION_MODES.indexOf(current)
42
+ }));
43
+ if (chosen && chosen !== current) {
44
+ setPermissionMode(ctx.config, chosen);
45
+ confirm(chosen);
46
+ }
47
+ }
48
+ const COMPACT_REASONS = {
49
+ NOTHING_TO_COMPACT: "Nothing new to compact since the last summary.",
50
+ RESTRUCTURING_DISABLED: "Chat restructuring is turned off in your preferences, so a summary would not be used. Turn it on in Settings → Performance to compact.",
51
+ SNAPSHOTS_DISABLED: "Memory snapshots are turned off in your preferences, so a summary would not be used. Turn them on in Settings → Performance to compact.",
52
+ BUSY: "An automatic context restructure is running for this conversation. Try /compact again in a moment.",
53
+ SESSION_NOT_FOUND: "This conversation is no longer available. Run /sessions to pick another."
54
+ };
55
+ /**
56
+ * `/compact`: replace the conversation's earlier messages in the model's
57
+ * context with a bounded summary of its state. Same conversation, same task,
58
+ * same permission mode; nothing is deleted locally or on the server.
59
+ */
60
+ export async function runCompact(ctx, client) {
61
+ const sessionId = ctx.config.get("sessionId");
62
+ if (!sessionId) {
63
+ info("No active conversation to compact. Start one, or resume one with /sessions.");
64
+ return;
65
+ }
66
+ try {
67
+ const r = await withSpinner("Compacting…", () => client.compactSession(sessionId, getPermissionMode(ctx.config)));
68
+ if (!r.compacted) {
69
+ info(COMPACT_REASONS[r.reason ?? ""] ?? "Nothing was compacted.");
70
+ return;
71
+ }
72
+ success(`Compacted ${r.messages ?? 0} earlier message${r.messages === 1 ? "" : "s"} into a summary (v${r.version}).`);
73
+ line(" " + c.dim(`Kept: ${r.task_context ? "the task, plan, inspected and changed files, tests, corrections, " : ""}your requests and the permission mode. Nothing was deleted — /context shows the task.`));
74
+ }
75
+ catch (err) {
76
+ errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
77
+ }
78
+ }
@@ -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
+ }
@@ -0,0 +1,146 @@
1
+ import { heading, kv, line } from "../services/output.js";
2
+ import { discoverRootWithoutGit, branchLabel, refreshWorkspace, shortenRemoteUrl, statusLabel, subPath } from "../services/workspace.js";
3
+ import { c } from "../ui/colors.js";
4
+ import { errorLine } from "../services/output.js";
5
+ import { invalidateProjectContext } from "../services/project-context.js";
6
+ import { activeRepository, getRegistry, listRepositories, repositoryDetails, setActiveRepository } from "../services/workspace-registry.js";
7
+ import { ensureWorkspaceTrust } from "../ui/trust.js";
8
+ /**
9
+ * `cos repo` — what Carrier OS thinks it is looking at.
10
+ *
11
+ * Read-only in the strict sense: it runs `git rev-parse`, `symbolic-ref`,
12
+ * `remote` and `status`, and nothing that writes. There is deliberately no
13
+ * command here to switch branches, stage, or commit — the CLI reports on the
14
+ * repository, it does not drive it.
15
+ *
16
+ * Refreshes rather than reading the cache, because the reason someone types
17
+ * this is usually that they just changed something.
18
+ */
19
+ export function registerRepo(program, ctx) {
20
+ program
21
+ .command("repo")
22
+ .argument("[use]", 'the word "use" to switch repository')
23
+ .argument("[repository]", "repository name from this workspace")
24
+ .description("Show the active repository, or switch with: repo use <name>")
25
+ .action(async (verb, name) => {
26
+ if ((verb ?? "").toLowerCase() === "use") {
27
+ await useRepository(ctx, name);
28
+ return;
29
+ }
30
+ if (verb) {
31
+ errorLine(`Unknown argument "${verb}". Use /repo, or /repo use <repository>.`);
32
+ return;
33
+ }
34
+ // Git runs inside the folder, so the folder is trusted first — decided
35
+ // without starting Git (see discoverRootWithoutGit).
36
+ if (!(await ensureWorkspaceTrust(ctx.config, discoverRootWithoutGit())))
37
+ return;
38
+ render();
39
+ });
40
+ }
41
+ /**
42
+ * Switch the active repository.
43
+ *
44
+ * Selection goes through the registry by NAME — a path is never accepted, so
45
+ * this cannot be used to point the CLI at an arbitrary folder. The new
46
+ * repository carries its own trust: switching into one that was never trusted
47
+ * asks, exactly as opening it would have.
48
+ */
49
+ export async function useRepository(ctx, name) {
50
+ if (!name) {
51
+ errorLine("Which repository? Try /repos to see the list, then /repo use <name>.");
52
+ return;
53
+ }
54
+ let handle;
55
+ try {
56
+ handle = setActiveRepository(name);
57
+ }
58
+ catch (err) {
59
+ errorLine(err.message);
60
+ return;
61
+ }
62
+ if (!(await ensureWorkspaceTrust(ctx.config, handle.root))) {
63
+ line(" " + c.warn("!") + " " + c.dim(`${handle.name} is not trusted — local tools stay off for it.`));
64
+ }
65
+ // The brief and the descriptor both describe "the repository", and that is
66
+ // now a different one.
67
+ invalidateProjectContext();
68
+ refreshWorkspace();
69
+ const details = repositoryDetails(handle, true);
70
+ line();
71
+ line(" " + c.ok("✓") + " " + c.dim("Active repository: ") + c.value(handle.name));
72
+ line(" " + c.dim(handle.root));
73
+ if (details.branch)
74
+ line(" " + c.dim(`branch ${details.branch}`));
75
+ line();
76
+ }
77
+ export function render() {
78
+ // The one caller that displays a remote, so the one that pays for it.
79
+ const ws = refreshWorkspace({ includeRemote: true });
80
+ const repo = ws.repository;
81
+ const registry = getRegistry();
82
+ const active = activeRepository();
83
+ if (registry.workspaceRoot) {
84
+ heading("Workspace");
85
+ kv("Root", registry.workspaceRoot);
86
+ kv("Repositories", listRepositories().map((r) => r.name).join(", "));
87
+ kv("Active", active.name);
88
+ }
89
+ if (repo.state === "detected") {
90
+ heading("Repository");
91
+ kv("Root", repo.root ?? "—");
92
+ const where = subPath(ws);
93
+ // Only worth a line when they are NOT at the root, which is exactly when
94
+ // "Root" alone would be misleading about where commands will act.
95
+ if (where)
96
+ kv("You are in", where);
97
+ kv("Branch", branchLabel(repo) ?? "Unknown");
98
+ if (repo.remote) {
99
+ kv("Remote", repo.remoteUrl ? `${repo.remote} · ${shortenRemoteUrl(repo.remoteUrl)}` : repo.remote);
100
+ }
101
+ else {
102
+ kv("Remote", "Not configured");
103
+ }
104
+ // null means the status could not be taken in budget — usually a very large
105
+ // repository. Saying "Clean" there would be a guess.
106
+ kv("Status", statusLabel(repo) ?? "Unavailable");
107
+ kv("Project", ws.project.name);
108
+ kv("Type", ws.project.label);
109
+ line();
110
+ return;
111
+ }
112
+ // A multi-repository workspace: the launch folder is not itself a repository,
113
+ // so describe the ACTIVE repository rather than the folder holding them.
114
+ if (registry.mode === "workspace") {
115
+ const details = repositoryDetails(active, true);
116
+ heading("Active repository");
117
+ kv("Root", active.root);
118
+ kv("Branch", details.branch ?? "Unknown");
119
+ kv("Status", details.status
120
+ ? details.status.dirty
121
+ ? `${details.status.modified} modified · ${details.status.untracked} untracked`
122
+ : "Clean"
123
+ : "Unavailable");
124
+ kv("Type", details.projectLabel);
125
+ kv("Trust", details.trust === "trusted" ? "Trusted" : "Not trusted");
126
+ line();
127
+ return;
128
+ }
129
+ heading("Workspace");
130
+ kv("Directory", ws.cwd);
131
+ kv("Project", ws.project.name);
132
+ kv("Type", ws.project.label);
133
+ if (repo.state === "unavailable") {
134
+ kv("Git", "Repository information unavailable");
135
+ if (repo.error)
136
+ line(" " + c.dim(repo.error));
137
+ }
138
+ else if (!repo.gitAvailable) {
139
+ kv("Git", "Not detected");
140
+ line(" " + c.dim("Git was not found on your PATH."));
141
+ }
142
+ else {
143
+ kv("Git", "Not detected");
144
+ }
145
+ line();
146
+ }