@carrieros/cli 0.2.0 → 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 +170 -64
- 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 +81 -15
- package/dist/commands/context.js +200 -0
- package/dist/commands/doctor.js +63 -3
- 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/logout.js +1 -0
- 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/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 +9 -6
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +224 -65
- package/dist/commands/settings.js +94 -0
- package/dist/commands/update.js +229 -0
- package/dist/commands/upload.js +204 -31
- package/dist/commands/usage.js +213 -17
- package/dist/commands/whoami.js +12 -9
- package/dist/ide/editor-context.js +275 -0
- package/dist/ide/ide-session.js +355 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +26 -1
- package/dist/services/api.js +315 -15
- 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 +352 -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 +311 -24
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +296 -23
- package/dist/services/device-auth.js +72 -35
- 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 +55 -17
- package/dist/services/meta.js +3 -1
- 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 +5 -2
- package/dist/services/packaged-update.js +403 -0
- package/dist/services/packaged.js +39 -0
- package/dist/services/permission-mode.js +60 -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/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 +1297 -59
- package/dist/shell/shell-commands.js +243 -12
- package/dist/shell/shell-prompt.js +94 -11
- package/dist/shell/shell-renderer.js +8 -20
- package/dist/shell/shell-router.js +19 -3
- package/dist/shell/shell.js +252 -22
- package/dist/shell/task-context-view.js +40 -0
- package/dist/types/index.js +3 -1
- 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 +31 -48
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +334 -0
- package/dist/ui/chat-renderer.js +207 -14
- package/dist/ui/colors.js +12 -8
- package/dist/ui/command-details.js +11 -0
- package/dist/ui/command-filter.js +26 -5
- package/dist/ui/command-palette.js +44 -14
- package/dist/ui/command-registry.js +92 -10
- package/dist/ui/command-review.js +187 -0
- package/dist/ui/composer-layout.js +48 -1
- package/dist/ui/conversation.js +450 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +4 -2
- 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 +19 -11
- package/dist/ui/select.js +191 -29
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/task-context-card.js +99 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/trust.js +88 -0
- package/dist/ui/ui.js +27 -1
- package/package.json +18 -4
- 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, loadFastModel } 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,31 +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")
|
|
17
|
-
.action(async (opts) => {
|
|
18
|
-
//
|
|
19
|
-
// an explicit -m flag overrides it for this run.
|
|
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.
|
|
20
25
|
if (opts.mode)
|
|
21
26
|
ctx.config.set("mode", opts.mode);
|
|
22
|
-
else
|
|
23
|
-
ctx.setSessionMode("general");
|
|
24
27
|
if (opts.model !== undefined)
|
|
25
28
|
ctx.config.set("model", opts.model === "auto" ? "" : opts.model);
|
|
26
29
|
// Chat type defaults to Carrier Chat (the persisted default is carrier);
|
|
27
30
|
// --standard opts into a plain chat for this run onward.
|
|
28
31
|
if (opts.standard)
|
|
29
32
|
ctx.setChatType("standard");
|
|
30
|
-
|
|
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);
|
|
31
37
|
});
|
|
32
38
|
}
|
|
33
|
-
export async function runChat(ctx) {
|
|
39
|
+
export async function runChat(ctx, initialMessage) {
|
|
34
40
|
const client = ctx.requireAuth();
|
|
35
41
|
// Preload modes + models so the banner can show friendly labels (best-effort).
|
|
36
|
-
await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => [])]);
|
|
42
|
+
await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => []), loadFastModel(client)]);
|
|
37
43
|
printBanner(ctx.config.get("scope"), modeLabelShort(ctx), modelLabelShort(ctx));
|
|
38
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
|
+
}
|
|
39
50
|
for (;;) {
|
|
40
51
|
let message;
|
|
41
52
|
try {
|
|
@@ -59,14 +70,33 @@ export async function runChat(ctx) {
|
|
|
59
70
|
printSlashHelp();
|
|
60
71
|
continue;
|
|
61
72
|
}
|
|
62
|
-
if (cmdWord === "/new"
|
|
63
|
-
ctx.
|
|
64
|
-
|
|
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);
|
|
65
85
|
continue;
|
|
66
86
|
}
|
|
67
87
|
if (cmdWord === "/session") {
|
|
68
|
-
|
|
69
|
-
|
|
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);
|
|
70
100
|
continue;
|
|
71
101
|
}
|
|
72
102
|
if (cmdWord === "/chat") {
|
|
@@ -96,6 +126,31 @@ export async function runChat(ctx) {
|
|
|
96
126
|
await setModel(ctx, client, argStr);
|
|
97
127
|
continue;
|
|
98
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
|
+
await setFast(ctx, argStr, client);
|
|
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
|
+
}
|
|
99
154
|
await chatTurn(ctx, client, message);
|
|
100
155
|
}
|
|
101
156
|
}
|
|
@@ -108,7 +163,18 @@ function printSlashHelp() {
|
|
|
108
163
|
line(` ${chalk.cyan("/mode <id>")} switch Carrier mode (e.g. /mode code)`);
|
|
109
164
|
line(` ${chalk.cyan("/models")} list provider models (GPT, Grok, …)`);
|
|
110
165
|
line(` ${chalk.cyan("/model <id>")} set model override (e.g. gpt-5.5), or /model auto`);
|
|
111
|
-
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`);
|
|
112
178
|
line(` ${chalk.cyan("/session")} show the current session id`);
|
|
113
179
|
line(` ${chalk.cyan("/help")} show this help`);
|
|
114
180
|
line(` ${chalk.cyan("/exit")} leave the chat`);
|
|
@@ -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
|
+
}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { ApiError } from "../services/api.js";
|
|
2
3
|
import { cliVersion } from "../services/meta.js";
|
|
4
|
+
import { findPrebuiltHelper } from "../services/helper-bin.js";
|
|
5
|
+
import { isPackaged, isSignedRelease } from "../services/packaged.js";
|
|
3
6
|
import { glyph, heading, line } from "../services/output.js";
|
|
4
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 { executionContract } from "../services/execution-platform.js";
|
|
5
12
|
function row(status, label, detail) {
|
|
6
13
|
const g = status === "ok" ? glyph.ok : status === "warn" ? glyph.warn : glyph.err;
|
|
7
14
|
line(` ${g} ${label.padEnd(20)} ${detail}`);
|
|
@@ -18,6 +25,16 @@ export function registerDoctor(program, ctx) {
|
|
|
18
25
|
const client = ctx.client();
|
|
19
26
|
const apiUrl = ctx.config.get("apiUrl") ?? "—";
|
|
20
27
|
heading("Carrier OS — diagnostics");
|
|
28
|
+
// 0) Installation — only the packaged .exe has one to check. A helper that
|
|
29
|
+
// fails its baked hash is reported here rather than discovered mid-login.
|
|
30
|
+
if (isPackaged()) {
|
|
31
|
+
row("ok", "Installation", `v${cliVersion()} · ${path.dirname(process.execPath)}`);
|
|
32
|
+
row(isSignedRelease() ? "ok" : "warn", "Build", isSignedRelease() ? "signed release" : "unsigned build");
|
|
33
|
+
for (const helper of ["cos-dpapi", "cos-job-runner"]) {
|
|
34
|
+
const found = findPrebuiltHelper(helper);
|
|
35
|
+
row(found ? "ok" : "err", helper, found ? "verified" : "missing or damaged — reinstall Carrier OS");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
21
38
|
// 1) Configuration
|
|
22
39
|
row("ok", "Configuration", `${ctx.config.file}`);
|
|
23
40
|
row("ok", "Endpoint", apiUrl);
|
|
@@ -26,7 +43,7 @@ export function registerDoctor(program, ctx) {
|
|
|
26
43
|
try {
|
|
27
44
|
const health = await withSpinner("Pinging API…", () => client.health());
|
|
28
45
|
apiVersion = health.version;
|
|
29
|
-
row("ok", "API reachable",
|
|
46
|
+
row("ok", "API reachable", [health.status, health.version, health.environment].filter(Boolean).join(" · "));
|
|
30
47
|
}
|
|
31
48
|
catch (err) {
|
|
32
49
|
row("err", "API reachable", err instanceof ApiError ? err.message : "unreachable");
|
|
@@ -40,13 +57,56 @@ export function registerDoctor(program, ctx) {
|
|
|
40
57
|
// 4) Session valid?
|
|
41
58
|
try {
|
|
42
59
|
const scope = await withSpinner("Verifying session…", () => client.verify());
|
|
43
|
-
row("ok", "Session valid",
|
|
60
|
+
row("ok", "Session valid", scope.user?.email ?? "CLI device session");
|
|
44
61
|
}
|
|
45
62
|
catch (err) {
|
|
46
63
|
row("err", "Session valid", err instanceof ApiError ? `${err.message} (${err.code})` : "failed");
|
|
47
64
|
}
|
|
48
65
|
}
|
|
49
|
-
// 5)
|
|
66
|
+
// 5) Local workspace. This is where the DETAIL of a failed repository
|
|
67
|
+
// read belongs — the banner and /repo say "unavailable" and move on,
|
|
68
|
+
// because a person opening a shell does not want a Git error, but a
|
|
69
|
+
// person running diagnostics does.
|
|
70
|
+
// Diagnostics never prompt; an untrusted folder is reported, not entered.
|
|
71
|
+
const trustRoot = discoverRootWithoutGit();
|
|
72
|
+
if (process.stdin.isTTY && !isTrusted(ctx.config, trustRoot) && !isTrusted(ctx.config)) {
|
|
73
|
+
row("warn", "Repository", "not checked — this folder is not trusted (open `cos` here to trust it)");
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const ws = refreshWorkspace();
|
|
77
|
+
row("ok", "Directory", ws.cwd);
|
|
78
|
+
if (!ws.repository.gitAvailable) {
|
|
79
|
+
row("warn", "Git", "not found on PATH");
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
row("ok", "Git", "available");
|
|
83
|
+
}
|
|
84
|
+
if (ws.repository.state === "detected") {
|
|
85
|
+
row("ok", "Repository", ws.repository.root ?? "detected");
|
|
86
|
+
}
|
|
87
|
+
else if (ws.repository.state === "unavailable") {
|
|
88
|
+
row("warn", "Repository", ws.repository.error ?? "unavailable");
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
row("ok", "Repository", "not a repository");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// 6) Local capabilities. Reading and file changes follow folder trust;
|
|
95
|
+
// running commands additionally needs an explicit opt-in, so say which
|
|
96
|
+
// of those is missing rather than just "off".
|
|
97
|
+
const trusted = isTrusted(ctx.config, trustRoot) || isTrusted(ctx.config);
|
|
98
|
+
row(trusted ? "ok" : "warn", "Folder trust", trusted ? `trusted: ${trustRoot}` : `not trusted: ${trustRoot}`);
|
|
99
|
+
// The same check the shell uses to offer run_command, so the two agree
|
|
100
|
+
// on every platform (Windows Job Object; macOS/Linux isolated runtime).
|
|
101
|
+
const commands = localCommandsState(ctx, true);
|
|
102
|
+
const runtime = executionContract().backend === "docker-engine-v1" ? "isolated Linux container" : "Windows Job Object";
|
|
103
|
+
const commandState = !commands.enabled
|
|
104
|
+
? `off — /settings commands on, or set ${COMMANDS_OPT_IN_ENV}=1 in this terminal`
|
|
105
|
+
: commands.blockedBy
|
|
106
|
+
? `not active — ${commands.blockedBy}`
|
|
107
|
+
: `on (${runtime}) — every command still needs your approval`;
|
|
108
|
+
row(commands.enabled && !commands.blockedBy ? "ok" : "warn", "Local commands", commandState);
|
|
109
|
+
// 7) Versions
|
|
50
110
|
row("ok", "CLI version", cliVersion());
|
|
51
111
|
row("ok", "API version", apiVersion);
|
|
52
112
|
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
|
@@ -22,6 +22,7 @@ export function registerHelp(program, _ctx) {
|
|
|
22
22
|
item("cos chat --mode code", "chat in a specific Carrier mode");
|
|
23
23
|
item("cos modes", "list Carrier modes (behavior)");
|
|
24
24
|
item("cos models", "list provider models (GPT, Grok, …)");
|
|
25
|
+
item("/btw <question>", "side question — not added to the conversation");
|
|
25
26
|
line("\n" + chalk.bold(" Sessions"));
|
|
26
27
|
item("cos sessions", "list conversations");
|
|
27
28
|
item("cos session use [id]", "switch active session");
|