@carrieros/cli-staging 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/commands/attach.js +45 -0
- package/dist/commands/auth.js +60 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +182 -0
- package/dist/commands/context.js +200 -0
- package/dist/commands/doctor.js +119 -0
- package/dist/commands/files.js +94 -0
- package/dist/commands/help.js +37 -0
- package/dist/commands/history.js +112 -0
- package/dist/commands/login.js +62 -0
- package/dist/commands/logout.js +26 -0
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +64 -0
- package/dist/commands/models.js +28 -0
- package/dist/commands/modes.js +30 -0
- package/dist/commands/permissions.js +78 -0
- package/dist/commands/project.js +106 -0
- package/dist/commands/repo.js +146 -0
- package/dist/commands/repos.js +61 -0
- package/dist/commands/review.js +92 -0
- package/dist/commands/scope.js +155 -0
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +282 -0
- package/dist/commands/settings.js +160 -0
- package/dist/commands/update.js +285 -0
- package/dist/commands/upload.js +223 -0
- package/dist/commands/usage.js +229 -0
- package/dist/commands/version.js +26 -0
- package/dist/commands/whoami.js +44 -0
- package/dist/ide/editor-context.js +275 -0
- package/dist/ide/ide-session.js +364 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +132 -0
- package/dist/services/api.js +441 -0
- package/dist/services/auth-origin.js +20 -0
- package/dist/services/auto-update.js +221 -0
- package/dist/services/chat-stream.js +168 -0
- package/dist/services/checkpoints.js +278 -0
- package/dist/services/client-tools.js +356 -0
- package/dist/services/code-intel.js +243 -0
- package/dist/services/code-symbols.js +94 -0
- package/dist/services/coding-workflow.js +554 -0
- package/dist/services/command-coordinator.js +273 -0
- package/dist/services/command-policy.js +434 -0
- package/dist/services/config.js +384 -0
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +416 -0
- package/dist/services/device-auth.js +288 -0
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -0
- package/dist/services/execution-platform.js +30 -0
- package/dist/services/file-detect.js +104 -0
- package/dist/services/file-resolver.js +199 -0
- package/dist/services/file-upload.js +126 -0
- package/dist/services/folder-key.js +22 -0
- package/dist/services/git-tools.js +429 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +85 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/instruction-resolver.js +54 -0
- package/dist/services/job-helper.js +328 -0
- package/dist/services/local-files.js +639 -0
- package/dist/services/local-tools.js +937 -0
- package/dist/services/login-flow.js +156 -0
- package/dist/services/meta.js +42 -0
- package/dist/services/mutation-coordinator.js +327 -0
- package/dist/services/mutation-groups.js +309 -0
- package/dist/services/mutation-recovery.js +159 -0
- package/dist/services/mutations.js +679 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +62 -0
- package/dist/services/packaged-update.js +403 -0
- package/dist/services/packaged.js +39 -0
- package/dist/services/permission-mode.js +78 -0
- package/dist/services/process-runner.js +412 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/result-reconciliation.js +49 -0
- package/dist/services/secure-store.js +217 -0
- package/dist/services/session-resolver.js +115 -0
- package/dist/services/sia.js +51 -0
- package/dist/services/spinner.js +40 -0
- package/dist/services/supported-runtime.js +59 -0
- package/dist/services/task-context.js +212 -0
- package/dist/services/task-snapshot.js +38 -0
- package/dist/services/tool-result-outbox.js +195 -0
- package/dist/services/update.js +730 -0
- package/dist/services/workspace-registry.js +310 -0
- package/dist/services/workspace.js +580 -0
- package/dist/shell/shell-chat.js +1622 -0
- package/dist/shell/shell-commands.js +411 -0
- package/dist/shell/shell-prompt.js +110 -0
- package/dist/shell/shell-renderer.js +51 -0
- package/dist/shell/shell-router.js +37 -0
- package/dist/shell/shell.js +414 -0
- package/dist/shell/task-context-view.js +40 -0
- package/dist/staging.js +5 -0
- package/dist/types/index.js +6 -0
- package/dist/ui/agent-cards.js +111 -0
- package/dist/ui/agent-presentation.js +131 -0
- package/dist/ui/approval.js +111 -0
- package/dist/ui/banner.js +56 -0
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +334 -0
- package/dist/ui/chat-renderer.js +463 -0
- package/dist/ui/code-block.js +52 -0
- package/dist/ui/color-picker.js +100 -0
- package/dist/ui/colors.js +55 -0
- package/dist/ui/command-details.js +11 -0
- package/dist/ui/command-filter.js +92 -0
- package/dist/ui/command-item.js +6 -0
- package/dist/ui/command-palette.js +383 -0
- package/dist/ui/command-registry.js +128 -0
- package/dist/ui/command-renderer.js +55 -0
- package/dist/ui/command-review.js +187 -0
- package/dist/ui/composer-layout.js +74 -0
- package/dist/ui/conversation.js +450 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +141 -0
- package/dist/ui/logo.js +58 -0
- package/dist/ui/markdown.js +205 -0
- package/dist/ui/message.js +21 -0
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +297 -0
- package/dist/ui/select.js +284 -0
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/spinner.js +23 -0
- package/dist/ui/sticky-stream.js +64 -0
- package/dist/ui/task-context-card.js +99 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/theme.js +80 -0
- package/dist/ui/trust.js +88 -0
- package/dist/ui/ui.js +101 -0
- package/package.json +33 -4
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { byGroupThenRank, visibleCommands } 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 visibleCommands().sort(byGroupThenRank);
|
|
27
|
+
const scored = [];
|
|
28
|
+
for (const cmd of visibleCommands()) {
|
|
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 <partial>`. With nothing typed yet the
|
|
44
|
+
// bracketed argHint() is shown instead, so don't ghost a single value there.
|
|
45
|
+
const color = query.match(/^\/(?:color|theme)\s+(\w*)$/i);
|
|
46
|
+
if (color) {
|
|
47
|
+
const p = color[1].toLowerCase();
|
|
48
|
+
if (!p)
|
|
49
|
+
return "";
|
|
50
|
+
const match = THEME_ORDER.find((n) => n.startsWith(p) && n.length > p.length);
|
|
51
|
+
return match ? match.slice(p.length) : "";
|
|
52
|
+
}
|
|
53
|
+
const term = query.toLowerCase().replace(/^\//, "");
|
|
54
|
+
if (!term)
|
|
55
|
+
return "";
|
|
56
|
+
const matches = visibleCommands().filter((cmd) => cmd.name.slice(1).toLowerCase().startsWith(term)).sort((a, b) => a.rank - b.rank);
|
|
57
|
+
if (matches.length === 0)
|
|
58
|
+
return "";
|
|
59
|
+
return matches[0].name.slice(query.length);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Claude-style inline argument hint: when a command expects a value but none is
|
|
63
|
+
* typed yet, show the options in-line as a dim `[a|b|c]` placeholder — e.g.
|
|
64
|
+
* `/color ` → `[red|blue|green|…]`. Purely a hint (never accepted by Tab). Empty
|
|
65
|
+
* once a value is being typed, or when the command takes no listed options.
|
|
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
|
+
}
|
|
82
|
+
export function argHint(query) {
|
|
83
|
+
if (/^\/(?:color|theme)\s+$/i.test(query))
|
|
84
|
+
return `[${THEME_ORDER.join("|")}]`;
|
|
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}]` : "";
|
|
92
|
+
}
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import * as readline from "node:readline";
|
|
2
|
+
import { c } from "./colors.js";
|
|
3
|
+
import { TAKES_ARG, visibleCommands } from "./command-item.js";
|
|
4
|
+
import { argHint, filterCommands, ghostCompletion, isArgMode } 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
|
+
import { screenClear, screenComposer, screenPrint, screenScrollable, screenScrollLines, screenScrollPage, screenScrollToBottom, screenScrollToTop } from "./screen.js";
|
|
9
|
+
const DEBUG_INPUT = Boolean(process.env.COS_DEBUG_INPUT);
|
|
10
|
+
/** Color name inside a `/color <name>` suggestion, or null. */
|
|
11
|
+
function colorOf(name) {
|
|
12
|
+
const m = name.match(/^\/(?:color|theme)\s+(\w+)$/i);
|
|
13
|
+
return m && isThemeColor(m[1].toLowerCase()) ? m[1].toLowerCase() : null;
|
|
14
|
+
}
|
|
15
|
+
export function readCommand(caret, history, footer = "", placeholder = "", locked = () => false) {
|
|
16
|
+
if (!process.stdin.isTTY || process.env.TERM === "dumb")
|
|
17
|
+
return readSimple(caret);
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
const stdin = process.stdin;
|
|
20
|
+
const stdout = process.stdout;
|
|
21
|
+
// Re-arm stdin from scratch every call. External prompt UIs (the @inquirer
|
|
22
|
+
// mode/model pickers) and spinners can leave stray keypress listeners, a
|
|
23
|
+
// paused stream, or a non-raw terminal behind — any of which would swallow
|
|
24
|
+
// our keystrokes and make the composer look frozen. Clearing and re-enabling
|
|
25
|
+
// guarantees a clean, responsive input each time.
|
|
26
|
+
stdin.removeAllListeners("keypress");
|
|
27
|
+
readline.emitKeypressEvents(stdin);
|
|
28
|
+
// Keep raw mode ON for the whole shell session. Toggling it off after each
|
|
29
|
+
// command (then back on for the next prompt) intermittently drops keypress
|
|
30
|
+
// delivery on Windows consoles — which looked like a frozen prompt after
|
|
31
|
+
// running a command like /chat. The shell restores cooked mode on exit.
|
|
32
|
+
if (stdin.isTTY && !stdin.isRaw)
|
|
33
|
+
stdin.setRawMode(true);
|
|
34
|
+
stdin.resume();
|
|
35
|
+
let input = "";
|
|
36
|
+
let cursor = 0;
|
|
37
|
+
let paletteOpen = false;
|
|
38
|
+
let selected = 0;
|
|
39
|
+
let filtered = visibleCommands();
|
|
40
|
+
let histIdx = history.length;
|
|
41
|
+
const refilter = () => {
|
|
42
|
+
filtered = filterCommands(input);
|
|
43
|
+
if (selected >= filtered.length)
|
|
44
|
+
selected = Math.max(0, filtered.length - 1);
|
|
45
|
+
};
|
|
46
|
+
// Full-width input bar (Claude-style): a horizontal rule above and below a
|
|
47
|
+
// `❯ ` prompt spanning the whole terminal. "❯ " is 2 visible cols; input
|
|
48
|
+
// starts at column 2. Long lines scroll horizontally to keep the caret in
|
|
49
|
+
// view. Rendering is delegated to the screen engine, which pins this bar to
|
|
50
|
+
// the bottom of the terminal and floats the palette directly above it.
|
|
51
|
+
const MARKER_COLS = 2;
|
|
52
|
+
// Live theme preview for `/color <name>` suggestions: previewing the accent
|
|
53
|
+
// as the highlighted color changes, restoring it if the user backs out.
|
|
54
|
+
let colorPreviewOrig = null;
|
|
55
|
+
const applyColorPreview = () => {
|
|
56
|
+
// Preview the accent for the color currently being typed (completing any
|
|
57
|
+
// ghost value), so the whole UI re-themes live; restored if the user backs
|
|
58
|
+
// out. `/color gr` previews green; a bare `/color ` previews nothing.
|
|
59
|
+
const g = paletteOpen && cursor === input.length ? ghostCompletion(input) : "";
|
|
60
|
+
const sel = paletteOpen ? colorOf((input + g).trim()) : null;
|
|
61
|
+
if (sel) {
|
|
62
|
+
if (colorPreviewOrig === null)
|
|
63
|
+
colorPreviewOrig = accentName();
|
|
64
|
+
setAccent(sel);
|
|
65
|
+
}
|
|
66
|
+
else if (colorPreviewOrig !== null) {
|
|
67
|
+
setAccent(colorPreviewOrig);
|
|
68
|
+
colorPreviewOrig = null;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
// Build the composer (input bar + optional palette) and hand it to the
|
|
72
|
+
// screen engine, which pins the bar to the bottom of the terminal and floats
|
|
73
|
+
// the palette in the transcript rows directly above it — the bar never moves.
|
|
74
|
+
const render = () => {
|
|
75
|
+
applyColorPreview();
|
|
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
|
+
// Inline trailer at the caret (only when it sits at the end of the input):
|
|
82
|
+
// a ghost completion (`/ver`→`sion`, `/color gr`→`een`), or — when a value
|
|
83
|
+
// is expected but not yet typed — a dim argument hint (`/color `→`[red|…]`).
|
|
84
|
+
const atEnd = paletteOpen && cursor === input.length;
|
|
85
|
+
const ghost = atEnd ? ghostCompletion(input) : "";
|
|
86
|
+
const hint = atEnd && !ghost ? argHint(input) : "";
|
|
87
|
+
const trailer = ghost || hint;
|
|
88
|
+
const start = cursor > field ? cursor - field : 0;
|
|
89
|
+
const visInput = input.slice(start, start + field);
|
|
90
|
+
const visTrailer = start + visInput.length >= input.length ? trailer.slice(0, field - visInput.length) : "";
|
|
91
|
+
// Empty + closed → show the dim italic placeholder (it never becomes part
|
|
92
|
+
// of the message; typing the first char replaces it, deleting brings it
|
|
93
|
+
// back). Otherwise render the typed text and any ghost completion.
|
|
94
|
+
const showPlaceholder = input === "" && !paletteOpen && placeholder !== "";
|
|
95
|
+
const bodyText = showPlaceholder ? placeholder.slice(0, field) : visInput;
|
|
96
|
+
const body = showPlaceholder ? c.placeholder(bodyText) : c.value(bodyText);
|
|
97
|
+
const promptCols = MARKER_COLS + bodyText.length + (showPlaceholder ? 0 : visTrailer.length);
|
|
98
|
+
const pad = " ".repeat(Math.max(0, total - promptCols));
|
|
99
|
+
// The two divider rules carry the runtime accent (/color); the prompt
|
|
100
|
+
// marker stays fixed brand green (branding, never recolored).
|
|
101
|
+
const rule = MARGIN + c.rule("─".repeat(total));
|
|
102
|
+
const promptLine = MARGIN + c.brand("›") + " " + body + (visTrailer ? c.dim(visTrailer) : "") + pad;
|
|
103
|
+
const core = [rule, promptLine, rule, typeof footer === "function" ? footer() : footer]; // fixed 4-row composer core
|
|
104
|
+
// The command palette floats ABOVE the bar when open — except in the
|
|
105
|
+
// value-entry context (`/color <value>`), where the inline arg hint / ghost
|
|
106
|
+
// on the prompt line replaces the list. The caret sits on the prompt line
|
|
107
|
+
// (core index 1) at the text column (1-based).
|
|
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);
|
|
114
|
+
const paletteLines = paletteOpen && !argMode ? paletteView(filtered, selected, input) : [];
|
|
115
|
+
const caretCol = MARGIN.length + MARKER_COLS + (cursor - start) + 1;
|
|
116
|
+
screenComposer(paletteLines, core, 1, caretCol);
|
|
117
|
+
};
|
|
118
|
+
process.stdout.on("resize", render);
|
|
119
|
+
let lastFooter = typeof footer === "function" ? footer() : footer;
|
|
120
|
+
const footerTimer = setInterval(() => {
|
|
121
|
+
const next = typeof footer === "function" ? footer() : footer;
|
|
122
|
+
if (next !== lastFooter) {
|
|
123
|
+
lastFooter = next;
|
|
124
|
+
render();
|
|
125
|
+
}
|
|
126
|
+
}, 500);
|
|
127
|
+
footerTimer.unref();
|
|
128
|
+
const finish = (res) => {
|
|
129
|
+
paletteOpen = false;
|
|
130
|
+
// Undo any live color preview — the /color command re-applies + persists
|
|
131
|
+
// the chosen color; other exits should leave the accent as it was.
|
|
132
|
+
if (colorPreviewOrig !== null) {
|
|
133
|
+
setAccent(colorPreviewOrig);
|
|
134
|
+
colorPreviewOrig = null;
|
|
135
|
+
}
|
|
136
|
+
// Clear the composer to an empty prompt so the just-submitted text doesn't
|
|
137
|
+
// linger in the bar while the response streams into the transcript above.
|
|
138
|
+
const total = contentWidth();
|
|
139
|
+
const rule = MARGIN + c.rule("─".repeat(total));
|
|
140
|
+
const empty = MARGIN + c.brand("›") + " " + " ".repeat(Math.max(0, total - MARKER_COLS));
|
|
141
|
+
screenComposer([], [rule, empty, rule, typeof footer === "function" ? footer() : footer], 1, MARGIN.length + MARKER_COLS + 1);
|
|
142
|
+
clearInterval(footerTimer);
|
|
143
|
+
process.stdout.removeListener("resize", render);
|
|
144
|
+
stdin.removeListener("keypress", onKey);
|
|
145
|
+
// Raw mode is intentionally left ON between prompts (see the setup note);
|
|
146
|
+
// the shell restores cooked mode when it exits.
|
|
147
|
+
resolve(res);
|
|
148
|
+
};
|
|
149
|
+
const setInput = (next, open) => {
|
|
150
|
+
input = locked() && !next.startsWith("/") ? "" : next;
|
|
151
|
+
cursor = input.length;
|
|
152
|
+
paletteOpen = open ?? input.startsWith("/");
|
|
153
|
+
if (paletteOpen) {
|
|
154
|
+
selected = 0;
|
|
155
|
+
refilter();
|
|
156
|
+
}
|
|
157
|
+
render();
|
|
158
|
+
};
|
|
159
|
+
// Input-history recall. On ↑/↓ when there's nothing to scroll, and always on
|
|
160
|
+
// Ctrl+P / Ctrl+N (so history stays reachable even in a long, scrollable chat).
|
|
161
|
+
const histPrev = () => {
|
|
162
|
+
if (!history.length)
|
|
163
|
+
return;
|
|
164
|
+
histIdx = Math.max(0, histIdx - 1);
|
|
165
|
+
setInput(history[histIdx] ?? "", false);
|
|
166
|
+
};
|
|
167
|
+
const histNext = () => {
|
|
168
|
+
if (!history.length)
|
|
169
|
+
return;
|
|
170
|
+
histIdx = Math.min(history.length, histIdx + 1);
|
|
171
|
+
setInput(histIdx === history.length ? "" : history[histIdx], false);
|
|
172
|
+
};
|
|
173
|
+
const acceptGhost = () => {
|
|
174
|
+
const ghost = ghostCompletion(input);
|
|
175
|
+
if (paletteOpen && cursor === input.length && ghost) {
|
|
176
|
+
setInput(input + ghost, true);
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
};
|
|
181
|
+
const onKey = (str, key) => {
|
|
182
|
+
try {
|
|
183
|
+
handleKey(str, key);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
// A render hiccup must never silently freeze input — surface it and
|
|
187
|
+
// keep the reader alive.
|
|
188
|
+
stdout.write(`\n${c.err("Input error:")} ${err.message}\n`);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const handleKey = (str, key) => {
|
|
192
|
+
if (!key)
|
|
193
|
+
return;
|
|
194
|
+
if (DEBUG_INPUT) {
|
|
195
|
+
screenPrint([
|
|
196
|
+
` \x1b[36m[key] name=${key.name ?? "?"} ctrl=${!!key.ctrl} shift=${!!key.shift} meta=${!!key.meta} str=${JSON.stringify(str)}\x1b[0m`
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
// Drop stray CSI fragments (e.g. mouse-report leftovers) so they can never
|
|
200
|
+
// land in the input buffer — wheel scrolling is handled by the screen engine.
|
|
201
|
+
if (key.name === undefined && !str)
|
|
202
|
+
return;
|
|
203
|
+
if (key.ctrl && key.name === "c") {
|
|
204
|
+
if (input.length)
|
|
205
|
+
return setInput("");
|
|
206
|
+
return finish({ type: "sigint" });
|
|
207
|
+
}
|
|
208
|
+
if (key.ctrl && key.name === "d")
|
|
209
|
+
return finish({ type: "exit" });
|
|
210
|
+
if (key.ctrl && key.name === "l") {
|
|
211
|
+
screenClear();
|
|
212
|
+
return render();
|
|
213
|
+
}
|
|
214
|
+
if (key.ctrl && (key.name === "u" || key.name === "k"))
|
|
215
|
+
return setInput("");
|
|
216
|
+
if (key.ctrl && key.name === "a") {
|
|
217
|
+
cursor = 0;
|
|
218
|
+
return render();
|
|
219
|
+
}
|
|
220
|
+
// History recall (always available; ↑/↓ scroll the transcript instead when
|
|
221
|
+
// there's history to scroll through).
|
|
222
|
+
if (key.ctrl && key.name === "p")
|
|
223
|
+
return histPrev();
|
|
224
|
+
if (key.ctrl && key.name === "n")
|
|
225
|
+
return histNext();
|
|
226
|
+
// ── Transcript scrolling (composer stays fixed) ──────────────────────
|
|
227
|
+
// Page keys always scroll history; Shift+↑/↓ nudge a line. Home/End scroll
|
|
228
|
+
// to the top/latest only when the input is empty (else they move the
|
|
229
|
+
// cursor). Mouse-wheel scrolling is handled in the screen engine.
|
|
230
|
+
if (key.name === "pageup")
|
|
231
|
+
return screenScrollPage(1);
|
|
232
|
+
if (key.name === "pagedown")
|
|
233
|
+
return screenScrollPage(-1);
|
|
234
|
+
if (key.shift && key.name === "up")
|
|
235
|
+
return screenScrollLines(1);
|
|
236
|
+
if (key.shift && key.name === "down")
|
|
237
|
+
return screenScrollLines(-1);
|
|
238
|
+
if (key.name === "home" && input.length === 0)
|
|
239
|
+
return screenScrollToTop();
|
|
240
|
+
if (key.name === "end" && input.length === 0)
|
|
241
|
+
return screenScrollToBottom();
|
|
242
|
+
if (key.name === "return" || key.name === "enter") {
|
|
243
|
+
if (locked() && !input.startsWith("/"))
|
|
244
|
+
return render();
|
|
245
|
+
// Value-entry (`/color <value>`): run what's typed, completing any ghost
|
|
246
|
+
// first (`/color gr` → `/color green`; a bare `/color ` → the picker).
|
|
247
|
+
if (paletteOpen && /^\/(?:color|theme)\s/i.test(input)) {
|
|
248
|
+
const g = cursor === input.length ? ghostCompletion(input) : "";
|
|
249
|
+
return finish({ type: "line", value: (input + g).trim() });
|
|
250
|
+
}
|
|
251
|
+
// Otherwise a single Enter RUNS the highlighted command (arg-taking ones
|
|
252
|
+
// open their own picker when given none). Tab inserts-and-adds-an-arg.
|
|
253
|
+
if (paletteOpen && filtered.length) {
|
|
254
|
+
return finish({ type: "line", value: filtered[selected].name });
|
|
255
|
+
}
|
|
256
|
+
return finish({ type: "line", value: input });
|
|
257
|
+
}
|
|
258
|
+
if (key.name === "escape") {
|
|
259
|
+
if (paletteOpen) {
|
|
260
|
+
paletteOpen = false;
|
|
261
|
+
render();
|
|
262
|
+
}
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
// ↑/↓ — palette navigation; else SCROLL the transcript when there's
|
|
266
|
+
// something to scroll (this is also where the mouse WHEEL lands, since the
|
|
267
|
+
// terminal's alternate-scroll mode turns the wheel into ↑/↓ keys); else
|
|
268
|
+
// recall input history. History is always available on Ctrl+P / Ctrl+N.
|
|
269
|
+
if (key.name === "up") {
|
|
270
|
+
if (paletteOpen) {
|
|
271
|
+
selected = Math.max(0, selected - 1);
|
|
272
|
+
return render();
|
|
273
|
+
}
|
|
274
|
+
if (screenScrollable())
|
|
275
|
+
return screenScrollLines(1); // wheel/↑ → older
|
|
276
|
+
return histPrev();
|
|
277
|
+
}
|
|
278
|
+
if (key.name === "down") {
|
|
279
|
+
if (paletteOpen) {
|
|
280
|
+
selected = Math.min(filtered.length - 1, selected + 1);
|
|
281
|
+
return render();
|
|
282
|
+
}
|
|
283
|
+
if (screenScrollable())
|
|
284
|
+
return screenScrollLines(-1); // wheel/↓ → newer
|
|
285
|
+
return histNext();
|
|
286
|
+
}
|
|
287
|
+
if (key.name === "tab") {
|
|
288
|
+
if (acceptGhost())
|
|
289
|
+
return;
|
|
290
|
+
// Insert the command (closing the palette) so an argument can be typed;
|
|
291
|
+
// arg-taking commands get a trailing space. A follow-up Enter runs it.
|
|
292
|
+
if (paletteOpen && filtered.length) {
|
|
293
|
+
const chosen = filtered[selected].name;
|
|
294
|
+
setInput(TAKES_ARG.has(chosen) ? chosen + " " : chosen, false);
|
|
295
|
+
}
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
// ←/→ switch chat type ONLY on an empty composer with the palette shut.
|
|
299
|
+
// Any typed text, and they are cursor keys again — otherwise fixing a
|
|
300
|
+
// typo would change which chat you are in. Modals, pickers and the /btw
|
|
301
|
+
// overlay capture stdin themselves, so this handler cannot run while one
|
|
302
|
+
// is open; no extra guard is needed for them.
|
|
303
|
+
if ((key.name === "left" || key.name === "right") && input === "" && !paletteOpen) {
|
|
304
|
+
return finish({ type: "switch", dir: key.name });
|
|
305
|
+
}
|
|
306
|
+
if (key.name === "left") {
|
|
307
|
+
cursor = Math.max(0, cursor - 1);
|
|
308
|
+
return render();
|
|
309
|
+
}
|
|
310
|
+
if (key.name === "right") {
|
|
311
|
+
// Right at end accepts the ghost (Claude-style); otherwise moves.
|
|
312
|
+
if (cursor === input.length && acceptGhost())
|
|
313
|
+
return;
|
|
314
|
+
cursor = Math.min(input.length, cursor + 1);
|
|
315
|
+
return render();
|
|
316
|
+
}
|
|
317
|
+
if (key.name === "home") {
|
|
318
|
+
cursor = 0;
|
|
319
|
+
return render();
|
|
320
|
+
}
|
|
321
|
+
if (key.name === "end") {
|
|
322
|
+
cursor = input.length;
|
|
323
|
+
return render();
|
|
324
|
+
}
|
|
325
|
+
if (key.name === "backspace") {
|
|
326
|
+
if (cursor > 0) {
|
|
327
|
+
input = input.slice(0, cursor - 1) + input.slice(cursor);
|
|
328
|
+
cursor--;
|
|
329
|
+
}
|
|
330
|
+
paletteOpen = input.startsWith("/");
|
|
331
|
+
if (paletteOpen) {
|
|
332
|
+
selected = 0;
|
|
333
|
+
refilter();
|
|
334
|
+
}
|
|
335
|
+
return render();
|
|
336
|
+
}
|
|
337
|
+
if (key.name === "delete") {
|
|
338
|
+
input = input.slice(0, cursor) + input.slice(cursor + 1);
|
|
339
|
+
paletteOpen = input.startsWith("/");
|
|
340
|
+
if (paletteOpen)
|
|
341
|
+
refilter();
|
|
342
|
+
return render();
|
|
343
|
+
}
|
|
344
|
+
// Printable character.
|
|
345
|
+
if (str && !key.ctrl && !key.meta && str >= " " && str !== "\x7f") {
|
|
346
|
+
const next = input.slice(0, cursor) + str + input.slice(cursor);
|
|
347
|
+
if (locked() && !next.startsWith("/"))
|
|
348
|
+
return;
|
|
349
|
+
input = next;
|
|
350
|
+
cursor += str.length;
|
|
351
|
+
if (input.startsWith("/")) {
|
|
352
|
+
paletteOpen = true;
|
|
353
|
+
selected = 0;
|
|
354
|
+
refilter();
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
paletteOpen = false;
|
|
358
|
+
}
|
|
359
|
+
render();
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
stdin.on("keypress", onKey);
|
|
363
|
+
render();
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/** Non-TTY fallback: a plain line read (pipes / CI), no overlay. */
|
|
367
|
+
function readSimple(caret) {
|
|
368
|
+
return new Promise((resolve) => {
|
|
369
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
370
|
+
let done = false;
|
|
371
|
+
rl.on("close", () => {
|
|
372
|
+
if (!done) {
|
|
373
|
+
done = true;
|
|
374
|
+
resolve({ type: "exit" });
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
rl.question(caret, (answer) => {
|
|
378
|
+
done = true;
|
|
379
|
+
rl.close();
|
|
380
|
+
resolve({ type: "line", value: answer });
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
}
|
|
13
|
+
/** The order groups render in (only groups with matches are shown). */
|
|
14
|
+
export const GROUP_ORDER = [
|
|
15
|
+
"Chat",
|
|
16
|
+
"Sessions",
|
|
17
|
+
"Context",
|
|
18
|
+
"Models",
|
|
19
|
+
"Files",
|
|
20
|
+
"Account",
|
|
21
|
+
"Developer"
|
|
22
|
+
];
|
|
23
|
+
export const COMMANDS = [
|
|
24
|
+
{ name: "/details", desc: "Show the last bounded command output", group: "Context", rank: 10 },
|
|
25
|
+
{ name: "/chat", desc: "Start chatting with Carrier", group: "Chat", rank: 1 },
|
|
26
|
+
{ name: "/switch", desc: "Switch chat: Carrier ⇄ Standard", group: "Chat", rank: 2 },
|
|
27
|
+
{ name: "/websearch", desc: "Search the web — or a query to search now", group: "Chat", rank: 3, arg: "query" },
|
|
28
|
+
{ name: "/sources", desc: "Sources from the last search", group: "Chat", rank: 4 },
|
|
29
|
+
{ name: "/open", desc: "Open a source in your browser", group: "Chat", rank: 5, arg: "n" },
|
|
30
|
+
// Standard chat only — Carrier Chat always uses its own models, so the web
|
|
31
|
+
// doesn't render the toggle there either (shouldShowToggle).
|
|
32
|
+
{
|
|
33
|
+
name: "/fast",
|
|
34
|
+
desc: "Fast mode — quicker, less refinement",
|
|
35
|
+
group: "Models",
|
|
36
|
+
rank: 3,
|
|
37
|
+
chatTypes: ["standard"],
|
|
38
|
+
arg: "on|off"
|
|
39
|
+
},
|
|
40
|
+
{ name: "/hipwr", desc: "High Power — 4-pass refinement", group: "Models", rank: 4, arg: "on|off" },
|
|
41
|
+
{
|
|
42
|
+
name: "/sia",
|
|
43
|
+
desc: "Clarifying questions — Auto lets Carrier OS decide",
|
|
44
|
+
group: "Chat",
|
|
45
|
+
rank: 6,
|
|
46
|
+
chatTypes: ["standard"],
|
|
47
|
+
arg: "auto|off|status"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "/btw",
|
|
51
|
+
desc: "Ask a quick side question without adding it to the conversation",
|
|
52
|
+
group: "Chat",
|
|
53
|
+
rank: 7,
|
|
54
|
+
arg: "question"
|
|
55
|
+
},
|
|
56
|
+
{ name: "/new", desc: "Start a new conversation", group: "Sessions", rank: 1, arg: "title" },
|
|
57
|
+
{ name: "/clear", desc: "Start a new task — the current one stays in /sessions", group: "Sessions", rank: 1 },
|
|
58
|
+
{ name: "/resume", desc: "Continue an earlier conversation (its permission mode, never its approvals)", group: "Sessions", rank: 2 },
|
|
59
|
+
{ name: "/sessions", desc: "List conversations, numbered", group: "Sessions", rank: 2 },
|
|
60
|
+
{ name: "/session", desc: "Continue a session — /session 2", group: "Sessions", rank: 3, arg: "n" },
|
|
61
|
+
{ name: "/history", desc: "Transcript — /history 2", group: "Sessions", rank: 4, arg: "n" },
|
|
62
|
+
{ name: "/context", desc: "What the next message is sent with — try /context project", group: "Context", rank: 1, arg: "project" },
|
|
63
|
+
{ name: "/memory", desc: "Snapshots and restructures — /memory 2", group: "Context", rank: 2, arg: "n" },
|
|
64
|
+
{ name: "/compact", desc: "Summarise earlier messages; keep the task, plan, changes and tests", group: "Context", rank: 2 },
|
|
65
|
+
{ name: "/permissions", desc: "Manual · Plan · Accept Edits · Auto", group: "Chat", rank: 1, arg: "manual|plan|accept-edits|auto" },
|
|
66
|
+
{ name: "/plan", desc: "Plan mode — investigate and plan; no changes or commands", group: "Chat", rank: 1 },
|
|
67
|
+
{ name: "/model", desc: "List & switch provider model", group: "Models", rank: 1, arg: "model" },
|
|
68
|
+
{ name: "/mode", desc: "Carrier mode — or /mode manual|plan|accept-edits for permissions", group: "Models", rank: 2, arg: "mode" },
|
|
69
|
+
{ name: "/upload", desc: "Upload file(s) — many + * globs", group: "Files", rank: 1, arg: "path" },
|
|
70
|
+
{ name: "/attach", desc: "Attach an upload to your next message", group: "Files", rank: 2, arg: "file" },
|
|
71
|
+
{ name: "/detach", desc: "Clear attached files", group: "Files", rank: 3 },
|
|
72
|
+
{ name: "/files", desc: "Local project tree & uploaded files", group: "Files", rank: 4, arg: "local|uploaded" },
|
|
73
|
+
{ name: "/search", desc: "Search the local project for text", group: "Files", rank: 5, arg: "text" },
|
|
74
|
+
{ name: "/review", desc: "Review this repository's changes (read-only)", group: "Files", rank: 1, arg: "repository" },
|
|
75
|
+
{ name: "/changes", desc: "File changes Carrier OS applied here", group: "Files", rank: 6 },
|
|
76
|
+
{ name: "/undo", desc: "Undo the latest change — /undo --repo <name> for another repository", group: "Files", rank: 7, arg: "operation" },
|
|
77
|
+
{ name: "/repo", desc: "Active repository — /repo use <name> to switch", group: "Context", rank: 3, arg: "use" },
|
|
78
|
+
{ name: "/repos", desc: "Repositories in this workspace", group: "Context", rank: 4 },
|
|
79
|
+
{ name: "/whoami", desc: "Your signed-in account", group: "Account", rank: 1 },
|
|
80
|
+
{ name: "/usage", desc: "View API usage", group: "Account", rank: 2 },
|
|
81
|
+
{ name: "/settings", desc: "CLI settings — commands, updates, channel, update-interval", group: "Account", rank: 3, arg: "commands" },
|
|
82
|
+
{ name: "/login", desc: "Sign in via your browser", group: "Account", rank: 3 },
|
|
83
|
+
{ name: "/logout", desc: "Remove saved credentials", group: "Account", rank: 4 },
|
|
84
|
+
{ name: "/help", desc: "Show available commands", group: "Developer", rank: 1 },
|
|
85
|
+
{ name: "/color", desc: "Change the accent color", group: "Developer", rank: 2 },
|
|
86
|
+
{ name: "/doctor", desc: "Run diagnostics", group: "Developer", rank: 3 },
|
|
87
|
+
{ name: "/version", desc: "Show CLI version", group: "Developer", rank: 4 },
|
|
88
|
+
{
|
|
89
|
+
name: "/update",
|
|
90
|
+
desc: "Check for and install the latest CLI version (your update channel)",
|
|
91
|
+
group: "Developer",
|
|
92
|
+
rank: 5
|
|
93
|
+
},
|
|
94
|
+
{ name: "/exit", desc: "Leave the shell", group: "Developer", rank: 5 }
|
|
95
|
+
];
|
|
96
|
+
/** Commands that take an argument — completed with a trailing space. */
|
|
97
|
+
export const TAKES_ARG = new Set([
|
|
98
|
+
"/mode",
|
|
99
|
+
"/permissions",
|
|
100
|
+
"/model",
|
|
101
|
+
"/websearch",
|
|
102
|
+
"/fast",
|
|
103
|
+
"/hipwr",
|
|
104
|
+
"/sia",
|
|
105
|
+
"/settings",
|
|
106
|
+
"/btw",
|
|
107
|
+
"/open",
|
|
108
|
+
"/memory",
|
|
109
|
+
"/new",
|
|
110
|
+
"/session",
|
|
111
|
+
"/history",
|
|
112
|
+
"/upload",
|
|
113
|
+
"/attach",
|
|
114
|
+
"/files",
|
|
115
|
+
"/search",
|
|
116
|
+
"/review",
|
|
117
|
+
"/repo",
|
|
118
|
+
"/undo",
|
|
119
|
+
"/context",
|
|
120
|
+
"/color",
|
|
121
|
+
"/theme"
|
|
122
|
+
]);
|
|
123
|
+
const GROUP_INDEX = new Map(GROUP_ORDER.map((g, i) => [g, i]));
|
|
124
|
+
/** Stable grouped ordering: by group (GROUP_ORDER), then rank within a group. */
|
|
125
|
+
export function byGroupThenRank(a, b) {
|
|
126
|
+
const g = (GROUP_INDEX.get(a.group) ?? 0) - (GROUP_INDEX.get(b.group) ?? 0);
|
|
127
|
+
return g !== 0 ? g : a.rank - b.rank;
|
|
128
|
+
}
|
|
@@ -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
|
+
}
|