@carrieros/cli 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -64
- package/dist/commands/attach.js +45 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +81 -15
- package/dist/commands/context.js +200 -0
- package/dist/commands/doctor.js +63 -3
- package/dist/commands/files.js +84 -23
- package/dist/commands/help.js +1 -0
- package/dist/commands/history.js +88 -23
- package/dist/commands/login.js +31 -7
- package/dist/commands/logout.js +1 -0
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +39 -3
- package/dist/commands/modes.js +4 -1
- package/dist/commands/permissions.js +77 -0
- package/dist/commands/project.js +106 -0
- package/dist/commands/repo.js +146 -0
- package/dist/commands/repos.js +61 -0
- package/dist/commands/review.js +92 -0
- package/dist/commands/scope.js +9 -6
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +224 -65
- package/dist/commands/settings.js +94 -0
- package/dist/commands/update.js +229 -0
- package/dist/commands/upload.js +204 -31
- package/dist/commands/usage.js +213 -17
- package/dist/commands/whoami.js +12 -9
- package/dist/ide/editor-context.js +275 -0
- package/dist/ide/ide-session.js +355 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +26 -1
- package/dist/services/api.js +315 -15
- package/dist/services/auth-origin.js +20 -0
- package/dist/services/chat-stream.js +168 -0
- package/dist/services/checkpoints.js +278 -0
- package/dist/services/client-tools.js +352 -0
- package/dist/services/code-intel.js +243 -0
- package/dist/services/code-symbols.js +94 -0
- package/dist/services/coding-workflow.js +554 -0
- package/dist/services/command-coordinator.js +273 -0
- package/dist/services/command-policy.js +434 -0
- package/dist/services/config.js +311 -24
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +296 -23
- package/dist/services/device-auth.js +72 -35
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -0
- package/dist/services/execution-platform.js +30 -0
- package/dist/services/file-detect.js +104 -0
- package/dist/services/file-resolver.js +199 -0
- package/dist/services/file-upload.js +126 -0
- package/dist/services/folder-key.js +22 -0
- package/dist/services/git-tools.js +429 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +85 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/instruction-resolver.js +54 -0
- package/dist/services/job-helper.js +328 -0
- package/dist/services/local-files.js +639 -0
- package/dist/services/local-tools.js +937 -0
- package/dist/services/login-flow.js +55 -17
- package/dist/services/meta.js +3 -1
- package/dist/services/mutation-coordinator.js +327 -0
- package/dist/services/mutation-groups.js +309 -0
- package/dist/services/mutation-recovery.js +159 -0
- package/dist/services/mutations.js +679 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +5 -2
- package/dist/services/packaged-update.js +403 -0
- package/dist/services/packaged.js +39 -0
- package/dist/services/permission-mode.js +60 -0
- package/dist/services/process-runner.js +412 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/result-reconciliation.js +49 -0
- package/dist/services/secure-store.js +217 -0
- package/dist/services/session-resolver.js +113 -0
- package/dist/services/sia.js +51 -0
- package/dist/services/supported-runtime.js +59 -0
- package/dist/services/task-context.js +212 -0
- package/dist/services/task-snapshot.js +38 -0
- package/dist/services/tool-result-outbox.js +195 -0
- package/dist/services/update.js +311 -0
- package/dist/services/workspace-registry.js +310 -0
- package/dist/services/workspace.js +580 -0
- package/dist/shell/shell-chat.js +1297 -59
- package/dist/shell/shell-commands.js +243 -12
- package/dist/shell/shell-prompt.js +94 -11
- package/dist/shell/shell-renderer.js +8 -20
- package/dist/shell/shell-router.js +19 -3
- package/dist/shell/shell.js +252 -22
- package/dist/shell/task-context-view.js +40 -0
- package/dist/types/index.js +3 -1
- package/dist/ui/agent-cards.js +111 -0
- package/dist/ui/agent-presentation.js +131 -0
- package/dist/ui/approval.js +111 -0
- package/dist/ui/banner.js +31 -48
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +334 -0
- package/dist/ui/chat-renderer.js +207 -14
- package/dist/ui/colors.js +12 -8
- package/dist/ui/command-details.js +11 -0
- package/dist/ui/command-filter.js +26 -5
- package/dist/ui/command-palette.js +44 -14
- package/dist/ui/command-registry.js +92 -10
- package/dist/ui/command-review.js +187 -0
- package/dist/ui/composer-layout.js +48 -1
- package/dist/ui/conversation.js +450 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +4 -2
- package/dist/ui/markdown.js +63 -9
- package/dist/ui/message.js +14 -31
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +19 -11
- package/dist/ui/select.js +191 -29
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/task-context-card.js +99 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/trust.js +88 -0
- package/dist/ui/ui.js +27 -1
- package/package.json +18 -4
- package/dist/ui/activity.js +0 -77
|
@@ -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";
|
|
@@ -12,8 +12,8 @@ function colorOf(name) {
|
|
|
12
12
|
const m = name.match(/^\/(?:color|theme)\s+(\w+)$/i);
|
|
13
13
|
return m && isThemeColor(m[1].toLowerCase()) ? m[1].toLowerCase() : null;
|
|
14
14
|
}
|
|
15
|
-
export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
16
|
-
if (!process.stdin.isTTY)
|
|
15
|
+
export function readCommand(caret, history, footer = "", placeholder = "", locked = () => false) {
|
|
16
|
+
if (!process.stdin.isTTY || process.env.TERM === "dumb")
|
|
17
17
|
return readSimple(caret);
|
|
18
18
|
return new Promise((resolve) => {
|
|
19
19
|
const stdin = process.stdin;
|
|
@@ -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);
|
|
@@ -98,18 +98,33 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
|
98
98
|
const pad = " ".repeat(Math.max(0, total - promptCols));
|
|
99
99
|
// The two divider rules carry the runtime accent (/color); the prompt
|
|
100
100
|
// marker stays fixed brand green (branding, never recolored).
|
|
101
|
-
const rule = MARGIN + c.
|
|
102
|
-
const promptLine = MARGIN + c.
|
|
103
|
-
const core = [rule, promptLine, rule, footer]; // fixed 4-row composer core
|
|
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
104
|
// The command palette floats ABOVE the bar when open — except in the
|
|
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);
|
|
112
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();
|
|
113
128
|
const finish = (res) => {
|
|
114
129
|
paletteOpen = false;
|
|
115
130
|
// Undo any live color preview — the /color command re-applies + persists
|
|
@@ -121,16 +136,18 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
|
121
136
|
// Clear the composer to an empty prompt so the just-submitted text doesn't
|
|
122
137
|
// linger in the bar while the response streams into the transcript above.
|
|
123
138
|
const total = contentWidth();
|
|
124
|
-
const rule = MARGIN + c.
|
|
125
|
-
const empty = MARGIN + c.
|
|
126
|
-
screenComposer([], [rule, empty, rule, footer], 1, MARGIN.length + MARKER_COLS + 1);
|
|
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);
|
|
127
144
|
stdin.removeListener("keypress", onKey);
|
|
128
145
|
// Raw mode is intentionally left ON between prompts (see the setup note);
|
|
129
146
|
// the shell restores cooked mode when it exits.
|
|
130
147
|
resolve(res);
|
|
131
148
|
};
|
|
132
149
|
const setInput = (next, open) => {
|
|
133
|
-
input = next;
|
|
150
|
+
input = locked() && !next.startsWith("/") ? "" : next;
|
|
134
151
|
cursor = input.length;
|
|
135
152
|
paletteOpen = open ?? input.startsWith("/");
|
|
136
153
|
if (paletteOpen) {
|
|
@@ -223,6 +240,8 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
|
223
240
|
if (key.name === "end" && input.length === 0)
|
|
224
241
|
return screenScrollToBottom();
|
|
225
242
|
if (key.name === "return" || key.name === "enter") {
|
|
243
|
+
if (locked() && !input.startsWith("/"))
|
|
244
|
+
return render();
|
|
226
245
|
// Value-entry (`/color <value>`): run what's typed, completing any ghost
|
|
227
246
|
// first (`/color gr` → `/color green`; a bare `/color ` → the picker).
|
|
228
247
|
if (paletteOpen && /^\/(?:color|theme)\s/i.test(input)) {
|
|
@@ -276,6 +295,14 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
|
276
295
|
}
|
|
277
296
|
return;
|
|
278
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
|
+
}
|
|
279
306
|
if (key.name === "left") {
|
|
280
307
|
cursor = Math.max(0, cursor - 1);
|
|
281
308
|
return render();
|
|
@@ -316,7 +343,10 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
|
|
|
316
343
|
}
|
|
317
344
|
// Printable character.
|
|
318
345
|
if (str && !key.ctrl && !key.meta && str >= " " && str !== "\x7f") {
|
|
319
|
-
|
|
346
|
+
const next = input.slice(0, cursor) + str + input.slice(cursor);
|
|
347
|
+
if (locked() && !next.startsWith("/"))
|
|
348
|
+
return;
|
|
349
|
+
input = next;
|
|
320
350
|
cursor += str.length;
|
|
321
351
|
if (input.startsWith("/")) {
|
|
322
352
|
paletteOpen = true;
|
|
@@ -1,40 +1,122 @@
|
|
|
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",
|
|
8
21
|
"Developer"
|
|
9
22
|
];
|
|
10
23
|
export const COMMANDS = [
|
|
24
|
+
{ name: "/details", desc: "Show the last bounded command output", group: "Context", rank: 10 },
|
|
11
25
|
{ name: "/chat", desc: "Start chatting with Carrier", group: "Chat", rank: 1 },
|
|
12
26
|
{ name: "/switch", desc: "Switch chat: Carrier ⇄ Standard", group: "Chat", rank: 2 },
|
|
13
|
-
{ name: "/
|
|
14
|
-
{ name: "/
|
|
15
|
-
{ name: "/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 },
|
|
22
80
|
{ name: "/usage", desc: "View API usage", group: "Account", rank: 2 },
|
|
23
|
-
{ name: "/
|
|
81
|
+
{ name: "/settings", desc: "CLI settings — /settings commands on|off", group: "Account", rank: 3, arg: "commands" },
|
|
82
|
+
{ name: "/login", desc: "Sign in via your browser", group: "Account", rank: 3 },
|
|
24
83
|
{ name: "/logout", desc: "Remove saved credentials", group: "Account", rank: 4 },
|
|
25
84
|
{ name: "/help", desc: "Show available commands", group: "Developer", rank: 1 },
|
|
26
85
|
{ name: "/color", desc: "Change the accent color", group: "Developer", rank: 2 },
|
|
27
86
|
{ name: "/doctor", desc: "Run diagnostics", group: "Developer", rank: 3 },
|
|
28
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",
|
|
91
|
+
group: "Developer",
|
|
92
|
+
rank: 5
|
|
93
|
+
},
|
|
29
94
|
{ name: "/exit", desc: "Leave the shell", group: "Developer", rank: 5 }
|
|
30
95
|
];
|
|
31
96
|
/** Commands that take an argument — completed with a trailing space. */
|
|
32
97
|
export const TAKES_ARG = new Set([
|
|
33
98
|
"/mode",
|
|
99
|
+
"/permissions",
|
|
34
100
|
"/model",
|
|
101
|
+
"/websearch",
|
|
102
|
+
"/fast",
|
|
103
|
+
"/hipwr",
|
|
104
|
+
"/sia",
|
|
105
|
+
"/settings",
|
|
106
|
+
"/btw",
|
|
107
|
+
"/open",
|
|
108
|
+
"/memory",
|
|
109
|
+
"/new",
|
|
35
110
|
"/session",
|
|
36
111
|
"/history",
|
|
37
112
|
"/upload",
|
|
113
|
+
"/attach",
|
|
114
|
+
"/files",
|
|
115
|
+
"/search",
|
|
116
|
+
"/review",
|
|
117
|
+
"/repo",
|
|
118
|
+
"/undo",
|
|
119
|
+
"/context",
|
|
38
120
|
"/color",
|
|
39
121
|
"/theme"
|
|
40
122
|
]);
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { executionContract } from "../services/execution-platform.js";
|
|
3
|
+
import { displayCommand } from "../services/command-policy.js";
|
|
4
|
+
import { c } from "./colors.js";
|
|
5
|
+
import { MARGIN, contentWidth } from "./composer-layout.js";
|
|
6
|
+
import { clip, stripControl, wrapText } from "./conversation.js";
|
|
7
|
+
import { approvalCard, cardHeader } from "./agent-cards.js";
|
|
8
|
+
/**
|
|
9
|
+
* What a person sees before and after a local command.
|
|
10
|
+
*
|
|
11
|
+
* The card is deliberately compact — a continuation of the conversation, not a
|
|
12
|
+
* form — but it still carries EVERY fact the decision needs: the exact command,
|
|
13
|
+
* where it will run, its risk tier, whether it may use the network, the real
|
|
14
|
+
* script text behind an npm script, the model's reason, and any policy notes.
|
|
15
|
+
* Nothing is summarised away; only the labelling is lighter.
|
|
16
|
+
*
|
|
17
|
+
* It is committed to the transcript, so what was approved stays on screen.
|
|
18
|
+
*/
|
|
19
|
+
const TIER_TEXT = {
|
|
20
|
+
R0: "R0 · read-only",
|
|
21
|
+
R1: "R1 · runs project code",
|
|
22
|
+
R2: "R2 · changes files"
|
|
23
|
+
};
|
|
24
|
+
const NETWORK_TEXT = {
|
|
25
|
+
"none-expected": "no network expected",
|
|
26
|
+
"project-code-may-use-network": "not restricted",
|
|
27
|
+
"uses-network": "uses the network"
|
|
28
|
+
};
|
|
29
|
+
export const safeText = stripControl;
|
|
30
|
+
const INDENT = MARGIN + " ";
|
|
31
|
+
/** Width available inside the card. */
|
|
32
|
+
const inner = () => Math.max(24, contentWidth() - 4);
|
|
33
|
+
/** ` Label value` with continuation lines aligned under the value. */
|
|
34
|
+
function field(label, value, paint = c.dim) {
|
|
35
|
+
const pad = Math.max(12, label.length + 2);
|
|
36
|
+
const head = label.padEnd(pad);
|
|
37
|
+
return wrapText(safeText(value), inner() - pad).map((l, i) => INDENT + c.dim(i === 0 ? head : " ".repeat(pad)) + paint(l));
|
|
38
|
+
}
|
|
39
|
+
export function renderCommandReview(d, reason, repository, execution = executionContract(), activeRoot, operationId) {
|
|
40
|
+
const tier = d.tier === "R2" ? c.warn(TIER_TEXT[d.tier]) : d.tier === "R1" ? c.value(TIER_TEXT[d.tier]) : c.dim(TIER_TEXT[d.tier]);
|
|
41
|
+
const lines = [...cardHeader("COMMAND REVIEW", c.title)];
|
|
42
|
+
for (const l of wrapText(safeText(displayCommand(d.program, d.args)), inner()))
|
|
43
|
+
lines.push(MARGIN + c.accent(l));
|
|
44
|
+
lines.push("");
|
|
45
|
+
// A command can be aimed at a repository that is not the active one, so
|
|
46
|
+
// WHICH repository is part of what is being approved.
|
|
47
|
+
if (repository)
|
|
48
|
+
lines.push(...field("Repository", repository, c.value));
|
|
49
|
+
const relative = activeRoot ? path.relative(activeRoot, d.cwdAbsolute) : undefined;
|
|
50
|
+
const cwd = relative !== undefined && relative !== ".." && !relative.startsWith(".." + path.sep) && !path.isAbsolute(relative) ? relative || "." : d.cwdAbsolute;
|
|
51
|
+
lines.push(...field("Directory", cwd, c.file));
|
|
52
|
+
const network = execution.backend === "docker-engine-v1" ? "Disabled" : execution.backend === "windows-job" ? "Not restricted by executor" : "Unavailable";
|
|
53
|
+
lines.push(...field("Runtime", execution.backend ? `${execution.backend} · ${execution.backend === "docker-engine-v1" ? "isolated Linux runtime" : "native Windows"}` : "unavailable", c.value));
|
|
54
|
+
lines.push(...field("Network", network, execution.backend === "docker-engine-v1" ? c.ok : c.warn));
|
|
55
|
+
if (execution.backend === "windows-job")
|
|
56
|
+
lines.push(...field("Expected", NETWORK_TEXT[d.network]));
|
|
57
|
+
lines.push(INDENT + c.dim("Risk".padEnd(12)) + tier);
|
|
58
|
+
if (d.script) {
|
|
59
|
+
lines.push(...field("Script", d.script.text, c.value));
|
|
60
|
+
if (d.script.pre)
|
|
61
|
+
lines.push(...field("pre", d.script.pre, c.value));
|
|
62
|
+
if (d.script.post)
|
|
63
|
+
lines.push(...field("post", d.script.post, c.value));
|
|
64
|
+
}
|
|
65
|
+
if (reason)
|
|
66
|
+
lines.push(...field("Reason", reason));
|
|
67
|
+
for (const note of d.notes) {
|
|
68
|
+
if (/^Read-only|^Runs project code/.test(note))
|
|
69
|
+
continue; // already said by the tier
|
|
70
|
+
lines.push(INDENT + c.dim("· " + clip(note, inner() - 2)));
|
|
71
|
+
}
|
|
72
|
+
lines.push(...approvalCard("command", "This command needs its own approval; approving file changes never approves a command.", operationId ? [operationId] : []), "");
|
|
73
|
+
return lines;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The result: a status heading, the command, then counts and timing — the
|
|
77
|
+
* exit code is the truth about success; counts are read from the output only
|
|
78
|
+
* when a runner states them plainly.
|
|
79
|
+
*/
|
|
80
|
+
export function renderCommandSummary(d, r, errorCode, message) {
|
|
81
|
+
const what = d ? displayCommand(d.program, d.args) : "command";
|
|
82
|
+
if (!r) {
|
|
83
|
+
const declined = errorCode === "COMMAND_REJECTED" || errorCode === "APPROVAL_TIMEOUT" || errorCode === "COMMAND_CANCELLED";
|
|
84
|
+
const icon = declined ? c.warn("✗") : c.err("✕");
|
|
85
|
+
return [MARGIN + icon + " " + c.dim(clip(`${what} — ${safeText(message ?? errorCode ?? "not run")}`, inner()))];
|
|
86
|
+
}
|
|
87
|
+
const secs = `${(r.duration_ms / 1000).toFixed(1)}s`;
|
|
88
|
+
const counts = summariseOutput(r.output);
|
|
89
|
+
const extra = [
|
|
90
|
+
counts,
|
|
91
|
+
secs,
|
|
92
|
+
r.truncated ? "output truncated" : "",
|
|
93
|
+
r.redaction_count ? `${r.redaction_count} secret${r.redaction_count === 1 ? "" : "s"} redacted` : ""
|
|
94
|
+
].filter(Boolean);
|
|
95
|
+
// "Running tests…", the command, each test the runner named, the counts one
|
|
96
|
+
// per line, then the status the exit code decides.
|
|
97
|
+
const report = parseTestReport(r.output);
|
|
98
|
+
const isTest = report.tests.length > 0 || !!counts;
|
|
99
|
+
const shown = report.tests.slice(0, 12);
|
|
100
|
+
const out = [
|
|
101
|
+
"",
|
|
102
|
+
MARGIN + c.title(isTest ? "Running tests…" : "Running command…"),
|
|
103
|
+
MARGIN + " " + c.dim("> ") + c.accent(clip(what, inner() - 2)),
|
|
104
|
+
...shown.map((t) => MARGIN + " " + (t.passed ? c.ok("✓ ") : c.err("✗ ")) + (t.passed ? c.dim : c.value)(clip(t.name, inner() - 2))),
|
|
105
|
+
...(report.tests.length > shown.length ? [MARGIN + " " + c.dim(`+${report.tests.length - shown.length} more`)] : []),
|
|
106
|
+
...(counts ? counts.split(" · ").map((n) => MARGIN + " " + (/^0 failed$/.test(n) || /passed/.test(n) ? c.value(n) : c.err(n))) : [])
|
|
107
|
+
];
|
|
108
|
+
const timing = MARGIN + " " + c.dim(extra.filter((e) => e !== counts).join(" · "));
|
|
109
|
+
if (r.timed_out)
|
|
110
|
+
return [...out, MARGIN + c.err("✕ TIMED OUT") + c.dim(" · process tree stopped"), timing];
|
|
111
|
+
if (r.cancelled)
|
|
112
|
+
return [...out, MARGIN + c.warn("⊘ CANCELLED") + c.dim(" · process tree stopped"), timing];
|
|
113
|
+
if (r.exit_code === 0)
|
|
114
|
+
return [...out, MARGIN + c.ok("✓ PASSED"), timing];
|
|
115
|
+
return [...out, MARGIN + c.err("✕ FAILED") + c.dim(` · exit ${r.exit_code}`), timing];
|
|
116
|
+
}
|
|
117
|
+
export function parseTestReport(output) {
|
|
118
|
+
const text = safeText(output).replace(/\r\n/g, "\n");
|
|
119
|
+
const tests = [];
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
const add = (name, passed) => {
|
|
122
|
+
const clean = name.replace(/\s+\([\d.]+\s*m?s\)\s*$/, "").replace(/\s+#\s.*$/, "").trim();
|
|
123
|
+
const key = `${passed}:${clean}`;
|
|
124
|
+
if (!clean || seen.has(key))
|
|
125
|
+
return;
|
|
126
|
+
seen.add(key);
|
|
127
|
+
tests.push({ name: clean, passed });
|
|
128
|
+
};
|
|
129
|
+
// Results end where a runner starts its failure recap; reading past it would
|
|
130
|
+
// list a failing test twice.
|
|
131
|
+
const body = text.split(/\n[✖✕]\s+failing tests:|\nFailures:|\n\s*\d+ failing\b/)[0];
|
|
132
|
+
for (const line of body.split("\n")) {
|
|
133
|
+
let m;
|
|
134
|
+
if ((m = /^\s{0,4}(✔|✓|✖|✕|×)\s+(.+)$/.exec(line)))
|
|
135
|
+
add(m[2], m[1] === "✔" || m[1] === "✓");
|
|
136
|
+
else if ((m = /^(not ok|ok)\s+\d+\s+-\s+(.+)$/.exec(line)))
|
|
137
|
+
add(m[2], m[1] === "ok");
|
|
138
|
+
}
|
|
139
|
+
const value = (re) => {
|
|
140
|
+
const m = re.exec(text);
|
|
141
|
+
return m ? m[1].trim().replace(/,$/, "").slice(0, 120) : undefined;
|
|
142
|
+
};
|
|
143
|
+
const failed = tests.find((t) => !t.passed);
|
|
144
|
+
const expected = value(/^\s*expected:\s*(.+)$/m) ?? value(/^\s*Expected[^:]*:\s*(.+)$/m);
|
|
145
|
+
const received = value(/^\s*actual:\s*(.+)$/m) ?? value(/^\s*Received[^:]*:\s*(.+)$/m);
|
|
146
|
+
return { tests, ...(failed || expected || received ? { failure: { name: failed?.name, expected, received } } : {}) };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Test counts, when a runner states them plainly. Presentation only: the exit
|
|
150
|
+
* code remains the truth about success, and an unrecognised format simply adds
|
|
151
|
+
* nothing to the line.
|
|
152
|
+
*/
|
|
153
|
+
export function summariseOutput(output) {
|
|
154
|
+
const text = safeText(output);
|
|
155
|
+
// node --test — "# pass 97" (tap reporter) or "ℹ pass 97" (spec reporter)
|
|
156
|
+
const nodePass = text.match(/^[#ℹ] pass (\d+)\s*$/m);
|
|
157
|
+
const nodeFail = text.match(/^[#ℹ] fail (\d+)\s*$/m);
|
|
158
|
+
if (nodePass && nodeFail) {
|
|
159
|
+
const skipped = text.match(/^[#ℹ] skipped (\d+)\s*$/m);
|
|
160
|
+
return [
|
|
161
|
+
`${nodePass[1]} passed`,
|
|
162
|
+
`${nodeFail[1]} failed`,
|
|
163
|
+
skipped && skipped[1] !== "0" ? `${skipped[1]} skipped` : ""
|
|
164
|
+
]
|
|
165
|
+
.filter(Boolean)
|
|
166
|
+
.join(" · ");
|
|
167
|
+
}
|
|
168
|
+
// jest / vitest: "Tests: 11 failed, 3612 passed, 3623 total"
|
|
169
|
+
const jest = text.match(/^Tests:\s+(.+?)\s*$/m);
|
|
170
|
+
if (jest) {
|
|
171
|
+
const failed = jest[1].match(/(\d+) failed/);
|
|
172
|
+
const passed = jest[1].match(/(\d+) passed/);
|
|
173
|
+
const skipped = jest[1].match(/(\d+) (?:skipped|todo)/);
|
|
174
|
+
if (passed || failed) {
|
|
175
|
+
return [passed ? `${passed[1]} passed` : "", failed ? `${failed[1]} failed` : "", skipped ? `${skipped[1]} skipped` : ""]
|
|
176
|
+
.filter(Boolean)
|
|
177
|
+
.join(" · ");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// mocha
|
|
181
|
+
const passing = text.match(/^\s*(\d+) passing/m);
|
|
182
|
+
if (passing) {
|
|
183
|
+
const failing = text.match(/^\s*(\d+) failing/m);
|
|
184
|
+
return [`${passing[1]} passed`, failing ? `${failing[1]} failed` : ""].filter(Boolean).join(" · ");
|
|
185
|
+
}
|
|
186
|
+
return "";
|
|
187
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import stringWidth from "string-width";
|
|
1
2
|
/**
|
|
2
3
|
* Composer layout. The composer + its divider lines span the FULL terminal
|
|
3
4
|
* width (Claude-style), inset by a small margin with a one-column right gutter
|
|
@@ -19,9 +20,55 @@ function columns() {
|
|
|
19
20
|
/** Full content width for the composer + dividers: terminal minus the left
|
|
20
21
|
* margin and a one-column right gutter. */
|
|
21
22
|
export function contentWidth() {
|
|
22
|
-
return Math.max(
|
|
23
|
+
return Math.max(8, columns() - MARGIN.length - 1);
|
|
23
24
|
}
|
|
24
25
|
/** Width to wrap running text to — full content width, capped for readability. */
|
|
25
26
|
export function textWidth() {
|
|
26
27
|
return Math.max(20, Math.min(contentWidth(), READABLE_MAX));
|
|
27
28
|
}
|
|
29
|
+
// SGR colour runs plus OSC strings. An OSC payload (a hyperlink URL, a window
|
|
30
|
+
// title) occupies no columns, so a matcher that only knows SGR over-counts any
|
|
31
|
+
// line carrying one.
|
|
32
|
+
/** Visible column count of a styled string — escape sequences don't count. */
|
|
33
|
+
export function visibleWidth(s) {
|
|
34
|
+
return stringWidth(s);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Clamp a styled line to `width` visible columns, keeping its colour codes.
|
|
38
|
+
*
|
|
39
|
+
* The screen engine writes one transcript line per terminal row and does no
|
|
40
|
+
* wrap accounting, so ANY line wider than the terminal steals a second physical
|
|
41
|
+
* row and shifts everything below it — which is how model output containing a
|
|
42
|
+
* 250-character URL ends up overwriting the composer. This is the last line of
|
|
43
|
+
* defence: it runs over everything the markdown renderer emits, so a path that
|
|
44
|
+
* forgets to wrap degrades to a clipped line instead of a corrupted screen.
|
|
45
|
+
*/
|
|
46
|
+
export function clampAnsi(s, width = contentWidth()) {
|
|
47
|
+
if (visibleWidth(s) <= width)
|
|
48
|
+
return s;
|
|
49
|
+
const first = wrapAnsi(s, Math.max(1, width - 1))[0];
|
|
50
|
+
return `${first}…${s.includes("\x1b[") ? "\x1b[0m" : ""}`;
|
|
51
|
+
}
|
|
52
|
+
/** Reflow transcript content without discarding reviewed bytes on resize. */
|
|
53
|
+
export function wrapAnsi(text, width) {
|
|
54
|
+
const limit = Math.max(1, width);
|
|
55
|
+
const tokens = text.split(/(\x1b\[[0-9;]*m)/g).flatMap(part => part.startsWith("\x1b[") ? [part] : [...new Intl.Segmenter().segment(part)].map(s => s.segment));
|
|
56
|
+
const lines = [];
|
|
57
|
+
let row = "", count = 0, style = "";
|
|
58
|
+
for (const token of tokens) {
|
|
59
|
+
if (token.startsWith("\x1b[")) {
|
|
60
|
+
row += token;
|
|
61
|
+
style = token === "\x1b[0m" ? "" : style + token;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (count + visibleWidth(token) > limit && count > 0) {
|
|
65
|
+
lines.push(row + (style ? "\x1b[0m" : ""));
|
|
66
|
+
row = style;
|
|
67
|
+
count = 0;
|
|
68
|
+
}
|
|
69
|
+
row += token;
|
|
70
|
+
count += visibleWidth(token);
|
|
71
|
+
}
|
|
72
|
+
lines.push(row);
|
|
73
|
+
return lines;
|
|
74
|
+
}
|