@carrieros/cli 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -57
- package/dist/commands/attach.js +45 -0
- package/dist/commands/auth.js +60 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +102 -13
- package/dist/commands/context.js +160 -0
- package/dist/commands/doctor.js +53 -8
- package/dist/commands/files.js +84 -23
- package/dist/commands/help.js +3 -1
- package/dist/commands/history.js +88 -23
- package/dist/commands/login.js +44 -41
- package/dist/commands/logout.js +13 -4
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +39 -3
- package/dist/commands/modes.js +4 -1
- package/dist/commands/project.js +106 -0
- package/dist/commands/repo.js +146 -0
- package/dist/commands/repos.js +61 -0
- package/dist/commands/review.js +92 -0
- package/dist/commands/scope.js +152 -0
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +219 -65
- package/dist/commands/settings.js +87 -0
- package/dist/commands/update.js +159 -0
- package/dist/commands/upload.js +204 -31
- package/dist/commands/usage.js +212 -16
- package/dist/commands/whoami.js +2 -1
- package/dist/ide/editor-context.js +172 -0
- package/dist/ide/ide-session.js +94 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +30 -1
- package/dist/services/api.js +171 -13
- package/dist/services/chat-stream.js +145 -0
- package/dist/services/checkpoints.js +116 -0
- package/dist/services/client-tools.js +260 -0
- package/dist/services/command-coordinator.js +200 -0
- package/dist/services/command-policy.js +404 -0
- package/dist/services/config.js +249 -22
- package/dist/services/context.js +307 -6
- package/dist/services/device-auth.js +261 -0
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -0
- package/dist/services/file-detect.js +104 -0
- package/dist/services/file-resolver.js +199 -0
- package/dist/services/file-upload.js +126 -0
- package/dist/services/git-tools.js +248 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +64 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/job-helper.js +307 -0
- package/dist/services/local-files.js +517 -0
- package/dist/services/local-tools.js +432 -0
- package/dist/services/login-flow.js +120 -10
- package/dist/services/meta.js +3 -1
- package/dist/services/mutation-coordinator.js +161 -0
- package/dist/services/mutations.js +493 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +13 -5
- package/dist/services/packaged.js +24 -0
- package/dist/services/process-runner.js +406 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/secure-store.js +197 -0
- package/dist/services/session-resolver.js +108 -0
- package/dist/services/sia.js +51 -0
- package/dist/services/spinner.js +23 -1
- package/dist/services/update.js +286 -0
- package/dist/services/workspace-registry.js +309 -0
- package/dist/services/workspace.js +573 -0
- package/dist/shell/shell-chat.js +1115 -59
- package/dist/shell/shell-commands.js +220 -19
- package/dist/shell/shell-prompt.js +89 -37
- package/dist/shell/shell-renderer.js +19 -38
- package/dist/shell/shell-router.js +19 -3
- package/dist/shell/shell.js +232 -44
- package/dist/types/index.js +3 -1
- package/dist/ui/approval.js +81 -0
- package/dist/ui/banner.js +55 -13
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +87 -0
- package/dist/ui/chat-renderer.js +223 -29
- package/dist/ui/color-picker.js +21 -0
- package/dist/ui/colors.js +9 -1
- package/dist/ui/command-filter.js +40 -5
- package/dist/ui/command-palette.js +122 -62
- package/dist/ui/command-registry.js +85 -11
- package/dist/ui/command-review.js +138 -0
- package/dist/ui/composer-layout.js +41 -0
- package/dist/ui/conversation.js +398 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +18 -1
- package/dist/ui/markdown.js +63 -9
- package/dist/ui/message.js +14 -31
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +289 -0
- package/dist/ui/select.js +193 -29
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/theme.js +17 -0
- package/dist/ui/trust.js +93 -0
- package/dist/ui/ui.js +4 -1
- package/package.json +17 -6
- package/dist/ui/activity.js +0 -77
package/dist/shell/shell.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import readline from "node:readline";
|
|
2
|
+
import { confirm } from "@inquirer/prompts";
|
|
3
3
|
import { DEFAULT_API_URL } from "../services/config.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { withSpinner } from "../services/spinner.js";
|
|
4
|
+
import { deviceLogin, renderLoginFailure } from "../services/login-flow.js";
|
|
5
|
+
import { line } from "../services/output.js";
|
|
7
6
|
import { renderWelcomeBanner } from "../ui/banner.js";
|
|
8
7
|
import { renderExit } from "../ui/chat-renderer.js";
|
|
9
8
|
import { c } from "../ui/colors.js";
|
|
10
9
|
import { readCommand } from "../ui/command-palette.js";
|
|
11
|
-
import {
|
|
10
|
+
import { setCommandScope } from "../ui/command-item.js";
|
|
11
|
+
import { startScreen, stopScreen, screenScrollToBottom } from "../ui/screen.js";
|
|
12
|
+
import { ensureWorkspaceTrust } from "../ui/trust.js";
|
|
13
|
+
import { activeRepository, inWorkspaceMode, listRepositories } from "../services/workspace-registry.js";
|
|
14
|
+
import { cachedUpdateNotice, refreshUpdateCache, shouldRefreshCheck } from "../services/update.js";
|
|
15
|
+
import { chatTypeLabel, loadModels, loadModes } from "./shell-chat.js";
|
|
12
16
|
import { CARET, buildFooter } from "./shell-prompt.js";
|
|
13
|
-
import { dispatchLine } from "./shell-router.js";
|
|
14
|
-
import {
|
|
17
|
+
import { dispatchLine, isMainTurn } from "./shell-router.js";
|
|
18
|
+
import { printWelcome, renderWelcomeBack } from "./shell-renderer.js";
|
|
15
19
|
/**
|
|
16
20
|
* The interactive Carrier OS shell — the default experience when you run
|
|
17
21
|
* `cos` with no command. It sits on top of the existing commands: chat is
|
|
@@ -19,6 +23,12 @@ import { printAuthSuccess, printWelcome } from "./shell-renderer.js";
|
|
|
19
23
|
* through the same Commander program, so no logic is duplicated.
|
|
20
24
|
*/
|
|
21
25
|
export async function runShell(ctx, program) {
|
|
26
|
+
// Safety check before anything touches the working directory — the shell
|
|
27
|
+
// uploads local files you reference by path. Asked once per repository: in a
|
|
28
|
+
// multi-repository workspace the folder holding them is NOT what gets
|
|
29
|
+
// trusted, because trusting it must never imply trusting its children.
|
|
30
|
+
if (!(await ensureWorkspaceTrust(ctx.config, activeRepository().root)))
|
|
31
|
+
return;
|
|
22
32
|
// Returning users see the branded banner once; a fresh login already showed
|
|
23
33
|
// the branding + scope in the welcome / auth-success screens, so we don't
|
|
24
34
|
// repeat it after logging in.
|
|
@@ -29,20 +39,53 @@ export async function runShell(ctx, program) {
|
|
|
29
39
|
return; // user chose /exit or Ctrl+C
|
|
30
40
|
}
|
|
31
41
|
const client = ctx.requireAuth();
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
// Mark that we're inside the interactive shell — commands (e.g. upload) use
|
|
43
|
+
// this to prompt interactively here vs. print finish-and-return output when
|
|
44
|
+
// run standalone (cos upload).
|
|
45
|
+
ctx.setInShell(true);
|
|
46
|
+
// Mode is derived from the chat type (see CommandContext.mode): Carrier Chat
|
|
47
|
+
// always opens in General, Standard opens on its saved mode or Auto. Forcing
|
|
48
|
+
// General here would override that and strand Standard users in General.
|
|
49
|
+
// Preload the mode + model lists so the prompt/banner can show friendly labels
|
|
50
|
+
// (e.g. the "Carrier OS" mode name rather than the raw id).
|
|
51
|
+
await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => [])]);
|
|
52
|
+
// Enter TUI mode: pin the composer to the bottom of the terminal and give the
|
|
53
|
+
// transcript its own scrolling region above it (Claude-style). From here, all
|
|
54
|
+
// output flows into the transcript via the screen engine.
|
|
55
|
+
startScreen();
|
|
56
|
+
// Branded startup banner (rendered once) — ALWAYS the first thing in the
|
|
57
|
+
// transcript, for returning users and fresh logins alike, so the lockup is
|
|
58
|
+
// always one scroll up from the composer (Claude-style). It can't be inherited
|
|
59
|
+
// from the onboarding screens: those were drawn on the real terminal, and
|
|
60
|
+
// startScreen() has since switched to the alternate buffer, which hides them.
|
|
61
|
+
// Update notice comes from the PREVIOUS check — reading the cache is a
|
|
62
|
+
// property lookup, so the banner is never waiting on npm.
|
|
63
|
+
const notice = cachedUpdateNotice(ctx.config);
|
|
64
|
+
renderWelcomeBanner(ctx, notice ? { notices: [notice] } : undefined);
|
|
65
|
+
if (inWorkspaceMode()) {
|
|
66
|
+
line(" " +
|
|
67
|
+
c.dim("Workspace with ") +
|
|
68
|
+
c.value(String(listRepositories().length)) +
|
|
69
|
+
c.dim(" repositories · active: ") +
|
|
70
|
+
c.value(activeRepository().name) +
|
|
71
|
+
c.dim(" · ") +
|
|
72
|
+
c.cmd("/repos") +
|
|
73
|
+
c.dim(" to switch"));
|
|
44
74
|
}
|
|
45
75
|
line();
|
|
76
|
+
// Refresh for NEXT launch, once a day, after the shell is already usable.
|
|
77
|
+
// setImmediate keeps the blocking npm call off the startup path; a failure is
|
|
78
|
+
// recorded and never shown.
|
|
79
|
+
if (shouldRefreshCheck(ctx.config)) {
|
|
80
|
+
setImmediate(() => {
|
|
81
|
+
try {
|
|
82
|
+
refreshUpdateCache(ctx.config);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
/* never let an update check affect the session */
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
46
89
|
// Interactive loop driven by the composer/reader. Each iteration reads one
|
|
47
90
|
// line (with the slash palette overlay, the dim status footer, and a
|
|
48
91
|
// placeholder inside the box), then dispatches it. Enter in the palette only
|
|
@@ -50,9 +93,61 @@ export async function runShell(ctx, program) {
|
|
|
50
93
|
const history = [];
|
|
51
94
|
let sigintArmed = false;
|
|
52
95
|
let conversationStarted = false; // only the first empty session shows the full welcome
|
|
96
|
+
/**
|
|
97
|
+
* The main turn runs in the BACKGROUND so the composer keeps reading.
|
|
98
|
+
*
|
|
99
|
+
* Only one may be in flight — a second `/v1/chat` would be a second
|
|
100
|
+
* conversation turn, which is not what "let me type while it answers" means.
|
|
101
|
+
* Commands stay awaited as before; they are fast and sequential, and awaiting
|
|
102
|
+
* a `/btw` does not block the main turn because that is already detached.
|
|
103
|
+
*/
|
|
104
|
+
let mainTask = null;
|
|
105
|
+
let mainAbort = null;
|
|
106
|
+
const mainRunning = () => mainTask !== null;
|
|
107
|
+
/**
|
|
108
|
+
* One message typed while a turn is still answering.
|
|
109
|
+
*
|
|
110
|
+
* A modern coding agent lets you line up the next thing to say instead of
|
|
111
|
+
* refusing it. Exactly one is held — the next turn is a real conversation
|
|
112
|
+
* turn, and stacking several would queue a pile of them behind an approval
|
|
113
|
+
* nobody is watching. It runs when the current turn finishes, and is dropped
|
|
114
|
+
* if that turn is cancelled (there is nothing to run it after).
|
|
115
|
+
*/
|
|
116
|
+
let queued = null;
|
|
117
|
+
/**
|
|
118
|
+
* Start a main turn detached, and — when it finishes — drain any message the
|
|
119
|
+
* user queued while it ran. Recursive on purpose: the drained turn can itself
|
|
120
|
+
* have a message queued behind it.
|
|
121
|
+
*/
|
|
122
|
+
const startMainTurn = (msg) => {
|
|
123
|
+
mainAbort = new AbortController();
|
|
124
|
+
ctx.mainTurnRunning = true;
|
|
125
|
+
const task = dispatchLine(ctx, program, client, msg, mainAbort.signal)
|
|
126
|
+
.catch(() => undefined)
|
|
127
|
+
.finally(() => {
|
|
128
|
+
if (mainTask === task) {
|
|
129
|
+
mainTask = null;
|
|
130
|
+
mainAbort = null;
|
|
131
|
+
ctx.mainTurnRunning = false;
|
|
132
|
+
if (queued !== null) {
|
|
133
|
+
const next = queued;
|
|
134
|
+
queued = null;
|
|
135
|
+
line(" " + c.dim("↳ Running the message you queued."));
|
|
136
|
+
startMainTurn(next);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
mainTask = task;
|
|
141
|
+
};
|
|
142
|
+
/** Cancel the running turn, if any. In its own closure so the type of
|
|
143
|
+
* mainAbort is not narrowed away at the call sites. */
|
|
144
|
+
const cancelMainTurn = () => {
|
|
145
|
+
mainAbort?.abort();
|
|
146
|
+
};
|
|
53
147
|
// Leaving the shell: restore cooked mode + a visible cursor (the reader keeps
|
|
54
148
|
// raw mode on for the session), then print the farewell.
|
|
55
149
|
const leave = () => {
|
|
150
|
+
stopScreen(); // drop the pinned composer + scroll region before the farewell
|
|
56
151
|
if (process.stdin.isTTY)
|
|
57
152
|
process.stdin.setRawMode(false);
|
|
58
153
|
process.stdout.write("\x1b[?25h");
|
|
@@ -63,12 +158,53 @@ export async function runShell(ctx, program) {
|
|
|
63
158
|
// One Ctrl+C swaps the status footer for a dim "again to exit" hint beneath
|
|
64
159
|
// the bar (no separate info line); a second Ctrl+C quits.
|
|
65
160
|
const footer = sigintArmed ? " " + c.dim("Press Ctrl-C again to exit") : buildFooter(ctx);
|
|
161
|
+
// Keep the palette in step with the chat type — /switch mid-session must
|
|
162
|
+
// add or remove the commands that only apply to one experience (e.g. /fast
|
|
163
|
+
// is Standard-only), the same way the web shows or hides its toggles.
|
|
164
|
+
setCommandScope(ctx.chatType);
|
|
66
165
|
const res = await readCommand(CARET, history, footer, placeholder);
|
|
67
166
|
if (res.type === "exit") {
|
|
68
167
|
leave();
|
|
69
168
|
return;
|
|
70
169
|
}
|
|
170
|
+
// ←/→ switch chat type. No confirmation: the outgoing conversation is NOT
|
|
171
|
+
// deleted — setChatType only drops the local pointer to it, and the thread
|
|
172
|
+
// stays on the server. So the note says how to get back rather than asking
|
|
173
|
+
// permission to leave.
|
|
174
|
+
if (res.type === "switch") {
|
|
175
|
+
const target = res.dir === "left" ? "carrier" : "standard";
|
|
176
|
+
if (ctx.chatType === target)
|
|
177
|
+
continue; // already there — nothing to say
|
|
178
|
+
// Refused mid-turn: the in-flight reply belongs to the OUTGOING
|
|
179
|
+
// conversation, and clearing the pointer now would file its session id
|
|
180
|
+
// against the chat type you just left.
|
|
181
|
+
if (mainRunning()) {
|
|
182
|
+
line();
|
|
183
|
+
line(" " + c.warn("!") + " " + c.dim("Finish the current response before switching."));
|
|
184
|
+
line();
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const leaving = describeCurrentSession(ctx);
|
|
188
|
+
ctx.setChatType(target);
|
|
189
|
+
conversationStarted = false; // a fresh conversation starts on the next message
|
|
190
|
+
line();
|
|
191
|
+
line(" " + c.dim("Switched to ") + c.value(chatTypeLabel(target)) + c.dim("."));
|
|
192
|
+
if (leaving)
|
|
193
|
+
line(" " + c.dim(leaving));
|
|
194
|
+
line();
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
71
197
|
if (res.type === "sigint") {
|
|
198
|
+
// Ctrl+C with a turn in flight cancels the TURN, not the CLI — the same
|
|
199
|
+
// meaning it had when the turn owned stdin. Only an idle Ctrl+C arms the
|
|
200
|
+
// exit, so a mistaken keystroke mid-answer can never drop the shell.
|
|
201
|
+
if (mainRunning()) {
|
|
202
|
+
// Cancelling the running turn also drops whatever was queued behind it —
|
|
203
|
+
// there is nothing for it to run after now.
|
|
204
|
+
queued = null;
|
|
205
|
+
cancelMainTurn();
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
72
208
|
if (sigintArmed) {
|
|
73
209
|
leave();
|
|
74
210
|
return;
|
|
@@ -79,8 +215,10 @@ export async function runShell(ctx, program) {
|
|
|
79
215
|
sigintArmed = false;
|
|
80
216
|
let message = res.value.trim();
|
|
81
217
|
if (!message)
|
|
82
|
-
continue;
|
|
218
|
+
continue; // never auto-act on an empty prompt
|
|
83
219
|
history.push(message);
|
|
220
|
+
// Submitting always re-follows the newest output (in case they'd scrolled up).
|
|
221
|
+
screenScrollToBottom();
|
|
84
222
|
// /new is a friendly alias for /clear. A cleared/new session drops back to
|
|
85
223
|
// the welcome placeholder; sending a real message starts the conversation
|
|
86
224
|
// and switches to the compact placeholder.
|
|
@@ -90,50 +228,100 @@ export async function runShell(ctx, program) {
|
|
|
90
228
|
conversationStarted = false;
|
|
91
229
|
else if (!message.startsWith("/"))
|
|
92
230
|
conversationStarted = true;
|
|
231
|
+
// A main turn while one is already running is QUEUED, not refused — one at a
|
|
232
|
+
// time, so the pending one is next when the current turn finishes. A quick
|
|
233
|
+
// side question (/btw) is still the way to ask without waiting.
|
|
234
|
+
if (isMainTurn(message) && mainRunning()) {
|
|
235
|
+
if (queued !== null) {
|
|
236
|
+
line();
|
|
237
|
+
line(" " + c.warn("!") + " " + c.dim("A message is already queued — it runs next. Send this once it starts."));
|
|
238
|
+
line();
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
queued = message;
|
|
242
|
+
line(" " + c.dim("⏎ Queued — runs after the current response. Ctrl+C cancels both."));
|
|
243
|
+
}
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
// Main turns are detached so the composer keeps reading; the drain of a
|
|
247
|
+
// queued message is handled in startMainTurn's finally.
|
|
248
|
+
if (isMainTurn(message)) {
|
|
249
|
+
startMainTurn(message);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
93
252
|
const { exit } = await dispatchLine(ctx, program, client, message);
|
|
94
253
|
if (exit) {
|
|
254
|
+
// Let an in-flight turn go rather than leaving it writing into a
|
|
255
|
+
// torn-down screen.
|
|
256
|
+
cancelMainTurn();
|
|
95
257
|
leave();
|
|
96
258
|
return;
|
|
97
259
|
}
|
|
98
260
|
}
|
|
99
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* "Your Carrier conversation "…" is saved — /session 3 to return.", or null when
|
|
264
|
+
* there is nothing to go back to.
|
|
265
|
+
*
|
|
266
|
+
* The ordinal comes from the list `/sessions` last printed, which is what the
|
|
267
|
+
* user would actually type; without it the message names the conversation but
|
|
268
|
+
* points at /sessions instead of inventing a number.
|
|
269
|
+
*/
|
|
270
|
+
function describeCurrentSession(ctx) {
|
|
271
|
+
const id = ctx.config.get("sessionId");
|
|
272
|
+
if (!id)
|
|
273
|
+
return null;
|
|
274
|
+
const title = ctx.config.get("sessionTitle");
|
|
275
|
+
const named = title ? `"${title}"` : "conversation";
|
|
276
|
+
const ordinal = (ctx.config.get("sessionOrdinals") ?? []).indexOf(id) + 1;
|
|
277
|
+
const back = ordinal > 0 ? `/session ${ordinal} to return` : "/sessions to return";
|
|
278
|
+
return `Your ${chatTypeLabel(ctx.chatType)} ${named} is saved — ${back}.`;
|
|
279
|
+
}
|
|
100
280
|
/** First empty session — the welcome placeholder doubles as the input area. */
|
|
101
281
|
const WELCOME_PLACEHOLDER = "What can I help you build today?";
|
|
102
282
|
/** Once the conversation is underway — a compact, unobtrusive prompt. */
|
|
103
283
|
const COMPACT_PLACEHOLDER = "Ask Carrier OS…";
|
|
104
|
-
/**
|
|
284
|
+
/** Browser-based first-run sign-in (device authorization). Loops so a denied or
|
|
285
|
+
* expired attempt can be retried; returns false if the user declines or Ctrl+C. */
|
|
105
286
|
async function firstRunLogin(ctx) {
|
|
106
287
|
printWelcome();
|
|
107
288
|
const apiUrl = ctx.config.get("apiUrl") ?? DEFAULT_API_URL;
|
|
108
289
|
for (;;) {
|
|
109
|
-
let key;
|
|
110
290
|
try {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
continue;
|
|
120
|
-
try {
|
|
121
|
-
const scope = await withSpinner("Verifying key…", () => verifyAndSaveKey(ctx, apiUrl, key));
|
|
122
|
-
printAuthSuccess(scope);
|
|
291
|
+
const scope = await deviceLogin(ctx, apiUrl);
|
|
292
|
+
const developer = ctx.config.get("auth")?.account?.name || scope.user?.email || "Developer";
|
|
293
|
+
// Claude-style two-step landing: confirm success, then a welcome screen,
|
|
294
|
+
// then into the shell — each gated by Enter.
|
|
295
|
+
line();
|
|
296
|
+
await pressEnter("Login successful. Press Enter to continue…");
|
|
297
|
+
renderWelcomeBack(scope, developer);
|
|
298
|
+
await pressEnter("Press Enter to start Carrier Chat…");
|
|
123
299
|
return true;
|
|
124
300
|
}
|
|
125
301
|
catch (err) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
302
|
+
renderLoginFailure(err, apiUrl);
|
|
303
|
+
line();
|
|
304
|
+
let again;
|
|
305
|
+
try {
|
|
306
|
+
again = await confirm({ message: "Try again?", default: true });
|
|
132
307
|
}
|
|
133
|
-
|
|
134
|
-
|
|
308
|
+
catch {
|
|
309
|
+
return false; // Ctrl+C at the prompt
|
|
135
310
|
}
|
|
136
|
-
|
|
311
|
+
if (!again)
|
|
312
|
+
return false;
|
|
137
313
|
}
|
|
138
314
|
}
|
|
139
315
|
}
|
|
316
|
+
/** Print a dim prompt and resolve when the user presses Enter. Used for the
|
|
317
|
+
* Claude-style "Press Enter to continue…" gates before the shell starts (raw
|
|
318
|
+
* TUI mode is not active yet, so a line-mode readline is correct here). */
|
|
319
|
+
function pressEnter(prompt) {
|
|
320
|
+
return new Promise((resolve) => {
|
|
321
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
322
|
+
rl.question(" " + c.dim(prompt) + " ", () => {
|
|
323
|
+
rl.close();
|
|
324
|
+
resolve();
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
}
|
package/dist/types/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Public /v1 API contract — mirrors the shapes returned by api.carrieros.ai's
|
|
2
2
|
// `src/routes/v1/*`. The CLI is a pure consumer: it never reimplements any of
|
|
3
3
|
// this logic, it only types the JSON it receives.
|
|
4
|
-
export {
|
|
4
|
+
export function isMemoryMarker(m) {
|
|
5
|
+
return m.role === "marker";
|
|
6
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { c } from "./colors.js";
|
|
2
|
+
import { MARGIN, contentWidth, visibleWidth } from "./composer-layout.js";
|
|
3
|
+
import { captureKeys } from "./screen-prompt.js";
|
|
4
|
+
import { screenScrollPage, screenScrollToBottom, screenTransient } from "./screen.js";
|
|
5
|
+
/** Remaining time as m:ss, for the auto-reject hint. */
|
|
6
|
+
function countdown(msLeft) {
|
|
7
|
+
const left = Math.max(0, Math.ceil(msLeft / 1000));
|
|
8
|
+
return `${Math.floor(left / 60)}:${String(left % 60).padStart(2, "0")}`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The exact lines the prompt shows. Pure, so the layout can be tested.
|
|
12
|
+
*
|
|
13
|
+
* One line to answer, one dim line saying what the keys do and when it gives
|
|
14
|
+
* up. `(y/N)` is the convention for "anything but y means no", which is exactly
|
|
15
|
+
* the policy underneath.
|
|
16
|
+
*/
|
|
17
|
+
export function approvalFrame(question, msLeft) {
|
|
18
|
+
const hint = c.dim("Enter or ") +
|
|
19
|
+
c.key("n") +
|
|
20
|
+
c.dim(" declines · ") +
|
|
21
|
+
c.key("Ctrl+C") +
|
|
22
|
+
c.dim(" stops the turn · declines on its own in ") +
|
|
23
|
+
c.dim(countdown(msLeft));
|
|
24
|
+
const short = c.dim("Enter/") + c.key("n") + c.dim(" declines · ") + c.key("Ctrl+C") + c.dim(" stops · ") + c.dim(countdown(msLeft));
|
|
25
|
+
const room = contentWidth() - 6;
|
|
26
|
+
return [
|
|
27
|
+
MARGIN + " " + c.warn("?") + " " + c.title(question) + " " + c.dim("(y/N)"),
|
|
28
|
+
MARGIN + " " + (visibleWidth(hint) <= room ? hint : short)
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
export function askApproval(opts) {
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
const deadline = Date.now() + opts.timeoutMs;
|
|
34
|
+
let done = false;
|
|
35
|
+
const paint = () => screenTransient(approvalFrame(opts.question, deadline - Date.now()));
|
|
36
|
+
const finish = (value) => {
|
|
37
|
+
if (done)
|
|
38
|
+
return;
|
|
39
|
+
done = true;
|
|
40
|
+
clearInterval(timer);
|
|
41
|
+
opts.signal?.removeEventListener?.("abort", onAbort);
|
|
42
|
+
release();
|
|
43
|
+
screenTransient([]);
|
|
44
|
+
resolve(value);
|
|
45
|
+
};
|
|
46
|
+
function onAbort() {
|
|
47
|
+
finish("cancel");
|
|
48
|
+
}
|
|
49
|
+
const onKey = (str, key) => {
|
|
50
|
+
if (!key && !str)
|
|
51
|
+
return;
|
|
52
|
+
if (key?.ctrl && (key.name === "c" || key.name === "d"))
|
|
53
|
+
return finish("cancel");
|
|
54
|
+
if (key?.name === "pageup")
|
|
55
|
+
return screenScrollPage(-1);
|
|
56
|
+
if (key?.name === "pagedown")
|
|
57
|
+
return screenScrollPage(1);
|
|
58
|
+
if (key?.name === "end")
|
|
59
|
+
return screenScrollToBottom();
|
|
60
|
+
if (str === "y" || str === "Y")
|
|
61
|
+
return finish("approve");
|
|
62
|
+
if (str === "n" || str === "N" || key?.name === "escape")
|
|
63
|
+
return finish("reject");
|
|
64
|
+
if (key?.name === "return" || key?.name === "enter")
|
|
65
|
+
return finish("reject");
|
|
66
|
+
};
|
|
67
|
+
const release = captureKeys(onKey);
|
|
68
|
+
const timer = setInterval(() => {
|
|
69
|
+
if (Date.now() >= deadline)
|
|
70
|
+
finish("timeout");
|
|
71
|
+
else
|
|
72
|
+
paint();
|
|
73
|
+
}, 1000);
|
|
74
|
+
timer.unref?.();
|
|
75
|
+
if (opts.signal?.aborted)
|
|
76
|
+
return finish("cancel");
|
|
77
|
+
opts.signal?.addEventListener?.("abort", onAbort, { once: true });
|
|
78
|
+
screenScrollToBottom();
|
|
79
|
+
paint();
|
|
80
|
+
});
|
|
81
|
+
}
|
package/dist/ui/banner.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { line } from "../services/output.js";
|
|
3
|
+
import { branchLabel, fitPath, getWorkspace, statusLabel } from "../services/workspace.js";
|
|
4
|
+
import { modeLabelShort, modelLabelShort } from "../shell/shell-chat.js";
|
|
4
5
|
import { c } from "./colors.js";
|
|
5
6
|
import { WORDMARK } from "./logo.js";
|
|
6
|
-
import {
|
|
7
|
+
import { BRAND_HEX } from "./theme.js";
|
|
7
8
|
const MARGIN = " ";
|
|
8
9
|
const LABEL_WIDTH = 13;
|
|
9
10
|
/** Visible width of a block of lines. */
|
|
@@ -25,10 +26,11 @@ function lerpHex(a, b, t) {
|
|
|
25
26
|
const mix = (x, y) => Math.round(x + (y - x) * t);
|
|
26
27
|
return "#" + [mix(ar, br), mix(ag, bg), mix(ab, bb)].map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
27
28
|
}
|
|
28
|
-
/** Color the wordmark with a gentle left→right gradient from the
|
|
29
|
-
* lighter tint of it (spaces left untouched).
|
|
29
|
+
/** Color the wordmark with a gentle left→right gradient from the fixed brand
|
|
30
|
+
* green to a lighter tint of it (spaces left untouched). The wordmark is
|
|
31
|
+
* branding, so it stays green and does NOT follow the runtime /color accent. */
|
|
30
32
|
function gradientWordmark(lines) {
|
|
31
|
-
const from =
|
|
33
|
+
const from = BRAND_HEX;
|
|
32
34
|
const to = lerpHex(from, "#ffffff", 0.5); // lighten toward white on the right
|
|
33
35
|
const maxW = Math.max(1, ...lines.map((l) => [...l].length));
|
|
34
36
|
return lines.map((line) => [...line].map((ch, i) => (ch === " " ? ch : chalk.hex(lerpHex(from, to, i / maxW))(ch))).join(""));
|
|
@@ -40,20 +42,55 @@ function gradientWordmark(lines) {
|
|
|
40
42
|
*/
|
|
41
43
|
export function renderBrandmark() {
|
|
42
44
|
if (isNarrow()) {
|
|
43
|
-
return [MARGIN + c.
|
|
45
|
+
return [MARGIN + c.brandFixed("Carrier OS") + " " + c.subtitle("CLI")];
|
|
44
46
|
}
|
|
45
47
|
return gradientWordmark(WORDMARK.split("\n")).map((l) => MARGIN + l);
|
|
46
48
|
}
|
|
47
49
|
function kvLine(label, value) {
|
|
48
50
|
return MARGIN + c.label(label.padEnd(LABEL_WIDTH)) + c.value(value);
|
|
49
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Where you are, in three lines: the project, its Git state, and the path.
|
|
54
|
+
*
|
|
55
|
+
* This is the first thing the CLI has ever known about the local machine, and
|
|
56
|
+
* the banner is where it belongs — it answers "what am I pointed at?" before
|
|
57
|
+
* the first prompt, rather than making someone run a command to find out.
|
|
58
|
+
*
|
|
59
|
+
* Failure is silent by design. A machine without Git, or a folder Git refuses
|
|
60
|
+
* to read, still gets a Workspace and a Path; only the Git line changes. The
|
|
61
|
+
* caller already wraps this, but the shell must open regardless.
|
|
62
|
+
*/
|
|
63
|
+
function workspaceLines() {
|
|
64
|
+
const ws = getWorkspace();
|
|
65
|
+
const repo = ws.repository;
|
|
66
|
+
const out = [kvLine("Workspace", ws.project.name)];
|
|
67
|
+
if (repo.state === "detected") {
|
|
68
|
+
const branch = branchLabel(repo) ?? "unknown";
|
|
69
|
+
const status = statusLabel(repo);
|
|
70
|
+
// "Clean" adds nothing at a glance — the absence of a count already says
|
|
71
|
+
// it. Only a dirty tree, or an unknown one, is worth the extra words.
|
|
72
|
+
const suffix = status && status !== "Clean" ? ` ${c.dim("·")} ${status}` : "";
|
|
73
|
+
out.push(kvLine("Git", branch) + suffix);
|
|
74
|
+
}
|
|
75
|
+
else if (repo.state === "unavailable") {
|
|
76
|
+
out.push(kvLine("Git", "Unavailable"));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
out.push(kvLine("Git", "Not detected"));
|
|
80
|
+
}
|
|
81
|
+
// Budget: margin + label column + a little slack, so a deep path shortens
|
|
82
|
+
// instead of wrapping the banner onto a second line.
|
|
83
|
+
const width = Math.max(24, (process.stdout.columns ?? 80) - MARGIN.length - LABEL_WIDTH - 2);
|
|
84
|
+
out.push(kvLine("Path", fitPath(ws.cwd, width)));
|
|
85
|
+
out.push("");
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
50
88
|
export function renderWelcomeBanner(ctx, opts = {}) {
|
|
51
89
|
try {
|
|
52
|
-
const scope = ctx.config.get("scope");
|
|
53
90
|
const out = ["", ...renderBrandmark(), ""];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
out.push(kvLine("Mode",
|
|
91
|
+
for (const l of workspaceLines())
|
|
92
|
+
out.push(l);
|
|
93
|
+
out.push(kvLine("Mode", modeLabelShort(ctx)));
|
|
57
94
|
out.push(kvLine("Model", modelLabelShort(ctx)));
|
|
58
95
|
out.push("");
|
|
59
96
|
for (const n of opts.notices ?? [])
|
|
@@ -61,10 +98,15 @@ export function renderWelcomeBanner(ctx, opts = {}) {
|
|
|
61
98
|
if (opts.notices?.length)
|
|
62
99
|
out.push("");
|
|
63
100
|
out.push(MARGIN + c.hint("Type ") + c.key("/help") + c.hint(" for available commands."));
|
|
64
|
-
|
|
101
|
+
// Emit through `line()` so, in the interactive shell, the banner lands in the
|
|
102
|
+
// transcript region above the pinned composer (not written over it).
|
|
103
|
+
for (const l of out)
|
|
104
|
+
line(l);
|
|
65
105
|
}
|
|
66
106
|
catch {
|
|
67
107
|
// The banner must never break startup — degrade to a bare header.
|
|
68
|
-
|
|
108
|
+
line();
|
|
109
|
+
line(` ${c.wordmark("Carrier OS")} ${c.subtitle("CLI")}`);
|
|
110
|
+
line();
|
|
69
111
|
}
|
|
70
112
|
}
|