@carrieros/cli-staging 0.0.0-stage → 0.4.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 +6 -2
- package/dist/commands/attach.js +45 -0
- package/dist/commands/auth.js +60 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +182 -0
- package/dist/commands/context.js +200 -0
- package/dist/commands/doctor.js +119 -0
- package/dist/commands/files.js +94 -0
- package/dist/commands/help.js +37 -0
- package/dist/commands/history.js +112 -0
- package/dist/commands/login.js +62 -0
- package/dist/commands/logout.js +25 -0
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +64 -0
- package/dist/commands/models.js +28 -0
- package/dist/commands/modes.js +30 -0
- package/dist/commands/permissions.js +77 -0
- 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/scope.js +155 -0
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +282 -0
- package/dist/commands/settings.js +100 -0
- package/dist/commands/update.js +229 -0
- package/dist/commands/upload.js +223 -0
- package/dist/commands/usage.js +227 -0
- package/dist/commands/version.js +26 -0
- package/dist/commands/whoami.js +44 -0
- package/dist/ide/editor-context.js +275 -0
- package/dist/ide/ide-session.js +360 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +126 -0
- package/dist/services/api.js +439 -0
- package/dist/services/auth-origin.js +20 -0
- package/dist/services/chat-stream.js +168 -0
- package/dist/services/checkpoints.js +278 -0
- package/dist/services/client-tools.js +356 -0
- package/dist/services/code-intel.js +243 -0
- package/dist/services/code-symbols.js +94 -0
- package/dist/services/coding-workflow.js +554 -0
- package/dist/services/command-coordinator.js +273 -0
- package/dist/services/command-policy.js +434 -0
- package/dist/services/config.js +383 -0
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +371 -0
- package/dist/services/device-auth.js +286 -0
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -0
- package/dist/services/execution-platform.js +30 -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/folder-key.js +22 -0
- package/dist/services/git-tools.js +429 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +85 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/instruction-resolver.js +54 -0
- package/dist/services/job-helper.js +328 -0
- package/dist/services/local-files.js +639 -0
- package/dist/services/local-tools.js +937 -0
- package/dist/services/login-flow.js +156 -0
- package/dist/services/meta.js +15 -0
- package/dist/services/mutation-coordinator.js +327 -0
- package/dist/services/mutation-groups.js +309 -0
- package/dist/services/mutation-recovery.js +159 -0
- package/dist/services/mutations.js +679 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +62 -0
- package/dist/services/packaged-update.js +403 -0
- package/dist/services/packaged.js +39 -0
- package/dist/services/permission-mode.js +78 -0
- package/dist/services/process-runner.js +412 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/result-reconciliation.js +49 -0
- package/dist/services/secure-store.js +217 -0
- package/dist/services/session-resolver.js +113 -0
- package/dist/services/sia.js +51 -0
- package/dist/services/spinner.js +40 -0
- package/dist/services/supported-runtime.js +59 -0
- package/dist/services/task-context.js +212 -0
- package/dist/services/task-snapshot.js +38 -0
- package/dist/services/tool-result-outbox.js +195 -0
- package/dist/services/update.js +311 -0
- package/dist/services/workspace-registry.js +310 -0
- package/dist/services/workspace.js +580 -0
- package/dist/shell/shell-chat.js +1619 -0
- package/dist/shell/shell-commands.js +411 -0
- package/dist/shell/shell-prompt.js +110 -0
- package/dist/shell/shell-renderer.js +51 -0
- package/dist/shell/shell-router.js +37 -0
- package/dist/shell/shell.js +389 -0
- package/dist/shell/task-context-view.js +40 -0
- package/dist/staging.js +5 -0
- package/dist/types/index.js +6 -0
- package/dist/ui/agent-cards.js +111 -0
- package/dist/ui/agent-presentation.js +131 -0
- package/dist/ui/approval.js +111 -0
- package/dist/ui/banner.js +56 -0
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +334 -0
- package/dist/ui/chat-renderer.js +463 -0
- package/dist/ui/code-block.js +52 -0
- package/dist/ui/color-picker.js +100 -0
- package/dist/ui/colors.js +55 -0
- package/dist/ui/command-details.js +11 -0
- package/dist/ui/command-filter.js +92 -0
- package/dist/ui/command-item.js +6 -0
- package/dist/ui/command-palette.js +383 -0
- package/dist/ui/command-registry.js +128 -0
- package/dist/ui/command-renderer.js +55 -0
- package/dist/ui/command-review.js +187 -0
- package/dist/ui/composer-layout.js +74 -0
- package/dist/ui/conversation.js +450 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +141 -0
- package/dist/ui/logo.js +58 -0
- package/dist/ui/markdown.js +205 -0
- package/dist/ui/message.js +21 -0
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +297 -0
- package/dist/ui/select.js +284 -0
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/spinner.js +23 -0
- package/dist/ui/sticky-stream.js +64 -0
- package/dist/ui/task-context-card.js +99 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/theme.js +80 -0
- package/dist/ui/trust.js +88 -0
- package/dist/ui/ui.js +101 -0
- package/package.json +33 -4
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { getPermissionMode, permissionModeExplanation, permissionModeLabel } from "../services/permission-mode.js";
|
|
2
|
+
import { taskSnapshot } from "../services/task-snapshot.js";
|
|
3
|
+
import { ApiError } from "../services/api.js";
|
|
4
|
+
import { errorLine, line, timeAgo } from "../services/output.js";
|
|
5
|
+
import { ordinalOf } from "../services/session-resolver.js";
|
|
6
|
+
import { memorySummaryLine } from "./memory.js";
|
|
7
|
+
import { isMemoryMarker } from "../types/index.js";
|
|
8
|
+
import { modeLabelShort, modelLabelShort, chatTypeLabel } from "../shell/shell-chat.js";
|
|
9
|
+
import { withSpinner } from "../services/spinner.js";
|
|
10
|
+
import { c } from "../ui/colors.js";
|
|
11
|
+
import { emptyState, sectionHeader } from "../ui/ui.js";
|
|
12
|
+
import { runProject } from "./project.js";
|
|
13
|
+
import { LOCAL_TOOL_NAMES } from "../services/local-tools.js";
|
|
14
|
+
import { instructionStatus, peekProjectContext, projectSummaryLine } from "../services/project-context.js";
|
|
15
|
+
/**
|
|
16
|
+
* `cos context` — what the next message will actually be sent with.
|
|
17
|
+
*
|
|
18
|
+
* DELIBERATELY PARTIAL. The web shows a token window, cognitive-health score,
|
|
19
|
+
* snapshot and anchor counts, all from `/responses/conversations/:id/token-stats`
|
|
20
|
+
* — an endpoint the public /v1 surface does not expose. Rather than estimate
|
|
21
|
+
* those numbers client-side (they would be wrong, and wrong in a way that looks
|
|
22
|
+
* authoritative), this shows only what /v1 and local config actually know, and
|
|
23
|
+
* names what is missing.
|
|
24
|
+
*/
|
|
25
|
+
export function registerContext(program, ctx) {
|
|
26
|
+
program
|
|
27
|
+
.command("context")
|
|
28
|
+
.argument("[what]", 'omit for the conversation, or "project" for the local repository')
|
|
29
|
+
.option("--preview", "with project: print the exact text that would be attached")
|
|
30
|
+
.option("--attach", "with project: attach the brief to the next message")
|
|
31
|
+
.option("--detach", "with project: stop attaching it")
|
|
32
|
+
.option("--repo <repository>", "with project: describe a named repository from this workspace")
|
|
33
|
+
.description("Show what the next message will be sent with")
|
|
34
|
+
.action(async (what, options) => {
|
|
35
|
+
if ((what ?? "").trim().toLowerCase() === "project") {
|
|
36
|
+
const action = options.attach ? "attach" : options.detach ? "detach" : undefined;
|
|
37
|
+
await runProject(ctx, action, Boolean(options.preview), options.repo);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const client = ctx.requireAuth();
|
|
41
|
+
await showContext(ctx, client);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const LABEL_W = 11;
|
|
45
|
+
function row(label, value) {
|
|
46
|
+
line(" " + c.dim(label.padEnd(LABEL_W)) + value);
|
|
47
|
+
}
|
|
48
|
+
/** Shared by the standalone command and the shell's /context. */
|
|
49
|
+
export async function showContext(ctx, client) {
|
|
50
|
+
const sessionId = ctx.config.get("sessionId");
|
|
51
|
+
line();
|
|
52
|
+
line(sectionHeader("Context"));
|
|
53
|
+
// ── The conversation ──────────────────────────────────────────────────────
|
|
54
|
+
if (!sessionId) {
|
|
55
|
+
line();
|
|
56
|
+
line(" " + c.dim("No active conversation — your next message starts one."));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
let title = ctx.config.get("sessionTitle");
|
|
60
|
+
let messages = null;
|
|
61
|
+
let started = null;
|
|
62
|
+
try {
|
|
63
|
+
const s = await withSpinner("Loading…", () => client.session(sessionId));
|
|
64
|
+
title = s.title;
|
|
65
|
+
messages = s.message_count;
|
|
66
|
+
started = s.created_at;
|
|
67
|
+
// Keep the footer's cached title honest while we're here.
|
|
68
|
+
if (s.title)
|
|
69
|
+
ctx.config.set("sessionTitle", s.title);
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
// A dead session shouldn't blank the whole view — show what's cached and
|
|
73
|
+
// say the rest couldn't be read.
|
|
74
|
+
if (err instanceof ApiError && err.status === 404) {
|
|
75
|
+
line();
|
|
76
|
+
line(" " + c.warn("!") + c.dim(" The active conversation is no longer available."));
|
|
77
|
+
line(" " + c.dim("Run ") + c.cmd("/sessions") + c.dim(" to pick another."));
|
|
78
|
+
line();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
line();
|
|
85
|
+
const n = ordinalOf(ctx, sessionId);
|
|
86
|
+
row("Session", c.value(title ?? sessionId.slice(0, 8)) + (n ? c.dim(` #${n}`) : ""));
|
|
87
|
+
if (started)
|
|
88
|
+
row("Started", c.value(timeAgo(started)));
|
|
89
|
+
if (messages !== null)
|
|
90
|
+
row("Messages", c.value(String(messages)));
|
|
91
|
+
}
|
|
92
|
+
// ── How the next turn is configured ───────────────────────────────────────
|
|
93
|
+
line();
|
|
94
|
+
row("Chat", c.value(chatTypeLabel(ctx.chatType)));
|
|
95
|
+
// Carrier Chat is always General, so the mode row would be noise there.
|
|
96
|
+
if (ctx.modeIsSelectable)
|
|
97
|
+
row("Mode", c.value(modeLabelShort(ctx)));
|
|
98
|
+
row("Model", c.value(modelLabelShort(ctx)));
|
|
99
|
+
const mode = getPermissionMode(ctx.config);
|
|
100
|
+
row("Permissions", c.value(permissionModeLabel(mode)) + c.dim(` · ${permissionModeExplanation(mode)}`));
|
|
101
|
+
const on = [];
|
|
102
|
+
if (ctx.fast)
|
|
103
|
+
on.push("Fast");
|
|
104
|
+
if (ctx.highPower)
|
|
105
|
+
on.push("High Power");
|
|
106
|
+
if (ctx.webSearchArmed)
|
|
107
|
+
on.push("Web search (next message)");
|
|
108
|
+
else if (ctx.webSearch === true)
|
|
109
|
+
on.push("Web search");
|
|
110
|
+
if (on.length)
|
|
111
|
+
row("Active", c.value(on.join(" · ")));
|
|
112
|
+
const attached = ctx.attachedFileIds.length;
|
|
113
|
+
if (attached > 0)
|
|
114
|
+
row("Files", c.value(`${attached} attached`));
|
|
115
|
+
const sources = ctx.lastSources.length;
|
|
116
|
+
if (sources > 0)
|
|
117
|
+
row("Sources", c.dim(`${sources} from the last search · `) + c.cmd("/sources"));
|
|
118
|
+
// ── Memory the engine has built for this conversation ─────────────────────
|
|
119
|
+
if (sessionId) {
|
|
120
|
+
try {
|
|
121
|
+
const { messages } = await client.sessionMessages(sessionId);
|
|
122
|
+
const markers = messages.filter(isMemoryMarker);
|
|
123
|
+
const summary = memorySummaryLine(markers);
|
|
124
|
+
if (summary) {
|
|
125
|
+
const cost = markers.reduce((sum, m) => sum + (m.cost_usd ?? 0), 0);
|
|
126
|
+
row("Memory", c.value(summary) + (cost > 0 ? c.dim(` · $${cost.toFixed(4)}`) : ""));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
/* memory is supplementary — a failure here shouldn't blank the view */
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// ── The current coding task (the platform's Task Context) ────────────────
|
|
134
|
+
if (sessionId && typeof client.taskContext === "function") {
|
|
135
|
+
const snap = taskSnapshot(await client.taskContext(sessionId).catch(() => null));
|
|
136
|
+
if (snap) {
|
|
137
|
+
line();
|
|
138
|
+
line(" " + c.dim("Task"));
|
|
139
|
+
for (const [label, value] of taskSnapshotRows(snap))
|
|
140
|
+
row(label, value);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// ── The local project ─────────────────────────────────────────────────────
|
|
144
|
+
// Peek rather than build: /context is a status view, and it should not be the
|
|
145
|
+
// thing that decides to walk a monorepo. When nothing has built a snapshot
|
|
146
|
+
// yet, the row says so instead of silently doing the work.
|
|
147
|
+
const pc = peekProjectContext();
|
|
148
|
+
if (pc) {
|
|
149
|
+
line();
|
|
150
|
+
row("Project", c.value(projectSummaryLine(pc)));
|
|
151
|
+
const found = instructionStatus(pc)
|
|
152
|
+
.filter((i) => i.found)
|
|
153
|
+
.map((i) => i.name);
|
|
154
|
+
row("Instructions", found.length ? c.value(found.join(", ")) : c.dim("none"));
|
|
155
|
+
row("Local tools", c.dim(LOCAL_TOOL_NAMES.join(" · ") + " (read-only)"));
|
|
156
|
+
row("Attached", ctx.config.get("projectContextPending") === true
|
|
157
|
+
? c.accent("yes — rides with your next message")
|
|
158
|
+
: c.dim("no · /context project --attach"));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
line();
|
|
162
|
+
row("Project", c.dim("not scanned yet · /project"));
|
|
163
|
+
}
|
|
164
|
+
// ── What we still can't show ──────────────────────────────────────────────
|
|
165
|
+
line();
|
|
166
|
+
line(" " + c.dim("Live token window and health aren't exposed by the public API yet."));
|
|
167
|
+
line();
|
|
168
|
+
}
|
|
169
|
+
/** Fallback used when there's nothing to report at all. */
|
|
170
|
+
export function contextUnavailable() {
|
|
171
|
+
for (const l of emptyState("No context yet.", "Start a conversation and run /context again.")) {
|
|
172
|
+
line(l);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** The task snapshot as label/value rows — the same facts the IDE's /context card shows. */
|
|
176
|
+
export function taskSnapshotRows(t) {
|
|
177
|
+
const list = (items, total = items.length) => (items.length ? items.join(", ") + (total > items.length ? c.dim(` (+${total - items.length} more)`) : "") : c.dim("none"));
|
|
178
|
+
const rows = [
|
|
179
|
+
["Task", c.value(t.title)],
|
|
180
|
+
["Status", c.value(t.status) + (t.verified !== t.status ? c.dim(` · verified: ${t.verified}`) : "")],
|
|
181
|
+
["Investigation", c.value(`${t.investigation.searches} searches · ${t.inspected.total} files read · ${t.investigation.symbols.length} symbols traced · ${t.investigation.relationships.length} relationships followed`)],
|
|
182
|
+
["Inspected", list(t.inspected.files, t.inspected.total)],
|
|
183
|
+
...(t.symptom ? [["Symptom", c.value(t.symptom)]] : []),
|
|
184
|
+
...(t.executionPath.length ? [["Path", t.executionPath.join(c.dim(" → "))]] : []),
|
|
185
|
+
["Root cause", t.rootCause ? c.value(t.rootCause) : c.dim("not established yet")],
|
|
186
|
+
...(t.changeLocation ? [["Change at", c.value(t.changeLocation)]] : []),
|
|
187
|
+
...(t.evidence.length ? [["Evidence", t.evidence.join("; ")]] : []),
|
|
188
|
+
...(t.ruledOut.length ? [["Ruled out", t.ruledOut.join("; ")]] : []),
|
|
189
|
+
...(t.plan ? [["Plan", c.value(t.plan)]] : []),
|
|
190
|
+
["Modified", list(t.modified)],
|
|
191
|
+
["Created", list(t.created)],
|
|
192
|
+
["Deleted", list(t.deleted)],
|
|
193
|
+
["Unresolved", t.unresolved.length ? c.warn(t.unresolved.join(", ") + " — may still be on disk; review before continuing") : c.dim("none")]
|
|
194
|
+
];
|
|
195
|
+
if (t.pendingOperations.length)
|
|
196
|
+
rows.push(["Interrupted", c.warn(t.pendingOperations.join(", ") + " — never resumed automatically")]);
|
|
197
|
+
rows.push(["Corrections", t.corrections ? c.value(String(t.corrections)) + (t.lastCorrection ? c.dim(` · ${t.lastCorrection.slice(0, 80)}`) : "") : c.dim("none")]);
|
|
198
|
+
rows.push(["Tests", t.tests.length ? t.tests.map((r) => `${r.command} → ${r.outcome}`).join("; ") : c.dim("none run")]);
|
|
199
|
+
return rows;
|
|
200
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { ApiError } from "../services/api.js";
|
|
3
|
+
import { cliVersion } from "../services/meta.js";
|
|
4
|
+
import { findPrebuiltHelper } from "../services/helper-bin.js";
|
|
5
|
+
import { isPackaged, isSignedRelease } from "../services/packaged.js";
|
|
6
|
+
import { glyph, heading, line } from "../services/output.js";
|
|
7
|
+
import { withSpinner } from "../services/spinner.js";
|
|
8
|
+
import { discoverRootWithoutGit, refreshWorkspace } from "../services/workspace.js";
|
|
9
|
+
import { isTrusted } from "../ui/trust.js";
|
|
10
|
+
import { COMMANDS_OPT_IN_ENV, localCommandsState } from "../services/client-tools.js";
|
|
11
|
+
import { getPermissionMode } from "../services/permission-mode.js";
|
|
12
|
+
import { executionContract } from "../services/execution-platform.js";
|
|
13
|
+
function row(status, label, detail) {
|
|
14
|
+
const g = status === "ok" ? glyph.ok : status === "warn" ? glyph.warn : glyph.err;
|
|
15
|
+
line(` ${g} ${label.padEnd(20)} ${detail}`);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `cos doctor` — one-shot health check of the whole setup:
|
|
19
|
+
* configuration, network/API reachability, key presence and key validity.
|
|
20
|
+
*/
|
|
21
|
+
export function registerDoctor(program, ctx) {
|
|
22
|
+
program
|
|
23
|
+
.command("doctor")
|
|
24
|
+
.description("Diagnose configuration, connectivity and authentication")
|
|
25
|
+
.action(async () => {
|
|
26
|
+
const client = ctx.client();
|
|
27
|
+
const apiUrl = ctx.config.get("apiUrl") ?? "—";
|
|
28
|
+
heading("Carrier OS — diagnostics");
|
|
29
|
+
// 0) Installation — only the packaged .exe has one to check. A helper that
|
|
30
|
+
// fails its baked hash is reported here rather than discovered mid-login.
|
|
31
|
+
if (isPackaged()) {
|
|
32
|
+
row("ok", "Installation", `v${cliVersion()} · ${path.dirname(process.execPath)}`);
|
|
33
|
+
row(isSignedRelease() ? "ok" : "warn", "Build", isSignedRelease() ? "signed release" : "unsigned build");
|
|
34
|
+
for (const helper of ["cos-dpapi", "cos-job-runner"]) {
|
|
35
|
+
const found = findPrebuiltHelper(helper);
|
|
36
|
+
row(found ? "ok" : "err", helper, found ? "verified" : "missing or damaged — reinstall Carrier OS");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// 1) Configuration
|
|
40
|
+
row("ok", "Configuration", `${ctx.config.file}`);
|
|
41
|
+
row("ok", "Endpoint", apiUrl);
|
|
42
|
+
// 2) Network / API reachability (health needs no key)
|
|
43
|
+
let apiVersion = "unknown";
|
|
44
|
+
try {
|
|
45
|
+
const health = await withSpinner("Pinging API…", () => client.health());
|
|
46
|
+
apiVersion = health.version;
|
|
47
|
+
row("ok", "API reachable", [health.status, health.version, health.environment].filter(Boolean).join(" · "));
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
row("err", "API reachable", err instanceof ApiError ? err.message : "unreachable");
|
|
51
|
+
}
|
|
52
|
+
// 3) Signed in?
|
|
53
|
+
if (!ctx.config.isAuthenticated) {
|
|
54
|
+
row("warn", "Session", "not signed in — run `cos login`");
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
row("ok", "Session", "present");
|
|
58
|
+
// 4) Session valid?
|
|
59
|
+
try {
|
|
60
|
+
const scope = await withSpinner("Verifying session…", () => client.verify());
|
|
61
|
+
row("ok", "Session valid", scope.user?.email ?? "CLI device session");
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
row("err", "Session valid", err instanceof ApiError ? `${err.message} (${err.code})` : "failed");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// 5) Local workspace. This is where the DETAIL of a failed repository
|
|
68
|
+
// read belongs — the banner and /repo say "unavailable" and move on,
|
|
69
|
+
// because a person opening a shell does not want a Git error, but a
|
|
70
|
+
// person running diagnostics does.
|
|
71
|
+
// Diagnostics never prompt; an untrusted folder is reported, not entered.
|
|
72
|
+
const trustRoot = discoverRootWithoutGit();
|
|
73
|
+
if (process.stdin.isTTY && !isTrusted(ctx.config, trustRoot) && !isTrusted(ctx.config)) {
|
|
74
|
+
row("warn", "Repository", "not checked — this folder is not trusted (open `cos` here to trust it)");
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const ws = refreshWorkspace();
|
|
78
|
+
row("ok", "Directory", ws.cwd);
|
|
79
|
+
if (!ws.repository.gitAvailable) {
|
|
80
|
+
row("warn", "Git", "not found on PATH");
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
row("ok", "Git", "available");
|
|
84
|
+
}
|
|
85
|
+
if (ws.repository.state === "detected") {
|
|
86
|
+
row("ok", "Repository", ws.repository.root ?? "detected");
|
|
87
|
+
}
|
|
88
|
+
else if (ws.repository.state === "unavailable") {
|
|
89
|
+
row("warn", "Repository", ws.repository.error ?? "unavailable");
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
row("ok", "Repository", "not a repository");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// 6) Local capabilities. Reading and file changes follow folder trust;
|
|
96
|
+
// running commands needs Auto or the explicit setting, plus containment;
|
|
97
|
+
// report the precise missing gate rather than just "off".
|
|
98
|
+
const trusted = isTrusted(ctx.config, trustRoot) || isTrusted(ctx.config);
|
|
99
|
+
row(trusted ? "ok" : "warn", "Folder trust", trusted ? `trusted: ${trustRoot}` : `not trusted: ${trustRoot}`);
|
|
100
|
+
// The same check the shell uses to offer run_command, so the two agree
|
|
101
|
+
// on every platform (Windows Job Object; macOS/Linux isolated runtime).
|
|
102
|
+
const commands = localCommandsState(ctx, true, getPermissionMode(ctx.config) === "auto");
|
|
103
|
+
const runtime = executionContract().backend === "docker-engine-v1" ? "isolated Linux container" : "Windows Job Object";
|
|
104
|
+
const commandState = !commands.enabled
|
|
105
|
+
? ctx.config.get("localCommandsEnabled") === false
|
|
106
|
+
? "off — explicitly disabled with /settings commands off"
|
|
107
|
+
: `off — /settings commands on (or select Auto), or set ${COMMANDS_OPT_IN_ENV}=1 in this terminal`
|
|
108
|
+
: commands.blockedBy
|
|
109
|
+
? `not active — ${commands.blockedBy}`
|
|
110
|
+
: getPermissionMode(ctx.config) === "auto"
|
|
111
|
+
? `on (${runtime}) — Auto runs locally permitted commands without individual prompts`
|
|
112
|
+
: `on (${runtime}) — Manual/Accept Edits ask before each command`;
|
|
113
|
+
row(commands.enabled && !commands.blockedBy ? "ok" : "warn", "Local commands", commandState);
|
|
114
|
+
// 7) Versions
|
|
115
|
+
row("ok", "CLI version", cliVersion());
|
|
116
|
+
row("ok", "API version", apiVersion);
|
|
117
|
+
line();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { line, timeAgo } from "../services/output.js";
|
|
2
|
+
import { formatSize, listDirectory } from "../services/local-files.js";
|
|
3
|
+
import { discoverRootWithoutGit, getWorkspace } from "../services/workspace.js";
|
|
4
|
+
import { c } from "../ui/colors.js";
|
|
5
|
+
import { ensureWorkspaceTrust } from "../ui/trust.js";
|
|
6
|
+
import { emptyState, sectionHeader, twoCol } from "../ui/ui.js";
|
|
7
|
+
export function registerFiles(program, ctx) {
|
|
8
|
+
program
|
|
9
|
+
.command("files")
|
|
10
|
+
.argument("[scope]", "local | uploaded")
|
|
11
|
+
.option("-d, --depth <n>", "how deep to show the local tree", "3")
|
|
12
|
+
.description("List local project files and files uploaded from this machine")
|
|
13
|
+
.action(async (scopeArg, options) => {
|
|
14
|
+
const scope = parseScope(scopeArg);
|
|
15
|
+
const depth = Number.parseInt(options.depth, 10) || 3;
|
|
16
|
+
if (scope !== "uploaded") {
|
|
17
|
+
const shown = await renderLocal(ctx, depth);
|
|
18
|
+
// Only separate the sections when the first one actually printed.
|
|
19
|
+
if (shown && scope === "all")
|
|
20
|
+
line();
|
|
21
|
+
}
|
|
22
|
+
if (scope !== "local")
|
|
23
|
+
renderUploaded(ctx, scope === "all");
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function parseScope(arg) {
|
|
27
|
+
const v = (arg ?? "").trim().toLowerCase();
|
|
28
|
+
if (v === "local" || v === "l")
|
|
29
|
+
return "local";
|
|
30
|
+
if (v === "uploaded" || v === "u" || v === "remote")
|
|
31
|
+
return "uploaded";
|
|
32
|
+
return "all";
|
|
33
|
+
}
|
|
34
|
+
/** The local project tree. Returns false when trust was declined. */
|
|
35
|
+
async function renderLocal(ctx, depth) {
|
|
36
|
+
// Listing reads the project, which is precisely what folder trust covers.
|
|
37
|
+
if (!(await ensureWorkspaceTrust(ctx.config, discoverRootWithoutGit())))
|
|
38
|
+
return false;
|
|
39
|
+
const ws = getWorkspace();
|
|
40
|
+
const result = listDirectory({ depth });
|
|
41
|
+
line();
|
|
42
|
+
line(sectionHeader(`Local project · ${ws.project.name}`));
|
|
43
|
+
if (result.entries.length === 0) {
|
|
44
|
+
line(" " + c.dim("This folder is empty."));
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
for (const e of result.entries) {
|
|
48
|
+
// depth 1 is a root-level entry, so it gets no extra indent.
|
|
49
|
+
const indent = " ".repeat(e.depth - 1);
|
|
50
|
+
if (e.type === "dir") {
|
|
51
|
+
line(" " + indent + c.accent(`${nameOf(e.path)}/`));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
line(" " + indent + c.value(nameOf(e.path)) + " " + c.dim(formatSize(e.size)));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const notes = [];
|
|
58
|
+
if (result.truncated)
|
|
59
|
+
notes.push("list shortened");
|
|
60
|
+
if (result.skipped)
|
|
61
|
+
notes.push(`${result.skipped} unreadable`);
|
|
62
|
+
if (notes.length) {
|
|
63
|
+
line(" " + c.dim(`(${notes.join(" · ")} — ignored and build folders are skipped)`));
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
/** The existing uploaded-files view, unchanged. */
|
|
68
|
+
function renderUploaded(ctx, withinCombined) {
|
|
69
|
+
const uploads = ctx.config.get("uploads") ?? [];
|
|
70
|
+
if (uploads.length === 0) {
|
|
71
|
+
if (withinCombined) {
|
|
72
|
+
line(sectionHeader("Uploaded to Carrier OS"));
|
|
73
|
+
line(" " + c.dim("Nothing uploaded yet — /upload <file>."));
|
|
74
|
+
line();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
for (const l of emptyState("No uploaded files yet.", "Upload one with", "/upload <file>")) {
|
|
78
|
+
line(l);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
line();
|
|
83
|
+
line(sectionHeader(`Uploaded to Carrier OS (${uploads.length})`));
|
|
84
|
+
const rows = uploads.map((f) => [
|
|
85
|
+
f.filename,
|
|
86
|
+
`${f.file_type} · ${timeAgo(f.uploaded_at)} · ${f.file_id.slice(0, 8)}`
|
|
87
|
+
]);
|
|
88
|
+
for (const l of twoCol(rows, c.value, c.dim))
|
|
89
|
+
line(l);
|
|
90
|
+
line();
|
|
91
|
+
}
|
|
92
|
+
function nameOf(relPath) {
|
|
93
|
+
return relPath.slice(relPath.lastIndexOf("/") + 1);
|
|
94
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { line } from "../services/output.js";
|
|
3
|
+
/**
|
|
4
|
+
* `cos help` — a styled overview of the workflow, complementing
|
|
5
|
+
* Commander's auto-generated `--help`.
|
|
6
|
+
*/
|
|
7
|
+
export function registerHelp(program, _ctx) {
|
|
8
|
+
program
|
|
9
|
+
.command("help-overview")
|
|
10
|
+
.alias("guide")
|
|
11
|
+
.description("Show a guided overview of the CLI workflow")
|
|
12
|
+
.action(() => {
|
|
13
|
+
const item = (cmd, desc) => line(` ${chalk.cyan(cmd.padEnd(26))} ${chalk.dim(desc)}`);
|
|
14
|
+
line("\n" + chalk.bold.cyan(" Carrier OS CLI") + chalk.dim(" — developer workflow\n"));
|
|
15
|
+
line(chalk.bold(" Getting started"));
|
|
16
|
+
item("cos login", "sign in through your browser");
|
|
17
|
+
item("cos workspace use", "switch workspace · cos project use");
|
|
18
|
+
item("cos doctor", "verify configuration & connectivity");
|
|
19
|
+
item("cos whoami", "show workspace / project / account");
|
|
20
|
+
line("\n" + chalk.bold(" Chat"));
|
|
21
|
+
item("cos", "interactive shell (default)");
|
|
22
|
+
item("cos chat --mode code", "chat in a specific Carrier mode");
|
|
23
|
+
item("cos modes", "list Carrier modes (behavior)");
|
|
24
|
+
item("cos models", "list provider models (GPT, Grok, …)");
|
|
25
|
+
item("/btw <question>", "side question — not added to the conversation");
|
|
26
|
+
line("\n" + chalk.bold(" Sessions"));
|
|
27
|
+
item("cos sessions", "list conversations");
|
|
28
|
+
item("cos session use [id]", "switch active session");
|
|
29
|
+
item("cos history [id]", "print a transcript");
|
|
30
|
+
item("cos clear", "start a fresh session");
|
|
31
|
+
line("\n" + chalk.bold(" Files & usage"));
|
|
32
|
+
item("cos upload <file>", "upload + process a file");
|
|
33
|
+
item("cos files", "list your uploads");
|
|
34
|
+
item("cos usage", "requests, tokens, cost");
|
|
35
|
+
line("\n" + chalk.dim(" Run `cos <command> --help` for details on any command.\n"));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ApiError } from "../services/api.js";
|
|
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";
|
|
5
|
+
import { withSpinner } from "../services/spinner.js";
|
|
6
|
+
import { c } from "../ui/colors.js";
|
|
7
|
+
import { memoryMarkerLine } from "../ui/chat-renderer.js";
|
|
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";
|
|
12
|
+
/**
|
|
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.
|
|
16
|
+
*/
|
|
17
|
+
export function registerHistory(program, ctx) {
|
|
18
|
+
program
|
|
19
|
+
.command("history")
|
|
20
|
+
.description("Show the transcript of a session")
|
|
21
|
+
.argument("[ref]", "session number from `cos sessions`, or a session id")
|
|
22
|
+
.action(async (ref) => {
|
|
23
|
+
const client = ctx.requireAuth();
|
|
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);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
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);
|
|
56
|
+
}
|
|
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
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
line(" " + m.content);
|
|
90
|
+
}
|
|
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>"));
|
|
98
|
+
line();
|
|
99
|
+
}
|
|
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;
|
|
108
|
+
}
|
|
109
|
+
errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
|
|
110
|
+
process.exitCode = 1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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";
|
|
4
|
+
/**
|
|
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.
|
|
14
|
+
*/
|
|
15
|
+
export function registerLogin(program, ctx) {
|
|
16
|
+
program
|
|
17
|
+
.command("login")
|
|
18
|
+
.description("Sign in through your browser (device authorization)")
|
|
19
|
+
.option("--url <url>", "override the API base URL (e.g. http://localhost:5000/v1)")
|
|
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
|
+
}
|
|
36
|
+
if (opts.url)
|
|
37
|
+
ctx.config.set("apiUrl", opts.url.replace(/\/+$/, ""));
|
|
38
|
+
if (opts.platform)
|
|
39
|
+
ctx.config.set("platformUrl", opts.platform.replace(/\/+$/, ""));
|
|
40
|
+
const apiUrl = ctx.config.get("apiUrl") ?? DEFAULT_API_URL;
|
|
41
|
+
if (ctx.config.isAuthenticated) {
|
|
42
|
+
info("You are already logged in. Run `cos logout` first to switch accounts.");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
await deviceLogin(ctx, apiUrl);
|
|
47
|
+
line();
|
|
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
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
const kind = renderLoginFailure(err, apiUrl);
|
|
57
|
+
if (kind === "denied")
|
|
58
|
+
line(" " + "Run `cos login` to retry.");
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DEFAULT_API_URL } from "../services/config.js";
|
|
2
|
+
import { logoutCliSession } from "../services/device-auth.js";
|
|
3
|
+
import { info, success } from "../services/output.js";
|
|
4
|
+
import { withSpinner } from "../services/spinner.js";
|
|
5
|
+
/** `cos logout` — revoke the session server-side, then forget it locally. */
|
|
6
|
+
export function registerLogout(program, ctx) {
|
|
7
|
+
program
|
|
8
|
+
.command("logout")
|
|
9
|
+
.description("Sign out and revoke this device's session")
|
|
10
|
+
.action(async () => {
|
|
11
|
+
if (!ctx.config.isAuthenticated) {
|
|
12
|
+
info("You are already logged out.");
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const apiUrl = ctx.config.get("apiUrl") ?? DEFAULT_API_URL;
|
|
16
|
+
const refreshToken = ctx.config.get("auth")?.refreshToken;
|
|
17
|
+
ctx.validateCredentialOrigin(apiUrl);
|
|
18
|
+
if (refreshToken) {
|
|
19
|
+
// Best-effort server revoke so the refresh token can't be reused.
|
|
20
|
+
await withSpinner("Signing out…", () => logoutCliSession(apiUrl, refreshToken));
|
|
21
|
+
}
|
|
22
|
+
ctx.config.clearAuth();
|
|
23
|
+
success("Logged out. This device's session has been removed.");
|
|
24
|
+
});
|
|
25
|
+
}
|