@carrieros/cli 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -57
- 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 +102 -13
- package/dist/commands/context.js +160 -0
- package/dist/commands/doctor.js +53 -8
- package/dist/commands/files.js +84 -23
- package/dist/commands/help.js +3 -1
- package/dist/commands/history.js +88 -23
- package/dist/commands/login.js +44 -41
- package/dist/commands/logout.js +13 -4
- 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/scope.js +152 -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/commands/whoami.js +2 -1
- 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 +30 -1
- package/dist/services/api.js +171 -13
- 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 +249 -22
- package/dist/services/context.js +307 -6
- package/dist/services/device-auth.js +261 -0
- 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 +120 -10
- 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 +13 -5
- 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/spinner.js +23 -1
- 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 +1115 -59
- package/dist/shell/shell-commands.js +220 -19
- package/dist/shell/shell-prompt.js +89 -37
- package/dist/shell/shell-renderer.js +19 -38
- package/dist/shell/shell-router.js +19 -3
- package/dist/shell/shell.js +232 -44
- package/dist/types/index.js +3 -1
- package/dist/ui/approval.js +81 -0
- package/dist/ui/banner.js +55 -13
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +87 -0
- package/dist/ui/chat-renderer.js +223 -29
- package/dist/ui/color-picker.js +21 -0
- package/dist/ui/colors.js +9 -1
- package/dist/ui/command-filter.js +40 -5
- package/dist/ui/command-palette.js +122 -62
- package/dist/ui/command-registry.js +85 -11
- 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 +18 -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 +289 -0
- package/dist/ui/select.js +193 -29
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/theme.js +17 -0
- package/dist/ui/trust.js +93 -0
- package/dist/ui/ui.js +4 -1
- package/package.json +17 -6
- package/dist/ui/activity.js +0 -77
package/dist/commands/chat.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { input } from "@inquirer/prompts";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { info, line, printBanner } from "../services/output.js";
|
|
4
|
-
import {
|
|
4
|
+
import { clearActiveSession, listSessions } from "../services/session-resolver.js";
|
|
5
|
+
import { showContext } from "./context.js";
|
|
6
|
+
import { showHistory } from "./history.js";
|
|
7
|
+
import { newSession, pickSession, renderSessionList, switchTo } from "./sessions.js";
|
|
8
|
+
import { chatTurn, chatTypeLabelShort, loadModels, loadModes, modeLabelShort, modelLabelShort, armWebSearch, isWebSearchStateArg, openSource, pickChatType, pickMode, pickModel, searchNow, setChatType, setFast, setHighPower, setMode, setModel, setWebSearch, showSources } from "../shell/shell-chat.js";
|
|
5
9
|
/**
|
|
6
10
|
* `cos chat` — a focused interactive REPL over POST /v1/chat. (The full
|
|
7
11
|
* shell — `cos` with no command — is a superset with every slash command.)
|
|
@@ -11,21 +15,38 @@ export function registerChat(program, ctx) {
|
|
|
11
15
|
program
|
|
12
16
|
.command("chat")
|
|
13
17
|
.description("Start a focused interactive chat session")
|
|
18
|
+
.argument("[message...]", "an optional first message to send immediately (uses attached files)")
|
|
14
19
|
.option("-m, --mode <mode>", "Carrier mode (general, code, research, …)")
|
|
15
20
|
.option("--model <model>", "provider model override (e.g. gpt-5.5); 'auto' to clear")
|
|
16
|
-
.
|
|
21
|
+
.option("--standard", "start in Standard chat instead of Carrier Chat")
|
|
22
|
+
.action(async (messageParts, opts) => {
|
|
23
|
+
// Mode follows the chat type (Carrier → General, Standard → saved or
|
|
24
|
+
// Auto); an explicit -m flag overrides it for this run.
|
|
17
25
|
if (opts.mode)
|
|
18
26
|
ctx.config.set("mode", opts.mode);
|
|
19
27
|
if (opts.model !== undefined)
|
|
20
28
|
ctx.config.set("model", opts.model === "auto" ? "" : opts.model);
|
|
21
|
-
|
|
29
|
+
// Chat type defaults to Carrier Chat (the persisted default is carrier);
|
|
30
|
+
// --standard opts into a plain chat for this run onward.
|
|
31
|
+
if (opts.standard)
|
|
32
|
+
ctx.setChatType("standard");
|
|
33
|
+
// e.g. `cos chat "Summarize this file"` — send it right away (with any
|
|
34
|
+
// attached file_ids), then continue into the REPL for follow-ups.
|
|
35
|
+
const initial = (messageParts ?? []).join(" ").trim();
|
|
36
|
+
await runChat(ctx, initial || undefined);
|
|
22
37
|
});
|
|
23
38
|
}
|
|
24
|
-
export async function runChat(ctx) {
|
|
39
|
+
export async function runChat(ctx, initialMessage) {
|
|
25
40
|
const client = ctx.requireAuth();
|
|
26
|
-
// Preload models so the banner can show
|
|
27
|
-
await loadModels(client).catch(() => []);
|
|
28
|
-
printBanner(ctx.config.get("scope"), ctx
|
|
41
|
+
// Preload modes + models so the banner can show friendly labels (best-effort).
|
|
42
|
+
await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => [])]);
|
|
43
|
+
printBanner(ctx.config.get("scope"), modeLabelShort(ctx), modelLabelShort(ctx));
|
|
44
|
+
info(`${chatTypeLabelShort(ctx)} · type /chat to switch (carrier / standard)`);
|
|
45
|
+
// A message passed on the command line (`cos chat "…"`) is sent immediately —
|
|
46
|
+
// with any attached files — before the interactive loop takes over.
|
|
47
|
+
if (initialMessage) {
|
|
48
|
+
await chatTurn(ctx, client, initialMessage);
|
|
49
|
+
}
|
|
29
50
|
for (;;) {
|
|
30
51
|
let message;
|
|
31
52
|
try {
|
|
@@ -49,14 +70,44 @@ export async function runChat(ctx) {
|
|
|
49
70
|
printSlashHelp();
|
|
50
71
|
continue;
|
|
51
72
|
}
|
|
52
|
-
if (cmdWord === "/new"
|
|
53
|
-
ctx.
|
|
54
|
-
|
|
73
|
+
if (cmdWord === "/new") {
|
|
74
|
+
await newSession(ctx, argStr.trim());
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (cmdWord === "/clear") {
|
|
78
|
+
clearActiveSession(ctx);
|
|
79
|
+
info("Cleared. Your next message starts a fresh session.");
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (cmdWord === "/sessions") {
|
|
83
|
+
const { conversations, total } = await listSessions(ctx, client, { limit: 20 });
|
|
84
|
+
renderSessionList(conversations, ctx.config.get("sessionId"), total);
|
|
55
85
|
continue;
|
|
56
86
|
}
|
|
57
87
|
if (cmdWord === "/session") {
|
|
58
|
-
|
|
59
|
-
|
|
88
|
+
if (!argStr.trim())
|
|
89
|
+
await pickSession(ctx, client);
|
|
90
|
+
else
|
|
91
|
+
await switchTo(ctx, client, argStr.trim());
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (cmdWord === "/history") {
|
|
95
|
+
await showHistory(ctx, client, argStr.trim() || undefined);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (cmdWord === "/context") {
|
|
99
|
+
await showContext(ctx, client);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (cmdWord === "/chat") {
|
|
103
|
+
setChatType(ctx, argStr);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (cmdWord === "/switch") {
|
|
107
|
+
if (argStr.trim())
|
|
108
|
+
setChatType(ctx, argStr);
|
|
109
|
+
else
|
|
110
|
+
await pickChatType(ctx);
|
|
60
111
|
continue;
|
|
61
112
|
}
|
|
62
113
|
if (cmdWord === "/modes") {
|
|
@@ -75,17 +126,55 @@ export async function runChat(ctx) {
|
|
|
75
126
|
await setModel(ctx, client, argStr);
|
|
76
127
|
continue;
|
|
77
128
|
}
|
|
129
|
+
if (cmdWord === "/websearch" || cmdWord === "/web") {
|
|
130
|
+
if (!argStr)
|
|
131
|
+
armWebSearch(ctx);
|
|
132
|
+
else if (isWebSearchStateArg(argStr))
|
|
133
|
+
setWebSearch(ctx, argStr);
|
|
134
|
+
else
|
|
135
|
+
await searchNow(ctx, client, argStr);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (cmdWord === "/fast") {
|
|
139
|
+
setFast(ctx, argStr);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (cmdWord === "/hipwr" || cmdWord === "/highpower") {
|
|
143
|
+
setHighPower(ctx, argStr);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (cmdWord === "/sources") {
|
|
147
|
+
showSources(ctx);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (cmdWord === "/open") {
|
|
151
|
+
openSource(ctx, argStr);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
78
154
|
await chatTurn(ctx, client, message);
|
|
79
155
|
}
|
|
80
156
|
}
|
|
81
157
|
function printSlashHelp() {
|
|
82
158
|
line();
|
|
83
159
|
line(chalk.dim(" In-chat commands:"));
|
|
160
|
+
line(` ${chalk.cyan("/switch")} switch chat: Carrier ⇄ Standard (picker)`);
|
|
161
|
+
line(` ${chalk.cyan("/chat")} switch experience: /chat carrier | /chat standard`);
|
|
84
162
|
line(` ${chalk.cyan("/modes")} list Carrier modes (behavior)`);
|
|
85
163
|
line(` ${chalk.cyan("/mode <id>")} switch Carrier mode (e.g. /mode code)`);
|
|
86
164
|
line(` ${chalk.cyan("/models")} list provider models (GPT, Grok, …)`);
|
|
87
165
|
line(` ${chalk.cyan("/model <id>")} set model override (e.g. gpt-5.5), or /model auto`);
|
|
88
|
-
line(` ${chalk.cyan("/
|
|
166
|
+
line(` ${chalk.cyan("/websearch")} search the web on your next message`);
|
|
167
|
+
line(` ${chalk.cyan("/websearch <q>")} search for something right now`);
|
|
168
|
+
line(` ${chalk.cyan("/fast")} toggle fast mode (quicker, less refinement)`);
|
|
169
|
+
line(` ${chalk.cyan("/hipwr")} toggle High Power (4-pass refinement)`);
|
|
170
|
+
line(` ${chalk.cyan("/sources")} sources from the last search`);
|
|
171
|
+
line(` ${chalk.cyan("/open <n>")} open a source in your browser`);
|
|
172
|
+
line();
|
|
173
|
+
line(` ${chalk.cyan("/new [title]")} start a new conversation`);
|
|
174
|
+
line(` ${chalk.cyan("/sessions")} list conversations, numbered`);
|
|
175
|
+
line(` ${chalk.cyan("/session <n>")} continue session n`);
|
|
176
|
+
line(` ${chalk.cyan("/history [n]")} transcript of n (or the active session)`);
|
|
177
|
+
line(` ${chalk.cyan("/context")} what your next message is sent with`);
|
|
89
178
|
line(` ${chalk.cyan("/session")} show the current session id`);
|
|
90
179
|
line(` ${chalk.cyan("/help")} show this help`);
|
|
91
180
|
line(` ${chalk.cyan("/exit")} leave the chat`);
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { ApiError } from "../services/api.js";
|
|
2
|
+
import { errorLine, line, timeAgo } from "../services/output.js";
|
|
3
|
+
import { ordinalOf } from "../services/session-resolver.js";
|
|
4
|
+
import { memorySummaryLine } from "./memory.js";
|
|
5
|
+
import { isMemoryMarker } from "../types/index.js";
|
|
6
|
+
import { modeLabelShort, modelLabelShort, chatTypeLabel } from "../shell/shell-chat.js";
|
|
7
|
+
import { withSpinner } from "../services/spinner.js";
|
|
8
|
+
import { c } from "../ui/colors.js";
|
|
9
|
+
import { emptyState, sectionHeader } from "../ui/ui.js";
|
|
10
|
+
import { runProject } from "./project.js";
|
|
11
|
+
import { LOCAL_TOOL_NAMES } from "../services/local-tools.js";
|
|
12
|
+
import { instructionStatus, peekProjectContext, projectSummaryLine } from "../services/project-context.js";
|
|
13
|
+
/**
|
|
14
|
+
* `cos context` — what the next message will actually be sent with.
|
|
15
|
+
*
|
|
16
|
+
* DELIBERATELY PARTIAL. The web shows a token window, cognitive-health score,
|
|
17
|
+
* snapshot and anchor counts, all from `/responses/conversations/:id/token-stats`
|
|
18
|
+
* — an endpoint the public /v1 surface does not expose. Rather than estimate
|
|
19
|
+
* those numbers client-side (they would be wrong, and wrong in a way that looks
|
|
20
|
+
* authoritative), this shows only what /v1 and local config actually know, and
|
|
21
|
+
* names what is missing.
|
|
22
|
+
*/
|
|
23
|
+
export function registerContext(program, ctx) {
|
|
24
|
+
program
|
|
25
|
+
.command("context")
|
|
26
|
+
.argument("[what]", 'omit for the conversation, or "project" for the local repository')
|
|
27
|
+
.option("--preview", "with project: print the exact text that would be attached")
|
|
28
|
+
.option("--attach", "with project: attach the brief to the next message")
|
|
29
|
+
.option("--detach", "with project: stop attaching it")
|
|
30
|
+
.option("--repo <repository>", "with project: describe a named repository from this workspace")
|
|
31
|
+
.description("Show what the next message will be sent with")
|
|
32
|
+
.action(async (what, options) => {
|
|
33
|
+
if ((what ?? "").trim().toLowerCase() === "project") {
|
|
34
|
+
const action = options.attach ? "attach" : options.detach ? "detach" : undefined;
|
|
35
|
+
await runProject(ctx, action, Boolean(options.preview), options.repo);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const client = ctx.requireAuth();
|
|
39
|
+
await showContext(ctx, client);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const LABEL_W = 11;
|
|
43
|
+
function row(label, value) {
|
|
44
|
+
line(" " + c.dim(label.padEnd(LABEL_W)) + value);
|
|
45
|
+
}
|
|
46
|
+
/** Shared by the standalone command and the shell's /context. */
|
|
47
|
+
export async function showContext(ctx, client) {
|
|
48
|
+
const sessionId = ctx.config.get("sessionId");
|
|
49
|
+
line();
|
|
50
|
+
line(sectionHeader("Context"));
|
|
51
|
+
// ── The conversation ──────────────────────────────────────────────────────
|
|
52
|
+
if (!sessionId) {
|
|
53
|
+
line();
|
|
54
|
+
line(" " + c.dim("No active conversation — your next message starts one."));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
let title = ctx.config.get("sessionTitle");
|
|
58
|
+
let messages = null;
|
|
59
|
+
let started = null;
|
|
60
|
+
try {
|
|
61
|
+
const s = await withSpinner("Loading…", () => client.session(sessionId));
|
|
62
|
+
title = s.title;
|
|
63
|
+
messages = s.message_count;
|
|
64
|
+
started = s.created_at;
|
|
65
|
+
// Keep the footer's cached title honest while we're here.
|
|
66
|
+
if (s.title)
|
|
67
|
+
ctx.config.set("sessionTitle", s.title);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
// A dead session shouldn't blank the whole view — show what's cached and
|
|
71
|
+
// say the rest couldn't be read.
|
|
72
|
+
if (err instanceof ApiError && err.status === 404) {
|
|
73
|
+
line();
|
|
74
|
+
line(" " + c.warn("!") + c.dim(" The active conversation is no longer available."));
|
|
75
|
+
line(" " + c.dim("Run ") + c.cmd("/sessions") + c.dim(" to pick another."));
|
|
76
|
+
line();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
errorLine(err instanceof ApiError ? `${err.message} (${err.code})` : err.message);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
line();
|
|
83
|
+
const n = ordinalOf(ctx, sessionId);
|
|
84
|
+
row("Session", c.value(title ?? sessionId.slice(0, 8)) + (n ? c.dim(` #${n}`) : ""));
|
|
85
|
+
if (started)
|
|
86
|
+
row("Started", c.value(timeAgo(started)));
|
|
87
|
+
if (messages !== null)
|
|
88
|
+
row("Messages", c.value(String(messages)));
|
|
89
|
+
}
|
|
90
|
+
// ── How the next turn is configured ───────────────────────────────────────
|
|
91
|
+
line();
|
|
92
|
+
row("Chat", c.value(chatTypeLabel(ctx.chatType)));
|
|
93
|
+
// Carrier Chat is always General, so the mode row would be noise there.
|
|
94
|
+
if (ctx.modeIsSelectable)
|
|
95
|
+
row("Mode", c.value(modeLabelShort(ctx)));
|
|
96
|
+
row("Model", c.value(modelLabelShort(ctx)));
|
|
97
|
+
const on = [];
|
|
98
|
+
if (ctx.fast)
|
|
99
|
+
on.push("Fast");
|
|
100
|
+
if (ctx.highPower)
|
|
101
|
+
on.push("High Power");
|
|
102
|
+
if (ctx.webSearchArmed)
|
|
103
|
+
on.push("Web search (next message)");
|
|
104
|
+
else if (ctx.webSearch === true)
|
|
105
|
+
on.push("Web search");
|
|
106
|
+
if (on.length)
|
|
107
|
+
row("Active", c.value(on.join(" · ")));
|
|
108
|
+
const attached = ctx.attachedFileIds.length;
|
|
109
|
+
if (attached > 0)
|
|
110
|
+
row("Files", c.value(`${attached} attached`));
|
|
111
|
+
const sources = ctx.lastSources.length;
|
|
112
|
+
if (sources > 0)
|
|
113
|
+
row("Sources", c.dim(`${sources} from the last search · `) + c.cmd("/sources"));
|
|
114
|
+
// ── Memory the engine has built for this conversation ─────────────────────
|
|
115
|
+
if (sessionId) {
|
|
116
|
+
try {
|
|
117
|
+
const { messages } = await client.sessionMessages(sessionId);
|
|
118
|
+
const markers = messages.filter(isMemoryMarker);
|
|
119
|
+
const summary = memorySummaryLine(markers);
|
|
120
|
+
if (summary) {
|
|
121
|
+
const cost = markers.reduce((sum, m) => sum + (m.cost_usd ?? 0), 0);
|
|
122
|
+
row("Memory", c.value(summary) + (cost > 0 ? c.dim(` · $${cost.toFixed(4)}`) : ""));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
/* memory is supplementary — a failure here shouldn't blank the view */
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// ── The local project ─────────────────────────────────────────────────────
|
|
130
|
+
// Peek rather than build: /context is a status view, and it should not be the
|
|
131
|
+
// thing that decides to walk a monorepo. When nothing has built a snapshot
|
|
132
|
+
// yet, the row says so instead of silently doing the work.
|
|
133
|
+
const pc = peekProjectContext();
|
|
134
|
+
if (pc) {
|
|
135
|
+
line();
|
|
136
|
+
row("Project", c.value(projectSummaryLine(pc)));
|
|
137
|
+
const found = instructionStatus(pc)
|
|
138
|
+
.filter((i) => i.found)
|
|
139
|
+
.map((i) => i.name);
|
|
140
|
+
row("Instructions", found.length ? c.value(found.join(", ")) : c.dim("none"));
|
|
141
|
+
row("Local tools", c.dim(LOCAL_TOOL_NAMES.join(" · ") + " (read-only)"));
|
|
142
|
+
row("Attached", ctx.config.get("projectContextPending") === true
|
|
143
|
+
? c.accent("yes — rides with your next message")
|
|
144
|
+
: c.dim("no · /context project --attach"));
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
line();
|
|
148
|
+
row("Project", c.dim("not scanned yet · /project"));
|
|
149
|
+
}
|
|
150
|
+
// ── What we still can't show ──────────────────────────────────────────────
|
|
151
|
+
line();
|
|
152
|
+
line(" " + c.dim("Live token window and health aren't exposed by the public API yet."));
|
|
153
|
+
line();
|
|
154
|
+
}
|
|
155
|
+
/** Fallback used when there's nothing to report at all. */
|
|
156
|
+
export function contextUnavailable() {
|
|
157
|
+
for (const l of emptyState("No context yet.", "Start a conversation and run /context again.")) {
|
|
158
|
+
line(l);
|
|
159
|
+
}
|
|
160
|
+
}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -2,6 +2,9 @@ import { ApiError } from "../services/api.js";
|
|
|
2
2
|
import { cliVersion } from "../services/meta.js";
|
|
3
3
|
import { glyph, heading, line } from "../services/output.js";
|
|
4
4
|
import { withSpinner } from "../services/spinner.js";
|
|
5
|
+
import { discoverRootWithoutGit, refreshWorkspace } from "../services/workspace.js";
|
|
6
|
+
import { isTrusted } from "../ui/trust.js";
|
|
7
|
+
import { COMMANDS_OPT_IN_ENV } from "../services/client-tools.js";
|
|
5
8
|
function row(status, label, detail) {
|
|
6
9
|
const g = status === "ok" ? glyph.ok : status === "warn" ? glyph.warn : glyph.err;
|
|
7
10
|
line(` ${g} ${label.padEnd(20)} ${detail}`);
|
|
@@ -31,22 +34,64 @@ export function registerDoctor(program, ctx) {
|
|
|
31
34
|
catch (err) {
|
|
32
35
|
row("err", "API reachable", err instanceof ApiError ? err.message : "unreachable");
|
|
33
36
|
}
|
|
34
|
-
// 3)
|
|
37
|
+
// 3) Signed in?
|
|
35
38
|
if (!ctx.config.isAuthenticated) {
|
|
36
|
-
row("warn", "
|
|
39
|
+
row("warn", "Session", "not signed in — run `cos login`");
|
|
37
40
|
}
|
|
38
41
|
else {
|
|
39
|
-
row("ok", "
|
|
40
|
-
// 4)
|
|
42
|
+
row("ok", "Session", "present");
|
|
43
|
+
// 4) Session valid?
|
|
41
44
|
try {
|
|
42
|
-
const scope = await withSpinner("Verifying
|
|
43
|
-
row("ok", "
|
|
45
|
+
const scope = await withSpinner("Verifying session…", () => client.verify());
|
|
46
|
+
row("ok", "Session valid", `${scope.workspace.name} / ${scope.project.name}`);
|
|
44
47
|
}
|
|
45
48
|
catch (err) {
|
|
46
|
-
row("err", "
|
|
49
|
+
row("err", "Session valid", err instanceof ApiError ? `${err.message} (${err.code})` : "failed");
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
|
-
// 5)
|
|
52
|
+
// 5) Local workspace. This is where the DETAIL of a failed repository
|
|
53
|
+
// read belongs — the banner and /repo say "unavailable" and move on,
|
|
54
|
+
// because a person opening a shell does not want a Git error, but a
|
|
55
|
+
// person running diagnostics does.
|
|
56
|
+
// Diagnostics never prompt; an untrusted folder is reported, not entered.
|
|
57
|
+
const trustRoot = discoverRootWithoutGit();
|
|
58
|
+
if (process.stdin.isTTY && !isTrusted(ctx.config, trustRoot) && !isTrusted(ctx.config)) {
|
|
59
|
+
row("warn", "Repository", "not checked — this folder is not trusted (open `cos` here to trust it)");
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const ws = refreshWorkspace();
|
|
63
|
+
row("ok", "Directory", ws.cwd);
|
|
64
|
+
if (!ws.repository.gitAvailable) {
|
|
65
|
+
row("warn", "Git", "not found on PATH");
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
row("ok", "Git", "available");
|
|
69
|
+
}
|
|
70
|
+
if (ws.repository.state === "detected") {
|
|
71
|
+
row("ok", "Repository", ws.repository.root ?? "detected");
|
|
72
|
+
}
|
|
73
|
+
else if (ws.repository.state === "unavailable") {
|
|
74
|
+
row("warn", "Repository", ws.repository.error ?? "unavailable");
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
row("ok", "Repository", "not a repository");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// 6) Local capabilities. Reading and file changes follow folder trust;
|
|
81
|
+
// running commands additionally needs an explicit opt-in, so say which
|
|
82
|
+
// of those is missing rather than just "off".
|
|
83
|
+
const trusted = isTrusted(ctx.config, trustRoot) || isTrusted(ctx.config);
|
|
84
|
+
row(trusted ? "ok" : "warn", "Folder trust", trusted ? `trusted: ${trustRoot}` : `not trusted: ${trustRoot}`);
|
|
85
|
+
const optedIn = process.env[COMMANDS_OPT_IN_ENV] === "1";
|
|
86
|
+
const commandState = !optedIn
|
|
87
|
+
? `off — set ${COMMANDS_OPT_IN_ENV}=1 in this terminal to offer them`
|
|
88
|
+
: process.platform !== "win32"
|
|
89
|
+
? "off — local commands are Windows-only for now"
|
|
90
|
+
: !trusted
|
|
91
|
+
? "off — this folder is not trusted"
|
|
92
|
+
: "on for this terminal — every command still needs your approval";
|
|
93
|
+
row(optedIn && trusted && process.platform === "win32" ? "ok" : "warn", "Local commands", commandState);
|
|
94
|
+
// 7) Versions
|
|
50
95
|
row("ok", "CLI version", cliVersion());
|
|
51
96
|
row("ok", "API version", apiVersion);
|
|
52
97
|
line();
|
package/dist/commands/files.js
CHANGED
|
@@ -1,33 +1,94 @@
|
|
|
1
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";
|
|
2
4
|
import { c } from "../ui/colors.js";
|
|
5
|
+
import { ensureWorkspaceTrust } from "../ui/trust.js";
|
|
3
6
|
import { emptyState, sectionHeader, twoCol } from "../ui/ui.js";
|
|
4
|
-
/**
|
|
5
|
-
* `cos files` — list files uploaded from this machine.
|
|
6
|
-
*
|
|
7
|
-
* NOTE: the public API has no "list files" endpoint yet, so this reflects the
|
|
8
|
-
* CLI's own record of recent uploads (kept in config). It is purely a local
|
|
9
|
-
* convenience view and duplicates no server logic.
|
|
10
|
-
*/
|
|
11
7
|
export function registerFiles(program, ctx) {
|
|
12
8
|
program
|
|
13
9
|
.command("files")
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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();
|
|
21
75
|
return;
|
|
22
76
|
}
|
|
23
|
-
|
|
24
|
-
line(sectionHeader(`Files (${uploads.length})`));
|
|
25
|
-
const rows = uploads.map((f) => [
|
|
26
|
-
f.filename,
|
|
27
|
-
`${f.file_type} · ${timeAgo(f.uploaded_at)} · ${f.file_id.slice(0, 8)}`
|
|
28
|
-
]);
|
|
29
|
-
for (const l of twoCol(rows, c.value, c.dim))
|
|
77
|
+
for (const l of emptyState("No uploaded files yet.", "Upload one with", "/upload <file>")) {
|
|
30
78
|
line(l);
|
|
31
|
-
|
|
32
|
-
|
|
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);
|
|
33
94
|
}
|
package/dist/commands/help.js
CHANGED
|
@@ -13,7 +13,8 @@ export function registerHelp(program, _ctx) {
|
|
|
13
13
|
const item = (cmd, desc) => line(` ${chalk.cyan(cmd.padEnd(26))} ${chalk.dim(desc)}`);
|
|
14
14
|
line("\n" + chalk.bold.cyan(" Carrier OS CLI") + chalk.dim(" — developer workflow\n"));
|
|
15
15
|
line(chalk.bold(" Getting started"));
|
|
16
|
-
item("cos login", "
|
|
16
|
+
item("cos login", "sign in through your browser");
|
|
17
|
+
item("cos workspace use", "switch workspace · cos project use");
|
|
17
18
|
item("cos doctor", "verify configuration & connectivity");
|
|
18
19
|
item("cos whoami", "show workspace / project / account");
|
|
19
20
|
line("\n" + chalk.bold(" Chat"));
|
|
@@ -21,6 +22,7 @@ export function registerHelp(program, _ctx) {
|
|
|
21
22
|
item("cos chat --mode code", "chat in a specific Carrier mode");
|
|
22
23
|
item("cos modes", "list Carrier modes (behavior)");
|
|
23
24
|
item("cos models", "list provider models (GPT, Grok, …)");
|
|
25
|
+
item("/btw <question>", "side question — not added to the conversation");
|
|
24
26
|
line("\n" + chalk.bold(" Sessions"));
|
|
25
27
|
item("cos sessions", "list conversations");
|
|
26
28
|
item("cos session use [id]", "switch active session");
|