@carrieros/cli 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -57
- package/dist/commands/attach.js +45 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +80 -14
- package/dist/commands/context.js +160 -0
- package/dist/commands/doctor.js +46 -1
- package/dist/commands/files.js +84 -23
- package/dist/commands/help.js +1 -0
- package/dist/commands/history.js +88 -23
- package/dist/commands/login.js +31 -7
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +39 -3
- package/dist/commands/modes.js +4 -1
- package/dist/commands/project.js +106 -0
- package/dist/commands/repo.js +146 -0
- package/dist/commands/repos.js +61 -0
- package/dist/commands/review.js +92 -0
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +219 -65
- package/dist/commands/settings.js +87 -0
- package/dist/commands/update.js +159 -0
- package/dist/commands/upload.js +204 -31
- package/dist/commands/usage.js +212 -16
- package/dist/ide/editor-context.js +172 -0
- package/dist/ide/ide-session.js +94 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +26 -1
- package/dist/services/api.js +140 -6
- package/dist/services/chat-stream.js +145 -0
- package/dist/services/checkpoints.js +116 -0
- package/dist/services/client-tools.js +260 -0
- package/dist/services/command-coordinator.js +200 -0
- package/dist/services/command-policy.js +404 -0
- package/dist/services/config.js +247 -22
- package/dist/services/context.js +265 -20
- package/dist/services/device-auth.js +42 -30
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -0
- package/dist/services/file-detect.js +104 -0
- package/dist/services/file-resolver.js +199 -0
- package/dist/services/file-upload.js +126 -0
- package/dist/services/git-tools.js +248 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +64 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/job-helper.js +307 -0
- package/dist/services/local-files.js +517 -0
- package/dist/services/local-tools.js +432 -0
- package/dist/services/login-flow.js +15 -8
- package/dist/services/meta.js +3 -1
- package/dist/services/mutation-coordinator.js +161 -0
- package/dist/services/mutations.js +493 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +5 -2
- package/dist/services/packaged.js +24 -0
- package/dist/services/process-runner.js +406 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/secure-store.js +197 -0
- package/dist/services/session-resolver.js +108 -0
- package/dist/services/sia.js +51 -0
- package/dist/services/update.js +286 -0
- package/dist/services/workspace-registry.js +309 -0
- package/dist/services/workspace.js +573 -0
- package/dist/shell/shell-chat.js +1028 -57
- package/dist/shell/shell-commands.js +200 -11
- package/dist/shell/shell-prompt.js +81 -8
- package/dist/shell/shell-renderer.js +7 -19
- package/dist/shell/shell-router.js +19 -3
- package/dist/shell/shell.js +185 -17
- package/dist/types/index.js +3 -1
- package/dist/ui/approval.js +81 -0
- package/dist/ui/banner.js +39 -0
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +87 -0
- package/dist/ui/chat-renderer.js +206 -13
- package/dist/ui/colors.js +4 -0
- package/dist/ui/command-filter.js +26 -5
- package/dist/ui/command-palette.js +17 -4
- package/dist/ui/command-registry.js +84 -9
- package/dist/ui/command-review.js +138 -0
- package/dist/ui/composer-layout.js +41 -0
- package/dist/ui/conversation.js +398 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +3 -1
- package/dist/ui/markdown.js +63 -9
- package/dist/ui/message.js +14 -31
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +1 -1
- package/dist/ui/select.js +185 -29
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/trust.js +93 -0
- package/dist/ui/ui.js +4 -1
- package/package.json +13 -2
- package/dist/ui/activity.js +0 -77
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { c } from "./colors.js";
|
|
2
|
+
import { MARGIN, contentWidth } from "./composer-layout.js";
|
|
3
|
+
import { clip, stripControl, wrapText } from "./conversation.js";
|
|
4
|
+
/**
|
|
5
|
+
* How a proposed file change is shown before anyone approves it.
|
|
6
|
+
*
|
|
7
|
+
* Compact header, then the diff — committed to the transcript rather than drawn
|
|
8
|
+
* in the prompt, so it stays on screen as the record of what was approved, and
|
|
9
|
+
* a long one can be scrolled back to. The limits that decide whether a change
|
|
10
|
+
* is reviewable at all live in the mutation layer, not here.
|
|
11
|
+
*/
|
|
12
|
+
const ACTION = {
|
|
13
|
+
create_file: "create",
|
|
14
|
+
write_file: "overwrite",
|
|
15
|
+
edit_file: "edit",
|
|
16
|
+
delete_file: "delete",
|
|
17
|
+
revert_change: "revert"
|
|
18
|
+
};
|
|
19
|
+
const RISK = { low: "low risk", medium: "medium risk", high: "high risk" };
|
|
20
|
+
export function riskOf(plan) {
|
|
21
|
+
if (plan.name === "delete_file")
|
|
22
|
+
return "high";
|
|
23
|
+
if (plan.name === "create_file")
|
|
24
|
+
return "low";
|
|
25
|
+
return "medium";
|
|
26
|
+
}
|
|
27
|
+
const safe = stripControl;
|
|
28
|
+
const INDENT = MARGIN + " ";
|
|
29
|
+
const inner = () => Math.max(24, contentWidth() - 4);
|
|
30
|
+
function planLines(plan, index, total) {
|
|
31
|
+
const risk = riskOf(plan);
|
|
32
|
+
const riskText = risk === "high" ? c.err(RISK[risk]) : risk === "medium" ? c.warn(RISK[risk]) : c.dim(RISK[risk]);
|
|
33
|
+
const counter = total > 1 ? c.dim(`${index + 1}/${total} `) : "";
|
|
34
|
+
const out = [
|
|
35
|
+
INDENT +
|
|
36
|
+
counter +
|
|
37
|
+
c.file(clip(plan.rel, Math.max(16, inner() - 28))) +
|
|
38
|
+
c.dim(` +${plan.diff.added} −${plan.diff.removed} · `) +
|
|
39
|
+
riskText
|
|
40
|
+
];
|
|
41
|
+
// WHICH repository, above the path — a change can now target a repository
|
|
42
|
+
// that is not the active one, so the name is part of what is being approved
|
|
43
|
+
// rather than context the user is assumed to be holding.
|
|
44
|
+
if (plan.repositoryName) {
|
|
45
|
+
out.unshift(INDENT + c.dim("Repository ") + c.value(clip(plan.repositoryName, Math.max(12, inner() - 14))));
|
|
46
|
+
}
|
|
47
|
+
if (plan.reverts)
|
|
48
|
+
out.push(INDENT + c.dim(`undoes ${plan.reverts}`));
|
|
49
|
+
for (const [i, l] of wrapText(safe(plan.reason), inner() - 8).entries()) {
|
|
50
|
+
out.push(INDENT + c.dim(i === 0 ? "Why " : " ") + c.dim(l));
|
|
51
|
+
}
|
|
52
|
+
out.push("");
|
|
53
|
+
if (plan.name === "delete_file") {
|
|
54
|
+
out.push(INDENT + c.err(`The whole file (${plan.diff.removed} lines) will be removed.`));
|
|
55
|
+
}
|
|
56
|
+
for (const raw of plan.unified.split("\n")) {
|
|
57
|
+
const l = safe(raw);
|
|
58
|
+
if (l.startsWith("@@"))
|
|
59
|
+
out.push(INDENT + c.accent(l));
|
|
60
|
+
else if (l.startsWith("+++") || l.startsWith("---"))
|
|
61
|
+
continue; // the path is in the header
|
|
62
|
+
else if (l.startsWith("+"))
|
|
63
|
+
out.push(INDENT + c.ok(l));
|
|
64
|
+
else if (l.startsWith("-"))
|
|
65
|
+
out.push(INDENT + c.err(l));
|
|
66
|
+
else
|
|
67
|
+
out.push(INDENT + c.dim(l));
|
|
68
|
+
}
|
|
69
|
+
if (plan.diff.hunks.length === 0)
|
|
70
|
+
out.push(INDENT + c.dim("(no line changes)"));
|
|
71
|
+
out.push("");
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
export function renderGroup(plans) {
|
|
75
|
+
const verb = plans.length === 1 ? ACTION[plans[0].name] ?? "change" : "change";
|
|
76
|
+
const what = plans.length === 1 ? `${verb}:` : `change ${plans.length} files:`;
|
|
77
|
+
return [
|
|
78
|
+
"",
|
|
79
|
+
MARGIN + c.warn("◆") + " " + c.title(`Carrier OS wants to ${what}`),
|
|
80
|
+
"",
|
|
81
|
+
...plans.flatMap((p, i) => planLines(p, i, plans.length))
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
/** One line per applied or refused change, for after the decision. */
|
|
85
|
+
export function renderChangeSummary(lines) {
|
|
86
|
+
return lines.map((l) => MARGIN + (l.includes("✓") ? c.ok(l.trim()) : c.warn(l.trim())));
|
|
87
|
+
}
|
package/dist/ui/chat-renderer.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { line } from "../services/output.js";
|
|
2
2
|
import { sleep } from "../services/spinner.js";
|
|
3
3
|
import { c } from "./colors.js";
|
|
4
|
+
import { contentWidth } from "./composer-layout.js";
|
|
4
5
|
import { renderMarkdown } from "./markdown.js";
|
|
5
6
|
import { renderUserMessage } from "./message.js";
|
|
6
7
|
import { thinking } from "./spinner.js";
|
|
@@ -34,9 +35,66 @@ const THINKING_PHRASES = [
|
|
|
34
35
|
];
|
|
35
36
|
let phraseIndex = 0;
|
|
36
37
|
let tipIndex = 0;
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Completion footers, rotated like the thinking phrases so a long session
|
|
40
|
+
* doesn't read as the same line stamped over and over.
|
|
41
|
+
*
|
|
42
|
+
* Each entry carries its own preposition — "Baked FOR 3s" but "Generated IN
|
|
43
|
+
* 3s" — because a shared connector makes half the list ungrammatical. "in"
|
|
44
|
+
* suits verbs about producing a result, "for" verbs about time spent.
|
|
45
|
+
*/
|
|
46
|
+
const COMPLETION_PHRASES = [
|
|
47
|
+
"Generated in",
|
|
48
|
+
"Brewed for",
|
|
49
|
+
"Baked for",
|
|
50
|
+
"Churned for",
|
|
51
|
+
"Simmered for",
|
|
52
|
+
"Percolated for",
|
|
53
|
+
"Distilled in",
|
|
54
|
+
"Composed in",
|
|
55
|
+
"Crafted in",
|
|
56
|
+
"Forged in",
|
|
57
|
+
"Assembled in",
|
|
58
|
+
"Synthesized in"
|
|
59
|
+
];
|
|
60
|
+
let completionIndex = 0;
|
|
61
|
+
/** Completion footer text, Claude-style: "Brewed for 1.2s". Advances the
|
|
62
|
+
* rotation, so call it once per finished turn. */
|
|
63
|
+
function completionLabel(seconds, spend) {
|
|
64
|
+
const phrase = COMPLETION_PHRASES[completionIndex % COMPLETION_PHRASES.length];
|
|
65
|
+
completionIndex++;
|
|
66
|
+
return `${phrase} ${Math.max(0.1, seconds).toFixed(1)}s${spendSuffix(spend)}`;
|
|
67
|
+
}
|
|
68
|
+
/** Format a number with thousands separators, trimming pointless decimals. */
|
|
69
|
+
const num = (n, dp = 0) => n.toLocaleString("en-US", { minimumFractionDigits: dp, maximumFractionDigits: dp });
|
|
70
|
+
/**
|
|
71
|
+
* " · 412.6 credits left"
|
|
72
|
+
*
|
|
73
|
+
* Balance only. Tokens and dollar cost are still returned by the API (and used
|
|
74
|
+
* for request logging), but three numbers on a completion line is a bill, not a
|
|
75
|
+
* status — the one that answers "can I keep going?" is what's left.
|
|
76
|
+
*
|
|
77
|
+
* Omitted entirely when the API didn't send it, rather than shown as 0: an
|
|
78
|
+
* older API build has no balance field, and a wrong number is worse than none
|
|
79
|
+
* when it's money.
|
|
80
|
+
*/
|
|
81
|
+
export function spendSuffix(spend) {
|
|
82
|
+
// An unlimited account's balance is a running total of real spend, not a
|
|
83
|
+
// limit — so "3,600 credits overdrawn" is true and alarming and answers the
|
|
84
|
+
// wrong question. What such an account wants to know is what THIS session
|
|
85
|
+
// cost. The balance itself is unchanged and still shown by /usage.
|
|
86
|
+
if (spend?.unlimited === true) {
|
|
87
|
+
return typeof spend.sessionSpent === "number"
|
|
88
|
+
? ` · Unlimited · session ${num(spend.sessionSpent, 2)} credits`
|
|
89
|
+
: " · Unlimited";
|
|
90
|
+
}
|
|
91
|
+
const credits = spend?.creditsRemaining;
|
|
92
|
+
if (typeof credits !== "number")
|
|
93
|
+
return "";
|
|
94
|
+
// A negative balance is an overdraft, not "-556 left" — say what it is.
|
|
95
|
+
return credits < 0
|
|
96
|
+
? ` · ${num(Math.abs(credits), 1)} credits overdrawn`
|
|
97
|
+
: ` · ${num(credits, 1)} credits left`;
|
|
40
98
|
}
|
|
41
99
|
// Rotating tips shown beneath the spinner while Carrier is responding — a chance
|
|
42
100
|
// to surface a handy shortcut, the way Claude Code does.
|
|
@@ -102,7 +160,10 @@ export function startThinkingLive(live) {
|
|
|
102
160
|
// SSE), so we surface it progressively — word by word at a natural cadence — so
|
|
103
161
|
// it reads like Claude typing the response in, rather than one instant block.
|
|
104
162
|
const STREAM_DELAY = 22; // ms between words
|
|
105
|
-
|
|
163
|
+
// SGR colour runs plus OSC strings (\x1b] … BEL / ST). OSC carries a payload —
|
|
164
|
+
// a hyperlink's URL, a title — that occupies no columns, so a regex that only
|
|
165
|
+
// knows SGR silently over-counts the width of any line containing one.
|
|
166
|
+
const ANSI = /\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b\[[0-9;]*m/g;
|
|
106
167
|
const stripAnsi = (s) => s.replace(ANSI, "");
|
|
107
168
|
/** Styled prefix of `s` showing its first `n` visible characters (ANSI kept). */
|
|
108
169
|
function ansiSlice(s, n) {
|
|
@@ -169,7 +230,7 @@ export async function streamAssistantSticky(sticky, text) {
|
|
|
169
230
|
}
|
|
170
231
|
sticky.scroll(); // trailing blank
|
|
171
232
|
}
|
|
172
|
-
/** Completion footer on the scroll region: ●
|
|
233
|
+
/** Completion footer on the scroll region: ● Brewed for 1.2s */
|
|
173
234
|
export function renderCompleteSticky(sticky, seconds) {
|
|
174
235
|
sticky.scroll();
|
|
175
236
|
sticky.setLine(MARGIN + c.dim(`● ${completionLabel(seconds)}`));
|
|
@@ -199,9 +260,9 @@ export async function streamAssistantLive(live, text) {
|
|
|
199
260
|
}
|
|
200
261
|
live.commit([""]); // single trailing blank
|
|
201
262
|
}
|
|
202
|
-
/** Dim completion footer committed above the pinned bar: ●
|
|
203
|
-
export function renderCompleteLive(live, seconds) {
|
|
204
|
-
live.commit([MARGIN + c.dim(`● ${completionLabel(seconds)}`), ""]);
|
|
263
|
+
/** Dim completion footer committed above the pinned bar: ● Brewed for 1.2s */
|
|
264
|
+
export function renderCompleteLive(live, seconds, spend) {
|
|
265
|
+
live.commit([MARGIN + c.dim(`● ${completionLabel(seconds, spend)}`), ""]);
|
|
205
266
|
}
|
|
206
267
|
/** Error block committed above the pinned bar. */
|
|
207
268
|
export function renderErrorLive(live, title, detail, hintCmd) {
|
|
@@ -239,15 +300,147 @@ export async function streamAssistant(text) {
|
|
|
239
300
|
process.stdout.write("\x1b[?25h");
|
|
240
301
|
line(); // single trailing blank
|
|
241
302
|
}
|
|
242
|
-
/** Dim completion footer: ●
|
|
243
|
-
export function renderComplete(seconds) {
|
|
244
|
-
line(MARGIN + c.dim(`● ${completionLabel(seconds)}`));
|
|
303
|
+
/** Dim completion footer: ● Brewed for 1.2s */
|
|
304
|
+
export function renderComplete(seconds, spend) {
|
|
305
|
+
line(MARGIN + c.dim(`● ${completionLabel(seconds, spend)}`));
|
|
306
|
+
line();
|
|
307
|
+
}
|
|
308
|
+
// ── Web-search citations ─────────────────────────────────────────────────────
|
|
309
|
+
// The web app renders these as hoverable chips. A terminal can't hover, so the
|
|
310
|
+
// list is numbered and the numbers are addressable: /open 2, /sources.
|
|
311
|
+
//
|
|
312
|
+
// Publisher leads, not the URL. Raw article URLs are long, visually noisy, and
|
|
313
|
+
// (for Google News results) not even human-readable — so the domain is shown
|
|
314
|
+
// bare and the full URL is attached as a terminal hyperlink where that works.
|
|
315
|
+
/** Citations shown inline under an answer before collapsing into a count. */
|
|
316
|
+
const INLINE_SOURCES = 4;
|
|
317
|
+
/** Indent under the "[n] " marker that title/domain lines sit at. */
|
|
318
|
+
const CITE_INDENT = " ";
|
|
319
|
+
/**
|
|
320
|
+
* Clip to the composer's content column.
|
|
321
|
+
*
|
|
322
|
+
* The screen engine writes one transcript line per terminal row and does no
|
|
323
|
+
* wrap accounting, so a line wider than the column steals a second row and
|
|
324
|
+
* shifts everything below it — which is how a URL tail ends up floating above
|
|
325
|
+
* the prompt. Titles and URLs are the only unbounded strings in the transcript,
|
|
326
|
+
* so they get clipped here. Plain text in, styled after, so this never has to
|
|
327
|
+
* count escape sequences.
|
|
328
|
+
*/
|
|
329
|
+
function fit(text, indent = CITE_INDENT.length) {
|
|
330
|
+
const max = Math.max(8, contentWidth() - indent);
|
|
331
|
+
return text.length <= max ? text : text.slice(0, max - 1) + "…";
|
|
332
|
+
}
|
|
333
|
+
/** Bare hostname for a citation — "bbc.com", never "www.bbc.com/path?utm=…". */
|
|
334
|
+
export function sourceDomain(s) {
|
|
335
|
+
try {
|
|
336
|
+
return new URL(s.url).hostname.replace(/^www\./, "");
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
return s.url;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/** Publisher name for a citation — the API's `source`, else the domain. */
|
|
343
|
+
export function sourceLabel(s) {
|
|
344
|
+
return s.source?.trim() || sourceDomain(s);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* One citation: publisher, then title, then domain — publisher first because
|
|
348
|
+
* that is what tells you whether to trust the line. `tail` carries the domain
|
|
349
|
+
* inline; the full list overrides it with the complete URL.
|
|
350
|
+
*/
|
|
351
|
+
function citation(s, i, tail) {
|
|
352
|
+
const marker = `[${i + 1}] `;
|
|
353
|
+
const head = `${MARGIN}${c.dim(`[${i + 1}]`)} ${c.value(fit(sourceLabel(s), marker.length))}`;
|
|
354
|
+
const tailLine = `${MARGIN}${CITE_INDENT}${c.dim(fit(tail))}`;
|
|
355
|
+
const title = s.title?.trim();
|
|
356
|
+
if (!title)
|
|
357
|
+
return [head, tailLine];
|
|
358
|
+
return [head, `${MARGIN}${CITE_INDENT}${c.dim(fit(title))}`, tailLine];
|
|
359
|
+
}
|
|
360
|
+
/** The compact block printed under an answer: first few, then a pointer. */
|
|
361
|
+
function sourceLines(sources) {
|
|
362
|
+
if (sources.length === 0)
|
|
363
|
+
return [];
|
|
364
|
+
const shown = sources.slice(0, INLINE_SOURCES);
|
|
365
|
+
const out = ["", MARGIN + c.dim(`Sources · ${sources.length}`), ""];
|
|
366
|
+
shown.forEach((s, i) => {
|
|
367
|
+
out.push(...citation(s, i, sourceDomain(s)));
|
|
368
|
+
out.push(""); // one blank between entries so the block scans as a list
|
|
369
|
+
});
|
|
370
|
+
const hidden = sources.length - shown.length;
|
|
371
|
+
if (hidden > 0)
|
|
372
|
+
out.push(`${MARGIN}${c.dim(`+ ${hidden} more · `)}${c.cmd("/sources")}`, "");
|
|
373
|
+
return out;
|
|
374
|
+
}
|
|
375
|
+
/** Numbered citation list printed under the answer. No-op without sources. */
|
|
376
|
+
export function renderSources(sources) {
|
|
377
|
+
for (const l of sourceLines(sources))
|
|
378
|
+
line(l);
|
|
379
|
+
}
|
|
380
|
+
/** Citation list committed above the pinned composer bar. */
|
|
381
|
+
export function renderSourcesLive(live, sources) {
|
|
382
|
+
const out = sourceLines(sources);
|
|
383
|
+
if (out.length)
|
|
384
|
+
live.commit(out);
|
|
385
|
+
}
|
|
386
|
+
/** The full list, every entry — `/sources`. Printed outside a turn. */
|
|
387
|
+
export function renderAllSources(sources, agoLabel) {
|
|
388
|
+
line();
|
|
389
|
+
line(MARGIN + c.title(`Sources · ${sources.length}`) + (agoLabel ? c.dim(` ${agoLabel}`) : ""));
|
|
245
390
|
line();
|
|
391
|
+
// The full list is where someone goes to copy a link, so the tail is the
|
|
392
|
+
// complete URL here even though the compact block deliberately hides it.
|
|
393
|
+
sources.forEach((s, i) => {
|
|
394
|
+
for (const l of citation(s, i, s.url))
|
|
395
|
+
line(l);
|
|
396
|
+
line();
|
|
397
|
+
});
|
|
398
|
+
line(MARGIN + c.dim("Open one with ") + c.cmd("/open <n>"));
|
|
399
|
+
line();
|
|
400
|
+
}
|
|
401
|
+
// ── Memory-engine markers ────────────────────────────────────────────────────
|
|
402
|
+
// The engine compresses a growing conversation on its own. The web draws two
|
|
403
|
+
// deliberately different marks and this mirrors that weighting: a snapshot is
|
|
404
|
+
// routine short-term housekeeping (muted, hairline rules), a restructure is a
|
|
405
|
+
// long-term rebuild that COSTS the account money (themed, heavier rule). Both
|
|
406
|
+
// carry the number you pass to `/memory <n>`.
|
|
407
|
+
function centred(inner, rule, char) {
|
|
408
|
+
const width = Math.max(20, contentWidth() - MARGIN.length);
|
|
409
|
+
const visible = inner.replace(ANSI, "").length;
|
|
410
|
+
const side = Math.max(2, Math.floor((width - visible - 2) / 2));
|
|
411
|
+
const bar = char.repeat(side);
|
|
412
|
+
return `${MARGIN}${rule(bar)} ${inner} ${rule(bar)}`;
|
|
413
|
+
}
|
|
414
|
+
/** `──── ⛁ Memory snapshot 3 · 229 tok ────` — understated, like the web. */
|
|
415
|
+
export function memoryMarkerLine(m) {
|
|
416
|
+
const n = m.number ?? "?";
|
|
417
|
+
const tok = m.tokens ? c.dim(` · ${m.tokens.toLocaleString()} tok`) : "";
|
|
418
|
+
const ref = m.index ? c.dim(` [${m.index}]`) : "";
|
|
419
|
+
if (m.failed) {
|
|
420
|
+
const label = c.warn(`! ${m.kind === "snapshot" ? "Snapshot" : "Restructure"} ${n} failed`);
|
|
421
|
+
return centred(label + ref, c.dim, "─");
|
|
422
|
+
}
|
|
423
|
+
if (m.kind === "restructure") {
|
|
424
|
+
// Themed and heavier — this one was billed.
|
|
425
|
+
return centred(c.brand(`⟐ Chat restructured v${n}`) + tok + ref, c.brand, "─");
|
|
426
|
+
}
|
|
427
|
+
return centred(c.dim(`⛁ Memory snapshot ${n}`) + tok + ref, c.dim, "─");
|
|
428
|
+
}
|
|
429
|
+
/** Completion footer for a turn that searched: ✓ Web search · 5 sources · 3.2s */
|
|
430
|
+
export function searchCompletionLine(sourceCount, seconds) {
|
|
431
|
+
const secs = seconds < 10 ? seconds.toFixed(1) : Math.round(seconds).toString();
|
|
432
|
+
const plural = sourceCount === 1 ? "source" : "sources";
|
|
433
|
+
return MARGIN + c.ok("✓") + c.dim(` Web search · ${sourceCount} ${plural} · ${secs}s`);
|
|
246
434
|
}
|
|
247
435
|
/** A premium error block: × Title / detail / hint. */
|
|
248
|
-
export function renderError(title, detail, hintCmd
|
|
436
|
+
export function renderError(title, detail, hintCmd,
|
|
437
|
+
/** "warn" for states the user can act on (out of credits) rather than
|
|
438
|
+
* failures — red reads as "something broke", which this isn't. */
|
|
439
|
+
tone = "error") {
|
|
440
|
+
const mark = tone === "warn" ? c.warn("⚠") : c.err("×");
|
|
441
|
+
const heading = tone === "warn" ? c.warn.bold(title) : c.err.bold(title);
|
|
249
442
|
line();
|
|
250
|
-
line(` ${
|
|
443
|
+
line(` ${mark} ${heading}`);
|
|
251
444
|
line();
|
|
252
445
|
line(" " + c.value(detail));
|
|
253
446
|
if (hintCmd) {
|
package/dist/ui/colors.js
CHANGED
|
@@ -43,6 +43,10 @@ export const c = {
|
|
|
43
43
|
// Command arguments
|
|
44
44
|
arg: chalk.green, // ids / values (mode, model)
|
|
45
45
|
file: chalk.yellow, // file paths
|
|
46
|
+
// SIA / clarification — deliberately not the yellow the turn-shape chips use,
|
|
47
|
+
// because it isn't one: Fast and HIPWR change how the answer is produced,
|
|
48
|
+
// while this changes the question before it's asked.
|
|
49
|
+
magic: chalk.magentaBright,
|
|
46
50
|
// Status
|
|
47
51
|
ok: chalk.green,
|
|
48
52
|
warn: chalk.yellow,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { byGroupThenRank,
|
|
1
|
+
import { byGroupThenRank, visibleCommands } from "./command-item.js";
|
|
2
2
|
import { THEME_COLORS, THEME_ORDER } from "./theme.js";
|
|
3
3
|
/** After `/color ` (or `/theme `), the palette suggests color values. */
|
|
4
4
|
const COLOR_ARG = /^\/(color|theme)\s+(.*)$/i;
|
|
@@ -23,9 +23,9 @@ export function filterCommands(query) {
|
|
|
23
23
|
}
|
|
24
24
|
const term = query.toLowerCase().replace(/^\//, "").trim();
|
|
25
25
|
if (!term)
|
|
26
|
-
return
|
|
26
|
+
return visibleCommands().sort(byGroupThenRank);
|
|
27
27
|
const scored = [];
|
|
28
|
-
for (const cmd of
|
|
28
|
+
for (const cmd of visibleCommands()) {
|
|
29
29
|
const idx = cmd.name.slice(1).toLowerCase().indexOf(term);
|
|
30
30
|
if (idx !== -1)
|
|
31
31
|
scored.push({ cmd, prefix: idx === 0 });
|
|
@@ -53,7 +53,7 @@ export function ghostCompletion(query) {
|
|
|
53
53
|
const term = query.toLowerCase().replace(/^\//, "");
|
|
54
54
|
if (!term)
|
|
55
55
|
return "";
|
|
56
|
-
const matches =
|
|
56
|
+
const matches = visibleCommands().filter((cmd) => cmd.name.slice(1).toLowerCase().startsWith(term)).sort((a, b) => a.rank - b.rank);
|
|
57
57
|
if (matches.length === 0)
|
|
58
58
|
return "";
|
|
59
59
|
return matches[0].name.slice(query.length);
|
|
@@ -64,8 +64,29 @@ export function ghostCompletion(query) {
|
|
|
64
64
|
* `/color ` → `[red|blue|green|…]`. Purely a hint (never accepted by Tab). Empty
|
|
65
65
|
* once a value is being typed, or when the command takes no listed options.
|
|
66
66
|
*/
|
|
67
|
+
/**
|
|
68
|
+
* True once the line is "a complete command, then its argument".
|
|
69
|
+
*
|
|
70
|
+
* From that point the palette must stop treating the line as a search — every
|
|
71
|
+
* further keystroke narrows a list that can never match again, ending in a
|
|
72
|
+
* spurious "No matching commands" while you are simply typing an argument.
|
|
73
|
+
*/
|
|
74
|
+
export function isArgMode(input) {
|
|
75
|
+
const typed = /^(\/\w+)\s/.exec(input);
|
|
76
|
+
if (!typed)
|
|
77
|
+
return false;
|
|
78
|
+
const name = typed[1].toLowerCase();
|
|
79
|
+
// /theme is an alias of /color and isn't in the registry as its own entry.
|
|
80
|
+
return name === "/theme" || visibleCommands().some((c) => c.name === name);
|
|
81
|
+
}
|
|
67
82
|
export function argHint(query) {
|
|
68
83
|
if (/^\/(?:color|theme)\s+$/i.test(query))
|
|
69
84
|
return `[${THEME_ORDER.join("|")}]`;
|
|
70
|
-
|
|
85
|
+
// Registry-driven, so a command's hint lives with the command rather than in
|
|
86
|
+
// a list here that would drift out of sync.
|
|
87
|
+
const typed = /^(\/\w+)\s+$/.exec(query);
|
|
88
|
+
if (!typed)
|
|
89
|
+
return "";
|
|
90
|
+
const command = visibleCommands().find((c) => c.name === typed[1].toLowerCase());
|
|
91
|
+
return command?.arg ? `[${command.arg}]` : "";
|
|
71
92
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as readline from "node:readline";
|
|
2
2
|
import { c } from "./colors.js";
|
|
3
|
-
import {
|
|
4
|
-
import { argHint, filterCommands, ghostCompletion } from "./command-filter.js";
|
|
3
|
+
import { TAKES_ARG, visibleCommands } from "./command-item.js";
|
|
4
|
+
import { argHint, filterCommands, ghostCompletion, isArgMode } from "./command-filter.js";
|
|
5
5
|
import { paletteView } from "./command-renderer.js";
|
|
6
6
|
import { accentName, isThemeColor, setAccent } from "./theme.js";
|
|
7
7
|
import { MARGIN, contentWidth } from "./composer-layout.js";
|
|
@@ -36,7 +36,7 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
|
36
36
|
let cursor = 0;
|
|
37
37
|
let paletteOpen = false;
|
|
38
38
|
let selected = 0;
|
|
39
|
-
let filtered =
|
|
39
|
+
let filtered = visibleCommands();
|
|
40
40
|
let histIdx = history.length;
|
|
41
41
|
const refilter = () => {
|
|
42
42
|
filtered = filterCommands(input);
|
|
@@ -105,7 +105,12 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
|
105
105
|
// value-entry context (`/color <value>`), where the inline arg hint / ghost
|
|
106
106
|
// on the prompt line replaces the list. The caret sits on the prompt line
|
|
107
107
|
// (core index 1) at the text column (1-based).
|
|
108
|
-
|
|
108
|
+
// Once a COMPLETE command is followed by a space, the rest of the line is
|
|
109
|
+
// its argument — not a search query. Filtering the whole line against
|
|
110
|
+
// command names from that point on can only ever say "No matching
|
|
111
|
+
// commands", which is both wrong and alarming while you type a question
|
|
112
|
+
// into /btw. The inline arg hint takes the list's place instead.
|
|
113
|
+
const argMode = isArgMode(input);
|
|
109
114
|
const paletteLines = paletteOpen && !argMode ? paletteView(filtered, selected, input) : [];
|
|
110
115
|
const caretCol = MARGIN.length + MARKER_COLS + (cursor - start) + 1;
|
|
111
116
|
screenComposer(paletteLines, core, 1, caretCol);
|
|
@@ -276,6 +281,14 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
|
276
281
|
}
|
|
277
282
|
return;
|
|
278
283
|
}
|
|
284
|
+
// ←/→ switch chat type ONLY on an empty composer with the palette shut.
|
|
285
|
+
// Any typed text, and they are cursor keys again — otherwise fixing a
|
|
286
|
+
// typo would change which chat you are in. Modals, pickers and the /btw
|
|
287
|
+
// overlay capture stdin themselves, so this handler cannot run while one
|
|
288
|
+
// is open; no extra guard is needed for them.
|
|
289
|
+
if ((key.name === "left" || key.name === "right") && input === "" && !paletteOpen) {
|
|
290
|
+
return finish({ type: "switch", dir: key.name });
|
|
291
|
+
}
|
|
279
292
|
if (key.name === "left") {
|
|
280
293
|
cursor = Math.max(0, cursor - 1);
|
|
281
294
|
return render();
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
// The active chat experience, so the palette can hide commands that don't apply
|
|
2
|
+
// to it. The shell sets this each loop iteration (it already rebuilds the footer
|
|
3
|
+
// from the same state), which keeps the registry a plain data module — no
|
|
4
|
+
// context object threaded through the filter and renderer.
|
|
5
|
+
let _scope = "carrier";
|
|
6
|
+
export function setCommandScope(scope) {
|
|
7
|
+
_scope = scope;
|
|
8
|
+
}
|
|
9
|
+
/** Commands available in the current chat experience. */
|
|
10
|
+
export function visibleCommands() {
|
|
11
|
+
return COMMANDS.filter((c) => !c.chatTypes || c.chatTypes.includes(_scope));
|
|
12
|
+
}
|
|
1
13
|
/** The order groups render in (only groups with matches are shown). */
|
|
2
14
|
export const GROUP_ORDER = [
|
|
3
15
|
"Chat",
|
|
4
16
|
"Sessions",
|
|
17
|
+
"Context",
|
|
5
18
|
"Models",
|
|
6
19
|
"Files",
|
|
7
20
|
"Account",
|
|
@@ -10,31 +23,93 @@ export const GROUP_ORDER = [
|
|
|
10
23
|
export const COMMANDS = [
|
|
11
24
|
{ name: "/chat", desc: "Start chatting with Carrier", group: "Chat", rank: 1 },
|
|
12
25
|
{ name: "/switch", desc: "Switch chat: Carrier ⇄ Standard", group: "Chat", rank: 2 },
|
|
13
|
-
{ name: "/
|
|
14
|
-
{ name: "/
|
|
15
|
-
{ name: "/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
{ name: "/websearch", desc: "Search the web — or a query to search now", group: "Chat", rank: 3, arg: "query" },
|
|
27
|
+
{ name: "/sources", desc: "Sources from the last search", group: "Chat", rank: 4 },
|
|
28
|
+
{ name: "/open", desc: "Open a source in your browser", group: "Chat", rank: 5, arg: "n" },
|
|
29
|
+
// Standard chat only — Carrier Chat always uses its own models, so the web
|
|
30
|
+
// doesn't render the toggle there either (shouldShowToggle).
|
|
31
|
+
{
|
|
32
|
+
name: "/fast",
|
|
33
|
+
desc: "Fast mode — quicker, less refinement",
|
|
34
|
+
group: "Models",
|
|
35
|
+
rank: 3,
|
|
36
|
+
chatTypes: ["standard"],
|
|
37
|
+
arg: "on|off"
|
|
38
|
+
},
|
|
39
|
+
{ name: "/hipwr", desc: "High Power — 4-pass refinement", group: "Models", rank: 4, arg: "on|off" },
|
|
40
|
+
{
|
|
41
|
+
name: "/sia",
|
|
42
|
+
desc: "Clarifying questions — Auto lets Carrier OS decide",
|
|
43
|
+
group: "Chat",
|
|
44
|
+
rank: 6,
|
|
45
|
+
chatTypes: ["standard"],
|
|
46
|
+
arg: "auto|off|status"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "/btw",
|
|
50
|
+
desc: "Ask a quick side question without adding it to the conversation",
|
|
51
|
+
group: "Chat",
|
|
52
|
+
rank: 7,
|
|
53
|
+
arg: "question"
|
|
54
|
+
},
|
|
55
|
+
{ name: "/new", desc: "Start a new conversation", group: "Sessions", rank: 1, arg: "title" },
|
|
56
|
+
{ name: "/sessions", desc: "List conversations, numbered", group: "Sessions", rank: 2 },
|
|
57
|
+
{ name: "/session", desc: "Continue a session — /session 2", group: "Sessions", rank: 3, arg: "n" },
|
|
58
|
+
{ name: "/history", desc: "Transcript — /history 2", group: "Sessions", rank: 4, arg: "n" },
|
|
59
|
+
{ name: "/context", desc: "What the next message is sent with — try /context project", group: "Context", rank: 1, arg: "project" },
|
|
60
|
+
{ name: "/memory", desc: "Snapshots and restructures — /memory 2", group: "Context", rank: 2, arg: "n" },
|
|
61
|
+
{ name: "/model", desc: "List & switch provider model", group: "Models", rank: 1, arg: "model" },
|
|
62
|
+
{ name: "/mode", desc: "List & switch Carrier mode", group: "Models", rank: 2, arg: "mode" },
|
|
63
|
+
{ name: "/upload", desc: "Upload file(s) — many + * globs", group: "Files", rank: 1, arg: "path" },
|
|
64
|
+
{ name: "/attach", desc: "Attach an upload to your next message", group: "Files", rank: 2, arg: "file" },
|
|
65
|
+
{ name: "/detach", desc: "Clear attached files", group: "Files", rank: 3 },
|
|
66
|
+
{ name: "/files", desc: "Local project tree & uploaded files", group: "Files", rank: 4, arg: "local|uploaded" },
|
|
67
|
+
{ name: "/search", desc: "Search the local project for text", group: "Files", rank: 5, arg: "text" },
|
|
68
|
+
{ name: "/review", desc: "Review this repository's changes (read-only)", group: "Files", rank: 1, arg: "repository" },
|
|
69
|
+
{ name: "/changes", desc: "File changes Carrier OS applied here", group: "Files", rank: 6 },
|
|
70
|
+
{ name: "/undo", desc: "Undo the latest change — /undo --repo <name> for another repository", group: "Files", rank: 7, arg: "operation" },
|
|
71
|
+
{ name: "/repo", desc: "Active repository — /repo use <name> to switch", group: "Context", rank: 3, arg: "use" },
|
|
72
|
+
{ name: "/repos", desc: "Repositories in this workspace", group: "Context", rank: 4 },
|
|
21
73
|
{ name: "/whoami", desc: "Current workspace & project", group: "Account", rank: 1 },
|
|
22
74
|
{ name: "/usage", desc: "View API usage", group: "Account", rank: 2 },
|
|
23
|
-
{ name: "/
|
|
75
|
+
{ name: "/settings", desc: "CLI settings — /settings commands on|off", group: "Account", rank: 3, arg: "commands" },
|
|
76
|
+
{ name: "/login", desc: "Sign in via your browser", group: "Account", rank: 3 },
|
|
24
77
|
{ name: "/logout", desc: "Remove saved credentials", group: "Account", rank: 4 },
|
|
25
78
|
{ name: "/help", desc: "Show available commands", group: "Developer", rank: 1 },
|
|
26
79
|
{ name: "/color", desc: "Change the accent color", group: "Developer", rank: 2 },
|
|
27
80
|
{ name: "/doctor", desc: "Run diagnostics", group: "Developer", rank: 3 },
|
|
28
81
|
{ name: "/version", desc: "Show CLI version", group: "Developer", rank: 4 },
|
|
82
|
+
{
|
|
83
|
+
name: "/update",
|
|
84
|
+
desc: "Check for and install the latest CLI version",
|
|
85
|
+
group: "Developer",
|
|
86
|
+
rank: 5
|
|
87
|
+
},
|
|
29
88
|
{ name: "/exit", desc: "Leave the shell", group: "Developer", rank: 5 }
|
|
30
89
|
];
|
|
31
90
|
/** Commands that take an argument — completed with a trailing space. */
|
|
32
91
|
export const TAKES_ARG = new Set([
|
|
33
92
|
"/mode",
|
|
34
93
|
"/model",
|
|
94
|
+
"/websearch",
|
|
95
|
+
"/fast",
|
|
96
|
+
"/hipwr",
|
|
97
|
+
"/sia",
|
|
98
|
+
"/settings",
|
|
99
|
+
"/btw",
|
|
100
|
+
"/open",
|
|
101
|
+
"/memory",
|
|
102
|
+
"/new",
|
|
35
103
|
"/session",
|
|
36
104
|
"/history",
|
|
37
105
|
"/upload",
|
|
106
|
+
"/attach",
|
|
107
|
+
"/files",
|
|
108
|
+
"/search",
|
|
109
|
+
"/review",
|
|
110
|
+
"/repo",
|
|
111
|
+
"/undo",
|
|
112
|
+
"/context",
|
|
38
113
|
"/color",
|
|
39
114
|
"/theme"
|
|
40
115
|
]);
|