@carrieros/cli 0.1.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 +305 -0
- package/dist/commands/chat.js +93 -0
- package/dist/commands/doctor.js +54 -0
- package/dist/commands/files.js +33 -0
- package/dist/commands/help.js +35 -0
- package/dist/commands/history.js +47 -0
- package/dist/commands/login.js +59 -0
- package/dist/commands/logout.js +15 -0
- package/dist/commands/mode-model.js +28 -0
- package/dist/commands/models.js +28 -0
- package/dist/commands/modes.js +27 -0
- package/dist/commands/sessions.js +123 -0
- package/dist/commands/upload.js +50 -0
- package/dist/commands/usage.js +31 -0
- package/dist/commands/version.js +28 -0
- package/dist/commands/whoami.js +40 -0
- package/dist/main.js +94 -0
- package/dist/services/api.js +115 -0
- package/dist/services/config.js +72 -0
- package/dist/services/context.js +42 -0
- package/dist/services/login-flow.js +15 -0
- package/dist/services/meta.js +13 -0
- package/dist/services/output.js +54 -0
- package/dist/services/spinner.js +18 -0
- package/dist/shell/shell-chat.js +280 -0
- package/dist/shell/shell-commands.js +168 -0
- package/dist/shell/shell-prompt.js +48 -0
- package/dist/shell/shell-renderer.js +70 -0
- package/dist/shell/shell-router.js +21 -0
- package/dist/shell/shell.js +139 -0
- package/dist/types/index.js +4 -0
- package/dist/ui/activity.js +77 -0
- package/dist/ui/banner.js +70 -0
- package/dist/ui/chat-renderer.js +269 -0
- package/dist/ui/code-block.js +52 -0
- package/dist/ui/color-picker.js +79 -0
- package/dist/ui/colors.js +47 -0
- package/dist/ui/command-filter.js +57 -0
- package/dist/ui/command-item.js +6 -0
- package/dist/ui/command-palette.js +306 -0
- package/dist/ui/command-registry.js +47 -0
- package/dist/ui/command-renderer.js +55 -0
- package/dist/ui/composer-layout.js +27 -0
- package/dist/ui/live.js +124 -0
- package/dist/ui/logo.js +58 -0
- package/dist/ui/markdown.js +151 -0
- package/dist/ui/message.js +38 -0
- package/dist/ui/select.js +114 -0
- package/dist/ui/spinner.js +23 -0
- package/dist/ui/sticky-stream.js +64 -0
- package/dist/ui/theme.js +63 -0
- package/dist/ui/ui.js +75 -0
- package/package.json +64 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as readline from "node:readline";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { c } from "./colors.js";
|
|
4
|
+
import { THEME_ORDER, accentHex, accentName, setAccent } from "./theme.js";
|
|
5
|
+
/**
|
|
6
|
+
* Claude-style inline /color selector. Renders on a single line:
|
|
7
|
+
*
|
|
8
|
+
* ❯ /color red │ blue │ [ green ] │ yellow │ …
|
|
9
|
+
*
|
|
10
|
+
* ← → (also Tab / Ctrl+B / Ctrl+F) move; Home/End jump; Enter confirms; Esc
|
|
11
|
+
* cancels. The accent live-previews as you move (the whole UI re-themes because
|
|
12
|
+
* colors read the accent dynamically); Esc restores the previous accent.
|
|
13
|
+
*
|
|
14
|
+
* Resolves the chosen color, or null on cancel.
|
|
15
|
+
*/
|
|
16
|
+
export function pickColor() {
|
|
17
|
+
const stdin = process.stdin;
|
|
18
|
+
const stdout = process.stdout;
|
|
19
|
+
if (!stdin.isTTY)
|
|
20
|
+
return Promise.resolve(null);
|
|
21
|
+
const options = [...THEME_ORDER];
|
|
22
|
+
const original = accentName();
|
|
23
|
+
let sel = Math.max(0, options.indexOf(original));
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
stdin.removeAllListeners("keypress");
|
|
26
|
+
readline.emitKeypressEvents(stdin);
|
|
27
|
+
if (!stdin.isRaw)
|
|
28
|
+
stdin.setRawMode(true);
|
|
29
|
+
stdin.resume();
|
|
30
|
+
stdout.write("\x1b[?25l"); // hide cursor while navigating
|
|
31
|
+
const render = () => {
|
|
32
|
+
setAccent(options[sel]); // live preview
|
|
33
|
+
readline.cursorTo(stdout, 0);
|
|
34
|
+
readline.clearLine(stdout, 0);
|
|
35
|
+
const opts = options
|
|
36
|
+
.map((name, i) => i === sel
|
|
37
|
+
? chalk.bgHex(accentHex(name)).black.bold(` ${name} `)
|
|
38
|
+
: c.dim(` ${name} `))
|
|
39
|
+
.join(c.dim("│"));
|
|
40
|
+
stdout.write(c.brand("❯") + c.dim(" /color ") + opts);
|
|
41
|
+
};
|
|
42
|
+
const done = (result) => {
|
|
43
|
+
if (result === null)
|
|
44
|
+
setAccent(original); // restore on cancel
|
|
45
|
+
readline.cursorTo(stdout, 0);
|
|
46
|
+
readline.clearLine(stdout, 0);
|
|
47
|
+
stdout.write("\x1b[?25h");
|
|
48
|
+
stdin.removeListener("keypress", onKey);
|
|
49
|
+
resolve(result);
|
|
50
|
+
};
|
|
51
|
+
const onKey = (_s, key) => {
|
|
52
|
+
if (!key)
|
|
53
|
+
return;
|
|
54
|
+
if (key.name === "left" || (key.ctrl && key.name === "b")) {
|
|
55
|
+
sel = (sel - 1 + options.length) % options.length;
|
|
56
|
+
return render();
|
|
57
|
+
}
|
|
58
|
+
if (key.name === "right" || key.name === "tab" || (key.ctrl && key.name === "f")) {
|
|
59
|
+
sel = (sel + 1) % options.length;
|
|
60
|
+
return render();
|
|
61
|
+
}
|
|
62
|
+
if (key.name === "home") {
|
|
63
|
+
sel = 0;
|
|
64
|
+
return render();
|
|
65
|
+
}
|
|
66
|
+
if (key.name === "end") {
|
|
67
|
+
sel = options.length - 1;
|
|
68
|
+
return render();
|
|
69
|
+
}
|
|
70
|
+
if (key.name === "return" || key.name === "enter")
|
|
71
|
+
return done(options[sel]);
|
|
72
|
+
if (key.name === "escape" || (key.ctrl && (key.name === "c" || key.name === "d"))) {
|
|
73
|
+
return done(null);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
stdin.on("keypress", onKey);
|
|
77
|
+
render();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { accentHex } from "./theme.js";
|
|
3
|
+
/**
|
|
4
|
+
* Carrier OS design system — the single source of truth for color. Every piece
|
|
5
|
+
* of CLI output pulls from here, so the whole tool stays consistent. All color
|
|
6
|
+
* goes through Chalk, which auto-detects terminal support (and honors NO_COLOR).
|
|
7
|
+
*
|
|
8
|
+
* The `brand` / `neural` / `sel` accents are getters that read the LIVE accent
|
|
9
|
+
* from the theme manager, so a runtime /color change re-themes the entire UI
|
|
10
|
+
* without recreating anything. Everything else is a fixed neutral (white / dim /
|
|
11
|
+
* status) that never changes with the accent.
|
|
12
|
+
*/
|
|
13
|
+
export const c = {
|
|
14
|
+
// Brand — dynamic accent (follows /color at runtime)
|
|
15
|
+
get brand() {
|
|
16
|
+
return chalk.hex(accentHex());
|
|
17
|
+
},
|
|
18
|
+
get neural() {
|
|
19
|
+
return chalk.hex(accentHex());
|
|
20
|
+
},
|
|
21
|
+
wordmark: chalk.whiteBright.bold, // CARRIER block logo (never recolored)
|
|
22
|
+
// Text
|
|
23
|
+
title: chalk.whiteBright.bold, // section titles / headings
|
|
24
|
+
value: chalk.white, // primary values
|
|
25
|
+
dim: chalk.dim, // secondary text
|
|
26
|
+
subtitle: chalk.dim,
|
|
27
|
+
label: chalk.dim, // metadata labels
|
|
28
|
+
hint: chalk.dim, // help hint text
|
|
29
|
+
rule: chalk.dim, // separators / rules
|
|
30
|
+
placeholder: chalk.dim.italic, // composer placeholder (fades into the background)
|
|
31
|
+
// Interactive
|
|
32
|
+
cmd: chalk.cyan, // slash commands
|
|
33
|
+
key: chalk.cyan, // keybindings / command keys
|
|
34
|
+
accent: chalk.cyan,
|
|
35
|
+
get sel() {
|
|
36
|
+
return chalk.bgHex(accentHex()).black.bold;
|
|
37
|
+
}, // selected palette bar (accent background)
|
|
38
|
+
group: chalk.dim.bold, // palette group headers
|
|
39
|
+
// Command arguments
|
|
40
|
+
arg: chalk.green, // ids / values (mode, model)
|
|
41
|
+
file: chalk.yellow, // file paths
|
|
42
|
+
// Status
|
|
43
|
+
ok: chalk.green,
|
|
44
|
+
warn: chalk.yellow,
|
|
45
|
+
info: chalk.cyan,
|
|
46
|
+
err: chalk.red
|
|
47
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { byGroupThenRank, COMMANDS } from "./command-item.js";
|
|
2
|
+
import { THEME_COLORS, THEME_ORDER } from "./theme.js";
|
|
3
|
+
/** After `/color ` (or `/theme `), the palette suggests color values. */
|
|
4
|
+
const COLOR_ARG = /^\/(color|theme)\s+(.*)$/i;
|
|
5
|
+
/**
|
|
6
|
+
* Substring matching for the palette (Claude-style): a command matches when the
|
|
7
|
+
* typed text appears anywhere in its name — `da` → `/update` (up**da**te) as
|
|
8
|
+
* well as `/dataviz`. Prefix matches rank above interior matches; ties fall back
|
|
9
|
+
* to grouped order (GROUP_ORDER, then rank) so arrow-nav stays predictable.
|
|
10
|
+
*/
|
|
11
|
+
export function filterCommands(query) {
|
|
12
|
+
// Argument suggestions: `/color <partial>` → matching color values.
|
|
13
|
+
const color = query.match(COLOR_ARG);
|
|
14
|
+
if (color) {
|
|
15
|
+
const cmd = color[1].toLowerCase();
|
|
16
|
+
const partial = color[2].toLowerCase().trim();
|
|
17
|
+
return THEME_ORDER.filter((name) => name.startsWith(partial)).map((name, i) => ({
|
|
18
|
+
name: `/${cmd} ${name}`,
|
|
19
|
+
desc: THEME_COLORS[name],
|
|
20
|
+
group: "Developer",
|
|
21
|
+
rank: i
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
const term = query.toLowerCase().replace(/^\//, "").trim();
|
|
25
|
+
if (!term)
|
|
26
|
+
return [...COMMANDS].sort(byGroupThenRank);
|
|
27
|
+
const scored = [];
|
|
28
|
+
for (const cmd of COMMANDS) {
|
|
29
|
+
const idx = cmd.name.slice(1).toLowerCase().indexOf(term);
|
|
30
|
+
if (idx !== -1)
|
|
31
|
+
scored.push({ cmd, prefix: idx === 0 });
|
|
32
|
+
}
|
|
33
|
+
return scored
|
|
34
|
+
.sort((a, b) => (a.prefix === b.prefix ? byGroupThenRank(a.cmd, b.cmd) : a.prefix ? -1 : 1))
|
|
35
|
+
.map((x) => x.cmd);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Ghost (inline) completion: given what's typed, return the remaining characters
|
|
39
|
+
* of the best prefix match — e.g. `/ver` → `sion`. Empty when the input isn't a
|
|
40
|
+
* clean prefix of any command (fuzzy-only matches don't ghost).
|
|
41
|
+
*/
|
|
42
|
+
export function ghostCompletion(query) {
|
|
43
|
+
// Complete a color value after `/color `.
|
|
44
|
+
const color = query.match(/^\/(?:color|theme)\s+(\w*)$/i);
|
|
45
|
+
if (color) {
|
|
46
|
+
const p = color[1].toLowerCase();
|
|
47
|
+
const match = THEME_ORDER.find((n) => n.startsWith(p) && n.length > p.length);
|
|
48
|
+
return match ? match.slice(p.length) : "";
|
|
49
|
+
}
|
|
50
|
+
const term = query.toLowerCase().replace(/^\//, "");
|
|
51
|
+
if (!term)
|
|
52
|
+
return "";
|
|
53
|
+
const matches = COMMANDS.filter((cmd) => cmd.name.slice(1).toLowerCase().startsWith(term)).sort((a, b) => a.rank - b.rank);
|
|
54
|
+
if (matches.length === 0)
|
|
55
|
+
return "";
|
|
56
|
+
return matches[0].name.slice(query.length);
|
|
57
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import * as readline from "node:readline";
|
|
2
|
+
import { c } from "./colors.js";
|
|
3
|
+
import { COMMANDS, TAKES_ARG } from "./command-item.js";
|
|
4
|
+
import { filterCommands, ghostCompletion } from "./command-filter.js";
|
|
5
|
+
import { paletteView } from "./command-renderer.js";
|
|
6
|
+
import { accentName, isThemeColor, setAccent } from "./theme.js";
|
|
7
|
+
import { MARGIN, contentWidth } from "./composer-layout.js";
|
|
8
|
+
/** Color name inside a `/color <name>` suggestion, or null. */
|
|
9
|
+
function colorOf(name) {
|
|
10
|
+
const m = name.match(/^\/(?:color|theme)\s+(\w+)$/i);
|
|
11
|
+
return m && isThemeColor(m[1].toLowerCase()) ? m[1].toLowerCase() : null;
|
|
12
|
+
}
|
|
13
|
+
export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
14
|
+
if (!process.stdin.isTTY)
|
|
15
|
+
return readSimple(caret);
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
const stdin = process.stdin;
|
|
18
|
+
const stdout = process.stdout;
|
|
19
|
+
// Re-arm stdin from scratch every call. External prompt UIs (the @inquirer
|
|
20
|
+
// mode/model pickers) and spinners can leave stray keypress listeners, a
|
|
21
|
+
// paused stream, or a non-raw terminal behind — any of which would swallow
|
|
22
|
+
// our keystrokes and make the composer look frozen. Clearing and re-enabling
|
|
23
|
+
// guarantees a clean, responsive input each time.
|
|
24
|
+
stdin.removeAllListeners("keypress");
|
|
25
|
+
readline.emitKeypressEvents(stdin);
|
|
26
|
+
// Keep raw mode ON for the whole shell session. Toggling it off after each
|
|
27
|
+
// command (then back on for the next prompt) intermittently drops keypress
|
|
28
|
+
// delivery on Windows consoles — which looked like a frozen prompt after
|
|
29
|
+
// running a command like /chat. The shell restores cooked mode on exit.
|
|
30
|
+
if (stdin.isTTY && !stdin.isRaw)
|
|
31
|
+
stdin.setRawMode(true);
|
|
32
|
+
stdin.resume();
|
|
33
|
+
let input = "";
|
|
34
|
+
let cursor = 0;
|
|
35
|
+
let paletteOpen = false;
|
|
36
|
+
let selected = 0;
|
|
37
|
+
let filtered = COMMANDS;
|
|
38
|
+
let histIdx = history.length;
|
|
39
|
+
const refilter = () => {
|
|
40
|
+
filtered = filterCommands(input);
|
|
41
|
+
if (selected >= filtered.length)
|
|
42
|
+
selected = Math.max(0, filtered.length - 1);
|
|
43
|
+
};
|
|
44
|
+
// Full-width input bar (Claude-style): a horizontal rule above and below a
|
|
45
|
+
// `❯ ` prompt spanning the whole terminal. "❯ " is 2 visible cols; input
|
|
46
|
+
// starts at column 2. Long lines scroll horizontally to keep the caret in
|
|
47
|
+
// view. The prompt sits near the TOP of the block (row 1), so re-renders only
|
|
48
|
+
// ever step up one line to clear — no risk of clamping past the viewport top.
|
|
49
|
+
const MARKER_COLS = 2;
|
|
50
|
+
let prevUp = 0;
|
|
51
|
+
// Live theme preview for `/color <name>` suggestions: previewing the accent
|
|
52
|
+
// as the highlighted color changes, restoring it if the user backs out.
|
|
53
|
+
let colorPreviewOrig = null;
|
|
54
|
+
const applyColorPreview = () => {
|
|
55
|
+
const sel = paletteOpen && filtered.length ? colorOf(filtered[selected].name) : null;
|
|
56
|
+
if (sel) {
|
|
57
|
+
if (colorPreviewOrig === null)
|
|
58
|
+
colorPreviewOrig = accentName();
|
|
59
|
+
setAccent(sel);
|
|
60
|
+
}
|
|
61
|
+
else if (colorPreviewOrig !== null) {
|
|
62
|
+
setAccent(colorPreviewOrig);
|
|
63
|
+
colorPreviewOrig = null;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const render = () => {
|
|
67
|
+
applyColorPreview();
|
|
68
|
+
// Hide the cursor for the duration of the redraw so it doesn't visibly
|
|
69
|
+
// flicker as it's repositioned; it's shown again at its final resting spot.
|
|
70
|
+
stdout.write("\x1b[?25l");
|
|
71
|
+
// Rewind to the top of the previous block and wipe it clean.
|
|
72
|
+
if (prevUp > 0)
|
|
73
|
+
readline.moveCursor(stdout, 0, -prevUp);
|
|
74
|
+
readline.cursorTo(stdout, 0);
|
|
75
|
+
readline.clearScreenDown(stdout);
|
|
76
|
+
// The composer + its divider lines span the full content width (terminal
|
|
77
|
+
// minus a small margin/gutter), recomputed each render so a resize just
|
|
78
|
+
// redraws cleanly at the new width.
|
|
79
|
+
const total = contentWidth();
|
|
80
|
+
const field = Math.max(8, total - MARKER_COLS); // usable text width
|
|
81
|
+
// Ghost-completion only when the caret sits at the end of the input.
|
|
82
|
+
const ghost = paletteOpen && cursor === input.length ? ghostCompletion(input) : "";
|
|
83
|
+
const start = cursor > field ? cursor - field : 0;
|
|
84
|
+
const visInput = input.slice(start, start + field);
|
|
85
|
+
const visGhost = start + visInput.length >= input.length ? ghost.slice(0, field - visInput.length) : "";
|
|
86
|
+
// Empty + closed → show the dim italic placeholder (it never becomes part
|
|
87
|
+
// of the message; typing the first char replaces it, deleting brings it
|
|
88
|
+
// back). Otherwise render the typed text and any ghost completion.
|
|
89
|
+
const showPlaceholder = input === "" && !paletteOpen && placeholder !== "";
|
|
90
|
+
const bodyText = showPlaceholder ? placeholder.slice(0, field) : visInput;
|
|
91
|
+
const body = showPlaceholder ? c.placeholder(bodyText) : c.value(bodyText);
|
|
92
|
+
const promptCols = MARKER_COLS + bodyText.length + (showPlaceholder ? 0 : visGhost.length);
|
|
93
|
+
const pad = " ".repeat(Math.max(0, total - promptCols));
|
|
94
|
+
const rule = MARGIN + c.rule("─".repeat(total));
|
|
95
|
+
const promptLine = MARGIN + c.brand("❯") + " " + body + (visGhost ? c.dim(visGhost) : "") + pad;
|
|
96
|
+
// Compose the block: the input bar (rule / prompt / rule), then the palette
|
|
97
|
+
// BELOW it while open, or the dim status footer below it when closed.
|
|
98
|
+
const lines = [rule, promptLine, rule];
|
|
99
|
+
const midRow = 1; // caret lands on the prompt line
|
|
100
|
+
if (paletteOpen)
|
|
101
|
+
lines.push(...paletteView(filtered, selected, input));
|
|
102
|
+
else if (footer)
|
|
103
|
+
lines.push(footer);
|
|
104
|
+
stdout.write(lines.join("\n"));
|
|
105
|
+
// Park the caret on the prompt line at the text column, then reveal it.
|
|
106
|
+
const lastRow = lines.length - 1;
|
|
107
|
+
if (lastRow > midRow)
|
|
108
|
+
readline.moveCursor(stdout, 0, -(lastRow - midRow));
|
|
109
|
+
readline.cursorTo(stdout, MARGIN.length + MARKER_COLS + (cursor - start));
|
|
110
|
+
stdout.write("\x1b[?25h");
|
|
111
|
+
prevUp = midRow;
|
|
112
|
+
};
|
|
113
|
+
const clearBox = () => {
|
|
114
|
+
// Rewind to the top of the block and wipe it, so callers render clean.
|
|
115
|
+
if (prevUp > 0)
|
|
116
|
+
readline.moveCursor(stdout, 0, -prevUp);
|
|
117
|
+
readline.cursorTo(stdout, 0);
|
|
118
|
+
readline.clearScreenDown(stdout);
|
|
119
|
+
prevUp = 0;
|
|
120
|
+
};
|
|
121
|
+
const finish = (res) => {
|
|
122
|
+
paletteOpen = false;
|
|
123
|
+
// Undo any live color preview — the /color command re-applies + persists
|
|
124
|
+
// the chosen color; other exits should leave the accent as it was.
|
|
125
|
+
if (colorPreviewOrig !== null) {
|
|
126
|
+
setAccent(colorPreviewOrig);
|
|
127
|
+
colorPreviewOrig = null;
|
|
128
|
+
}
|
|
129
|
+
clearBox();
|
|
130
|
+
stdin.removeListener("keypress", onKey);
|
|
131
|
+
// Raw mode is intentionally left ON between prompts (see the setup note);
|
|
132
|
+
// the shell restores cooked mode when it exits.
|
|
133
|
+
resolve(res);
|
|
134
|
+
};
|
|
135
|
+
const setInput = (next, open) => {
|
|
136
|
+
input = next;
|
|
137
|
+
cursor = input.length;
|
|
138
|
+
paletteOpen = open ?? input.startsWith("/");
|
|
139
|
+
if (paletteOpen) {
|
|
140
|
+
selected = 0;
|
|
141
|
+
refilter();
|
|
142
|
+
}
|
|
143
|
+
render();
|
|
144
|
+
};
|
|
145
|
+
const acceptGhost = () => {
|
|
146
|
+
const ghost = ghostCompletion(input);
|
|
147
|
+
if (paletteOpen && cursor === input.length && ghost) {
|
|
148
|
+
setInput(input + ghost, true);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
};
|
|
153
|
+
const onKey = (str, key) => {
|
|
154
|
+
try {
|
|
155
|
+
handleKey(str, key);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
// A render hiccup must never silently freeze input — surface it and
|
|
159
|
+
// keep the reader alive.
|
|
160
|
+
stdout.write(`\n${c.err("Input error:")} ${err.message}\n`);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const handleKey = (str, key) => {
|
|
164
|
+
if (!key)
|
|
165
|
+
return;
|
|
166
|
+
if (key.ctrl && key.name === "c") {
|
|
167
|
+
if (input.length)
|
|
168
|
+
return setInput("");
|
|
169
|
+
return finish({ type: "sigint" });
|
|
170
|
+
}
|
|
171
|
+
if (key.ctrl && key.name === "d")
|
|
172
|
+
return finish({ type: "exit" });
|
|
173
|
+
if (key.ctrl && key.name === "l") {
|
|
174
|
+
stdout.write("\x1b[2J\x1b[H");
|
|
175
|
+
prevUp = 0;
|
|
176
|
+
return render();
|
|
177
|
+
}
|
|
178
|
+
if (key.ctrl && (key.name === "u" || key.name === "k"))
|
|
179
|
+
return setInput("");
|
|
180
|
+
if (key.ctrl && key.name === "a") {
|
|
181
|
+
cursor = 0;
|
|
182
|
+
return render();
|
|
183
|
+
}
|
|
184
|
+
if (key.name === "return" || key.name === "enter") {
|
|
185
|
+
// Single Enter RUNS the highlighted command (arg-taking ones open their
|
|
186
|
+
// own picker when given none). Use Tab to insert-and-add-an-argument.
|
|
187
|
+
if (paletteOpen && filtered.length) {
|
|
188
|
+
return finish({ type: "line", value: filtered[selected].name });
|
|
189
|
+
}
|
|
190
|
+
return finish({ type: "line", value: input });
|
|
191
|
+
}
|
|
192
|
+
if (key.name === "escape") {
|
|
193
|
+
if (paletteOpen) {
|
|
194
|
+
paletteOpen = false;
|
|
195
|
+
render();
|
|
196
|
+
}
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (key.name === "up") {
|
|
200
|
+
if (paletteOpen) {
|
|
201
|
+
selected = Math.max(0, selected - 1);
|
|
202
|
+
render();
|
|
203
|
+
}
|
|
204
|
+
else if (history.length) {
|
|
205
|
+
histIdx = Math.max(0, histIdx - 1);
|
|
206
|
+
setInput(history[histIdx] ?? "", false);
|
|
207
|
+
}
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (key.name === "down") {
|
|
211
|
+
if (paletteOpen) {
|
|
212
|
+
selected = Math.min(filtered.length - 1, selected + 1);
|
|
213
|
+
render();
|
|
214
|
+
}
|
|
215
|
+
else if (history.length) {
|
|
216
|
+
histIdx = Math.min(history.length, histIdx + 1);
|
|
217
|
+
setInput(histIdx === history.length ? "" : history[histIdx], false);
|
|
218
|
+
}
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (key.name === "tab") {
|
|
222
|
+
if (acceptGhost())
|
|
223
|
+
return;
|
|
224
|
+
// Insert the command (closing the palette) so an argument can be typed;
|
|
225
|
+
// arg-taking commands get a trailing space. A follow-up Enter runs it.
|
|
226
|
+
if (paletteOpen && filtered.length) {
|
|
227
|
+
const chosen = filtered[selected].name;
|
|
228
|
+
setInput(TAKES_ARG.has(chosen) ? chosen + " " : chosen, false);
|
|
229
|
+
}
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (key.name === "left") {
|
|
233
|
+
cursor = Math.max(0, cursor - 1);
|
|
234
|
+
return render();
|
|
235
|
+
}
|
|
236
|
+
if (key.name === "right") {
|
|
237
|
+
// Right at end accepts the ghost (Claude-style); otherwise moves.
|
|
238
|
+
if (cursor === input.length && acceptGhost())
|
|
239
|
+
return;
|
|
240
|
+
cursor = Math.min(input.length, cursor + 1);
|
|
241
|
+
return render();
|
|
242
|
+
}
|
|
243
|
+
if (key.name === "home") {
|
|
244
|
+
cursor = 0;
|
|
245
|
+
return render();
|
|
246
|
+
}
|
|
247
|
+
if (key.name === "end") {
|
|
248
|
+
cursor = input.length;
|
|
249
|
+
return render();
|
|
250
|
+
}
|
|
251
|
+
if (key.name === "backspace") {
|
|
252
|
+
if (cursor > 0) {
|
|
253
|
+
input = input.slice(0, cursor - 1) + input.slice(cursor);
|
|
254
|
+
cursor--;
|
|
255
|
+
}
|
|
256
|
+
paletteOpen = input.startsWith("/");
|
|
257
|
+
if (paletteOpen) {
|
|
258
|
+
selected = 0;
|
|
259
|
+
refilter();
|
|
260
|
+
}
|
|
261
|
+
return render();
|
|
262
|
+
}
|
|
263
|
+
if (key.name === "delete") {
|
|
264
|
+
input = input.slice(0, cursor) + input.slice(cursor + 1);
|
|
265
|
+
paletteOpen = input.startsWith("/");
|
|
266
|
+
if (paletteOpen)
|
|
267
|
+
refilter();
|
|
268
|
+
return render();
|
|
269
|
+
}
|
|
270
|
+
// Printable character.
|
|
271
|
+
if (str && !key.ctrl && !key.meta && str >= " " && str !== "\x7f") {
|
|
272
|
+
input = input.slice(0, cursor) + str + input.slice(cursor);
|
|
273
|
+
cursor += str.length;
|
|
274
|
+
if (input.startsWith("/")) {
|
|
275
|
+
paletteOpen = true;
|
|
276
|
+
selected = 0;
|
|
277
|
+
refilter();
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
paletteOpen = false;
|
|
281
|
+
}
|
|
282
|
+
render();
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
stdin.on("keypress", onKey);
|
|
286
|
+
render();
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/** Non-TTY fallback: a plain line read (pipes / CI), no overlay. */
|
|
290
|
+
function readSimple(caret) {
|
|
291
|
+
return new Promise((resolve) => {
|
|
292
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
293
|
+
let done = false;
|
|
294
|
+
rl.on("close", () => {
|
|
295
|
+
if (!done) {
|
|
296
|
+
done = true;
|
|
297
|
+
resolve({ type: "exit" });
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
rl.question(caret, (answer) => {
|
|
301
|
+
done = true;
|
|
302
|
+
rl.close();
|
|
303
|
+
resolve({ type: "line", value: answer });
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** The order groups render in (only groups with matches are shown). */
|
|
2
|
+
export const GROUP_ORDER = [
|
|
3
|
+
"Chat",
|
|
4
|
+
"Sessions",
|
|
5
|
+
"Models",
|
|
6
|
+
"Files",
|
|
7
|
+
"Account",
|
|
8
|
+
"Developer"
|
|
9
|
+
];
|
|
10
|
+
export const COMMANDS = [
|
|
11
|
+
{ name: "/chat", desc: "Start chatting with Carrier", group: "Chat", rank: 1 },
|
|
12
|
+
{ name: "/clear", desc: "Start a new conversation", group: "Chat", rank: 2 },
|
|
13
|
+
{ name: "/sessions", desc: "List conversations", group: "Sessions", rank: 1 },
|
|
14
|
+
{ name: "/session", desc: "Switch / manage a session", group: "Sessions", rank: 2 },
|
|
15
|
+
{ name: "/history", desc: "Conversation transcript", group: "Sessions", rank: 3 },
|
|
16
|
+
{ name: "/models", desc: "List provider models", group: "Models", rank: 1 },
|
|
17
|
+
{ name: "/model", desc: "Switch provider model", group: "Models", rank: 2 },
|
|
18
|
+
{ name: "/mode", desc: "Switch Carrier mode", group: "Models", rank: 3 },
|
|
19
|
+
{ name: "/modes", desc: "List Carrier modes", group: "Models", rank: 4 },
|
|
20
|
+
{ name: "/upload", desc: "Upload a file", group: "Files", rank: 1 },
|
|
21
|
+
{ name: "/files", desc: "List uploaded files", group: "Files", rank: 2 },
|
|
22
|
+
{ name: "/whoami", desc: "Current workspace & project", group: "Account", rank: 1 },
|
|
23
|
+
{ name: "/usage", desc: "View API usage", group: "Account", rank: 2 },
|
|
24
|
+
{ name: "/login", desc: "Authenticate using an API key", group: "Account", rank: 3 },
|
|
25
|
+
{ name: "/logout", desc: "Remove saved credentials", group: "Account", rank: 4 },
|
|
26
|
+
{ name: "/help", desc: "Show available commands", group: "Developer", rank: 1 },
|
|
27
|
+
{ name: "/color", desc: "Change the accent color", group: "Developer", rank: 2 },
|
|
28
|
+
{ name: "/doctor", desc: "Run diagnostics", group: "Developer", rank: 3 },
|
|
29
|
+
{ name: "/version", desc: "Show CLI version", group: "Developer", rank: 4 },
|
|
30
|
+
{ name: "/exit", desc: "Leave the shell", group: "Developer", rank: 5 }
|
|
31
|
+
];
|
|
32
|
+
/** Commands that take an argument — completed with a trailing space. */
|
|
33
|
+
export const TAKES_ARG = new Set([
|
|
34
|
+
"/mode",
|
|
35
|
+
"/model",
|
|
36
|
+
"/session",
|
|
37
|
+
"/history",
|
|
38
|
+
"/upload",
|
|
39
|
+
"/color",
|
|
40
|
+
"/theme"
|
|
41
|
+
]);
|
|
42
|
+
const GROUP_INDEX = new Map(GROUP_ORDER.map((g, i) => [g, i]));
|
|
43
|
+
/** Stable grouped ordering: by group (GROUP_ORDER), then rank within a group. */
|
|
44
|
+
export function byGroupThenRank(a, b) {
|
|
45
|
+
const g = (GROUP_INDEX.get(a.group) ?? 0) - (GROUP_INDEX.get(b.group) ?? 0);
|
|
46
|
+
return g !== 0 ? g : a.rank - b.rank;
|
|
47
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { c } from "./colors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders the palette overlay Claude Code–style: a flat list of aligned
|
|
5
|
+
* `command description` rows. Command names are white; the selected row is
|
|
6
|
+
* lifted in the brand green (green `❯` + bold green name), while every other row
|
|
7
|
+
* stays quiet. The visible window scrolls to keep the selection in view. Returns
|
|
8
|
+
* col-0 lines; the reader floats them directly above the input box.
|
|
9
|
+
*/
|
|
10
|
+
const MAX_ROWS = 8; // command rows shown at once
|
|
11
|
+
const NAME_W = 10; // command-name column width (longest: "/sessions")
|
|
12
|
+
export function paletteView(filtered, selected, query = "") {
|
|
13
|
+
const term = query.toLowerCase().replace(/^\//, "").trim();
|
|
14
|
+
if (filtered.length === 0) {
|
|
15
|
+
return ["", " " + c.dim("No matching commands."), ""];
|
|
16
|
+
}
|
|
17
|
+
// Scroll a window of command rows around the selection.
|
|
18
|
+
let start = 0;
|
|
19
|
+
if (filtered.length > MAX_ROWS) {
|
|
20
|
+
start = Math.min(Math.max(0, selected - Math.floor(MAX_ROWS / 2)), filtered.length - MAX_ROWS);
|
|
21
|
+
}
|
|
22
|
+
const slice = filtered.slice(start, start + MAX_ROWS);
|
|
23
|
+
const out = [""];
|
|
24
|
+
slice.forEach((cmd, i) => out.push(row(cmd, start + i === selected, term)));
|
|
25
|
+
out.push("");
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
/** One command row: `❯ /name description`, aligned. Selected = brand green.
|
|
29
|
+
* The matched substring in the name is emphasized (bold) like Claude. */
|
|
30
|
+
function row(cmd, selected, term) {
|
|
31
|
+
const pad = " ".repeat(Math.max(0, NAME_W - cmd.name.length));
|
|
32
|
+
const desc = renderDesc(cmd.desc, selected);
|
|
33
|
+
if (selected) {
|
|
34
|
+
const name = highlight(cmd.name, term, c.brand, c.brand.bold);
|
|
35
|
+
return " " + c.brand("❯ ") + name + pad + " " + desc;
|
|
36
|
+
}
|
|
37
|
+
const name = highlight(cmd.name, term, c.value, c.title);
|
|
38
|
+
return " " + name + pad + " " + desc;
|
|
39
|
+
}
|
|
40
|
+
/** Description cell — a hex value gets a color swatch (used by /color rows). */
|
|
41
|
+
function renderDesc(desc, selected) {
|
|
42
|
+
if (/^#[0-9a-f]{6}$/i.test(desc))
|
|
43
|
+
return chalk.hex(desc)("●") + " " + c.dim(desc);
|
|
44
|
+
return selected ? c.brand(desc) : c.dim(desc);
|
|
45
|
+
}
|
|
46
|
+
/** Color a command name, emphasizing the matched substring — `base` for the
|
|
47
|
+
* rest, `hi` for the match. The leading "/" always stays in `base`. */
|
|
48
|
+
function highlight(raw, term, base, hi) {
|
|
49
|
+
const idx = term ? raw.slice(1).toLowerCase().indexOf(term) : -1;
|
|
50
|
+
if (idx === -1)
|
|
51
|
+
return base(raw);
|
|
52
|
+
const s = idx + 1; // account for the leading "/"
|
|
53
|
+
const e = s + term.length;
|
|
54
|
+
return base(raw.slice(0, s)) + hi(raw.slice(s, e)) + base(raw.slice(e));
|
|
55
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composer layout. The composer + its divider lines span the FULL terminal
|
|
3
|
+
* width (Claude-style), inset by a small margin with a one-column right gutter
|
|
4
|
+
* so a line never overflows and wraps. It's computed fresh each render, so a
|
|
5
|
+
* resize simply redraws at the new width — cleanly, never "messed up".
|
|
6
|
+
*
|
|
7
|
+
* Long answer text still wraps to a readable maximum (READABLE_MAX) so replies
|
|
8
|
+
* don't run edge-to-edge on very wide terminals.
|
|
9
|
+
*/
|
|
10
|
+
/** Left margin the whole column sits at. */
|
|
11
|
+
export const MARGIN = " ";
|
|
12
|
+
/** Cap for wrapping running text (dividers/composer are not capped). */
|
|
13
|
+
const READABLE_MAX = 96;
|
|
14
|
+
/** Terminal columns, defensively defaulted. */
|
|
15
|
+
function columns() {
|
|
16
|
+
const cols = process.stdout.columns;
|
|
17
|
+
return cols && cols > 0 ? cols : 80;
|
|
18
|
+
}
|
|
19
|
+
/** Full content width for the composer + dividers: terminal minus the left
|
|
20
|
+
* margin and a one-column right gutter. */
|
|
21
|
+
export function contentWidth() {
|
|
22
|
+
return Math.max(24, columns() - MARGIN.length - 1);
|
|
23
|
+
}
|
|
24
|
+
/** Width to wrap running text to — full content width, capped for readability. */
|
|
25
|
+
export function textWidth() {
|
|
26
|
+
return Math.max(20, Math.min(contentWidth(), READABLE_MAX));
|
|
27
|
+
}
|