@carrieros/cli 0.2.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.
- package/README.md +142 -57
- package/dist/commands/attach.js +45 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +80 -14
- package/dist/commands/context.js +160 -0
- package/dist/commands/doctor.js +46 -1
- package/dist/commands/files.js +84 -23
- package/dist/commands/help.js +1 -0
- package/dist/commands/history.js +88 -23
- package/dist/commands/login.js +31 -7
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +39 -3
- package/dist/commands/modes.js +4 -1
- package/dist/commands/project.js +106 -0
- package/dist/commands/repo.js +146 -0
- package/dist/commands/repos.js +61 -0
- package/dist/commands/review.js +92 -0
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +219 -65
- package/dist/commands/settings.js +87 -0
- package/dist/commands/update.js +159 -0
- package/dist/commands/upload.js +204 -31
- package/dist/commands/usage.js +212 -16
- package/dist/ide/editor-context.js +172 -0
- package/dist/ide/ide-session.js +94 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +26 -1
- package/dist/services/api.js +140 -6
- package/dist/services/chat-stream.js +145 -0
- package/dist/services/checkpoints.js +116 -0
- package/dist/services/client-tools.js +260 -0
- package/dist/services/command-coordinator.js +200 -0
- package/dist/services/command-policy.js +404 -0
- package/dist/services/config.js +247 -22
- package/dist/services/context.js +265 -20
- package/dist/services/device-auth.js +42 -30
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -0
- package/dist/services/file-detect.js +104 -0
- package/dist/services/file-resolver.js +199 -0
- package/dist/services/file-upload.js +126 -0
- package/dist/services/git-tools.js +248 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +64 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/job-helper.js +307 -0
- package/dist/services/local-files.js +517 -0
- package/dist/services/local-tools.js +432 -0
- package/dist/services/login-flow.js +15 -8
- package/dist/services/meta.js +3 -1
- package/dist/services/mutation-coordinator.js +161 -0
- package/dist/services/mutations.js +493 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +5 -2
- package/dist/services/packaged.js +24 -0
- package/dist/services/process-runner.js +406 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/secure-store.js +197 -0
- package/dist/services/session-resolver.js +108 -0
- package/dist/services/sia.js +51 -0
- package/dist/services/update.js +286 -0
- package/dist/services/workspace-registry.js +309 -0
- package/dist/services/workspace.js +573 -0
- package/dist/shell/shell-chat.js +1028 -57
- package/dist/shell/shell-commands.js +200 -11
- package/dist/shell/shell-prompt.js +81 -8
- package/dist/shell/shell-renderer.js +7 -19
- package/dist/shell/shell-router.js +19 -3
- package/dist/shell/shell.js +185 -17
- package/dist/types/index.js +3 -1
- package/dist/ui/approval.js +81 -0
- package/dist/ui/banner.js +39 -0
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +87 -0
- package/dist/ui/chat-renderer.js +206 -13
- package/dist/ui/colors.js +4 -0
- package/dist/ui/command-filter.js +26 -5
- package/dist/ui/command-palette.js +17 -4
- package/dist/ui/command-registry.js +84 -9
- package/dist/ui/command-review.js +138 -0
- package/dist/ui/composer-layout.js +41 -0
- package/dist/ui/conversation.js +398 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +3 -1
- package/dist/ui/markdown.js +63 -9
- package/dist/ui/message.js +14 -31
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +1 -1
- package/dist/ui/select.js +185 -29
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/trust.js +93 -0
- package/dist/ui/ui.js +4 -1
- package/package.json +13 -2
- package/dist/ui/activity.js +0 -77
package/dist/commands/login.js
CHANGED
|
@@ -1,19 +1,38 @@
|
|
|
1
|
-
import { DEFAULT_API_URL } from "../services/config.js";
|
|
1
|
+
import { DEFAULT_API_URL, isSafeUrl } from "../services/config.js";
|
|
2
2
|
import { deviceLogin, renderLoginFailure } from "../services/login-flow.js";
|
|
3
|
-
import { info, line } from "../services/output.js";
|
|
3
|
+
import { errorLine, info, line } from "../services/output.js";
|
|
4
4
|
/**
|
|
5
5
|
* `cos login` — browser-based sign-in via the OAuth 2.0 Device Authorization
|
|
6
|
-
* flow (like Claude Code / GitHub CLI). Opens
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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.
|
|
9
14
|
*/
|
|
10
15
|
export function registerLogin(program, ctx) {
|
|
11
16
|
program
|
|
12
17
|
.command("login")
|
|
13
18
|
.description("Sign in through your browser (device authorization)")
|
|
14
19
|
.option("--url <url>", "override the API base URL (e.g. http://localhost:5000/v1)")
|
|
15
|
-
.option("--platform <url>", "override the
|
|
20
|
+
.option("--platform <url>", "override the site that opens for the browser step (e.g. http://localhost:3000)")
|
|
16
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
|
+
}
|
|
17
36
|
if (opts.url)
|
|
18
37
|
ctx.config.set("apiUrl", opts.url.replace(/\/+$/, ""));
|
|
19
38
|
if (opts.platform)
|
|
@@ -26,7 +45,12 @@ export function registerLogin(program, ctx) {
|
|
|
26
45
|
try {
|
|
27
46
|
await deviceLogin(ctx, apiUrl);
|
|
28
47
|
line();
|
|
29
|
-
|
|
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
|
+
}
|
|
30
54
|
}
|
|
31
55
|
catch (err) {
|
|
32
56
|
const kind = renderLoginFailure(err, apiUrl);
|
|
@@ -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
|
|
4
|
-
* They reuse the SAME shared helpers, so behavior is
|
|
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
|
}
|
package/dist/commands/modes.js
CHANGED
|
@@ -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(
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { line } from "../services/output.js";
|
|
2
|
+
import { activeRepository, inWorkspaceMode, listRepositories, repositoryDetails, getRegistry } from "../services/workspace-registry.js";
|
|
3
|
+
import { c } from "../ui/colors.js";
|
|
4
|
+
import { sectionHeader } from "../ui/ui.js";
|
|
5
|
+
/**
|
|
6
|
+
* `cos repos` — the repositories this workspace knows about.
|
|
7
|
+
*
|
|
8
|
+
* Listing is not access: a repository appears here because it exists next to
|
|
9
|
+
* the others, and each one keeps its own trust state and its own boundary. The
|
|
10
|
+
* marker says which one commands and tools act on right now.
|
|
11
|
+
*/
|
|
12
|
+
export function registerRepos(program, _ctx) {
|
|
13
|
+
program
|
|
14
|
+
.command("repos")
|
|
15
|
+
.description("List the repositories in this workspace")
|
|
16
|
+
.action(() => {
|
|
17
|
+
showRepositories();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function statusText(handle) {
|
|
21
|
+
const d = repositoryDetails(handle);
|
|
22
|
+
const parts = [];
|
|
23
|
+
if (d.status) {
|
|
24
|
+
parts.push(d.status.dirty
|
|
25
|
+
? [d.status.modified ? `${d.status.modified} modified` : "", d.status.untracked ? `${d.status.untracked} untracked` : ""]
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
.join(" · ")
|
|
28
|
+
: "clean");
|
|
29
|
+
}
|
|
30
|
+
else if (handle.git) {
|
|
31
|
+
parts.push("status unavailable");
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
parts.push("not a Git repository");
|
|
35
|
+
}
|
|
36
|
+
if (d.trust !== "trusted")
|
|
37
|
+
parts.push("not trusted");
|
|
38
|
+
return parts.join(" · ");
|
|
39
|
+
}
|
|
40
|
+
export function showRepositories() {
|
|
41
|
+
const reg = getRegistry();
|
|
42
|
+
const active = activeRepository();
|
|
43
|
+
line(sectionHeader(inWorkspaceMode() ? "Workspace" : "Repository"));
|
|
44
|
+
if (reg.workspaceRoot)
|
|
45
|
+
line(" " + c.dim(reg.workspaceRoot));
|
|
46
|
+
line();
|
|
47
|
+
for (const handle of listRepositories()) {
|
|
48
|
+
const isActive = handle.id === active.id;
|
|
49
|
+
const marker = isActive ? c.brand("*") : " ";
|
|
50
|
+
const name = isActive ? c.title(handle.name) : c.value(handle.name);
|
|
51
|
+
line(` ${marker} ${name}`);
|
|
52
|
+
const d = repositoryDetails(handle);
|
|
53
|
+
line(" " + c.dim(`branch ${d.branch ?? "unknown"} · ${statusText(handle)}`));
|
|
54
|
+
line(" " + c.dim(handle.root));
|
|
55
|
+
line();
|
|
56
|
+
}
|
|
57
|
+
if (inWorkspaceMode()) {
|
|
58
|
+
line(" " + c.dim("Switch with ") + c.cmd("/repo use <name>") + c.dim(" — tools and commands follow the active repository."));
|
|
59
|
+
line();
|
|
60
|
+
}
|
|
61
|
+
}
|