@carrieros/cli-staging 0.0.0-stage → 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 +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 +25 -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 +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 +155 -0
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +282 -0
- package/dist/commands/settings.js +100 -0
- package/dist/commands/update.js +229 -0
- package/dist/commands/upload.js +223 -0
- package/dist/commands/usage.js +227 -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 +360 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +126 -0
- package/dist/services/api.js +439 -0
- 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 +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 +383 -0
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +371 -0
- package/dist/services/device-auth.js +286 -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 +15 -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 +113 -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 +311 -0
- package/dist/services/workspace-registry.js +310 -0
- package/dist/services/workspace.js +580 -0
- package/dist/shell/shell-chat.js +1619 -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 +389 -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,389 @@
|
|
|
1
|
+
import readline from "node:readline";
|
|
2
|
+
import { confirm } from "@inquirer/prompts";
|
|
3
|
+
import { DEFAULT_API_URL } from "../services/config.js";
|
|
4
|
+
import { isPackaged } from "../services/packaged.js";
|
|
5
|
+
import { refreshPackagedUpdateCache } from "../services/packaged-update.js";
|
|
6
|
+
import { deviceLogin, renderLoginFailure } from "../services/login-flow.js";
|
|
7
|
+
import { line } from "../services/output.js";
|
|
8
|
+
import { showTaskContext } from "./task-context-view.js";
|
|
9
|
+
import { renderWelcomeBanner } from "../ui/banner.js";
|
|
10
|
+
import { renderExit } from "../ui/chat-renderer.js";
|
|
11
|
+
import { c } from "../ui/colors.js";
|
|
12
|
+
import { readCommand } from "../ui/command-palette.js";
|
|
13
|
+
import { setCommandScope } from "../ui/command-item.js";
|
|
14
|
+
import { startScreen, stopScreen, screenScrollToBottom } from "../ui/screen.js";
|
|
15
|
+
import { ensureWorkspaceTrust } from "../ui/trust.js";
|
|
16
|
+
import { activeRepository, inWorkspaceMode, listRepositories } from "../services/workspace-registry.js";
|
|
17
|
+
import { cachedUpdateNotice, refreshUpdateCache, shouldRefreshCheck } from "../services/update.js";
|
|
18
|
+
import { chatTypeLabel, loadModels, loadModes, showCarrierMaintenance, syncChatAvailability, loadFastModel } from "./shell-chat.js";
|
|
19
|
+
import { CARET, buildFooter } from "./shell-prompt.js";
|
|
20
|
+
import { dispatchLine, isMainTurn } from "./shell-router.js";
|
|
21
|
+
import { printWelcome, renderWelcomeBack } from "./shell-renderer.js";
|
|
22
|
+
/**
|
|
23
|
+
* The interactive Carrier OS shell — the default experience when you run
|
|
24
|
+
* `cos` with no command. It sits on top of the existing commands: chat is
|
|
25
|
+
* handled by the shared chat turn, and every other slash command is routed
|
|
26
|
+
* through the same Commander program, so no logic is duplicated.
|
|
27
|
+
*/
|
|
28
|
+
export async function runShell(ctx, program) {
|
|
29
|
+
// Safety check before anything touches the working directory — the shell
|
|
30
|
+
// uploads local files you reference by path. Asked once per repository: in a
|
|
31
|
+
// multi-repository workspace the folder holding them is NOT what gets
|
|
32
|
+
// trusted, because trusting it must never imply trusting its children.
|
|
33
|
+
if (!(await ensureWorkspaceTrust(ctx.config, activeRepository().root)))
|
|
34
|
+
return;
|
|
35
|
+
// Returning users see the branded banner once; a fresh login already showed
|
|
36
|
+
// the branding + scope in the welcome / auth-success screens, so we don't
|
|
37
|
+
// repeat it after logging in.
|
|
38
|
+
const returning = ctx.config.isAuthenticated;
|
|
39
|
+
if (!returning) {
|
|
40
|
+
const ok = await firstRunLogin(ctx);
|
|
41
|
+
if (!ok)
|
|
42
|
+
return; // user chose /exit or Ctrl+C
|
|
43
|
+
}
|
|
44
|
+
const client = ctx.requireAuth();
|
|
45
|
+
await client.recoverToolResults();
|
|
46
|
+
await client.reportCodingTaskRecovery();
|
|
47
|
+
// Mark that we're inside the interactive shell — commands (e.g. upload) use
|
|
48
|
+
// this to prompt interactively here vs. print finish-and-return output when
|
|
49
|
+
// run standalone (cos upload).
|
|
50
|
+
ctx.setInShell(true);
|
|
51
|
+
// Mode is derived from the chat type (see CommandContext.mode): Carrier Chat
|
|
52
|
+
// always opens in General, Standard opens on its saved mode or Auto. Forcing
|
|
53
|
+
// General here would override that and strand Standard users in General.
|
|
54
|
+
// Preload the mode + model lists so the prompt/banner can show friendly labels
|
|
55
|
+
// (e.g. the "Carrier OS" mode name rather than the raw id).
|
|
56
|
+
await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => []), loadFastModel(client)]);
|
|
57
|
+
// Enter TUI mode: pin the composer to the bottom of the terminal and give the
|
|
58
|
+
// transcript its own scrolling region above it (Claude-style). From here, all
|
|
59
|
+
// output flows into the transcript via the screen engine.
|
|
60
|
+
startScreen();
|
|
61
|
+
// Branded startup banner (rendered once) — ALWAYS the first thing in the
|
|
62
|
+
// transcript, for returning users and fresh logins alike, so the lockup is
|
|
63
|
+
// always one scroll up from the composer (Claude-style). It can't be inherited
|
|
64
|
+
// from the onboarding screens: those were drawn on the real terminal, and
|
|
65
|
+
// startScreen() has since switched to the alternate buffer, which hides them.
|
|
66
|
+
// Update notice comes from the PREVIOUS check — reading the cache is a
|
|
67
|
+
// property lookup, so the banner is never waiting on npm.
|
|
68
|
+
const notice = cachedUpdateNotice(ctx.config);
|
|
69
|
+
renderWelcomeBanner(ctx, notice ? { notices: [notice] } : undefined);
|
|
70
|
+
if (inWorkspaceMode()) {
|
|
71
|
+
line(" " +
|
|
72
|
+
c.dim("Workspace with ") +
|
|
73
|
+
c.value(String(listRepositories().length)) +
|
|
74
|
+
c.dim(" repositories · active: ") +
|
|
75
|
+
c.value(activeRepository().name) +
|
|
76
|
+
c.dim(" · ") +
|
|
77
|
+
c.cmd("/repos") +
|
|
78
|
+
c.dim(" to switch"));
|
|
79
|
+
}
|
|
80
|
+
line();
|
|
81
|
+
try {
|
|
82
|
+
const availability = await syncChatAvailability(ctx, client);
|
|
83
|
+
if (ctx.chatType === "carrier" && availability.carrier_chat_maintenance)
|
|
84
|
+
showCarrierMaintenance();
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
ctx.carrierMaintenance = null;
|
|
88
|
+
line(" " + c.warn("⚠") + " " + c.dim("Carrier Chat status is unavailable. Sending will wait until it can be checked."));
|
|
89
|
+
}
|
|
90
|
+
// Keep the locked composer in sync while the shell sits open. The server
|
|
91
|
+
// remains the authority at send time; this poll only updates presentation.
|
|
92
|
+
let pollingAvailability = false;
|
|
93
|
+
const availabilityTimer = setInterval(() => {
|
|
94
|
+
if (pollingAvailability)
|
|
95
|
+
return;
|
|
96
|
+
pollingAvailability = true;
|
|
97
|
+
const previous = ctx.carrierMaintenance;
|
|
98
|
+
void syncChatAvailability(ctx, client).then((state) => {
|
|
99
|
+
if (ctx.chatType !== "carrier" || previous === state.carrier_chat_maintenance)
|
|
100
|
+
return;
|
|
101
|
+
if (state.carrier_chat_maintenance)
|
|
102
|
+
showCarrierMaintenance();
|
|
103
|
+
else
|
|
104
|
+
line(" " + c.warn("⚠") + " " + c.dim("Carrier Chat is available again."));
|
|
105
|
+
}).catch(() => {
|
|
106
|
+
ctx.carrierMaintenance = null;
|
|
107
|
+
}).finally(() => { pollingAvailability = false; });
|
|
108
|
+
}, 10_000);
|
|
109
|
+
availabilityTimer.unref();
|
|
110
|
+
// Restarted into a remembered conversation with earlier coding work: show
|
|
111
|
+
// what was being done, as context only. No approval, mutation or command is
|
|
112
|
+
// restored — anything still needed is proposed and approved again.
|
|
113
|
+
await showTaskContext(client, ctx.config.get("sessionId"));
|
|
114
|
+
// Refresh for NEXT launch, once a day, after the shell is already usable.
|
|
115
|
+
// setImmediate keeps the blocking npm call off the startup path; a failure is
|
|
116
|
+
// recorded and never shown.
|
|
117
|
+
if (shouldRefreshCheck(ctx.config)) {
|
|
118
|
+
setImmediate(() => {
|
|
119
|
+
try {
|
|
120
|
+
// The installed .exe has no npm: it reads the release manifest instead,
|
|
121
|
+
// asynchronously, so it never blocks the composer.
|
|
122
|
+
if (isPackaged())
|
|
123
|
+
void refreshPackagedUpdateCache(ctx.config).catch(() => undefined);
|
|
124
|
+
else
|
|
125
|
+
refreshUpdateCache(ctx.config);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
/* never let an update check affect the session */
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
// Interactive loop driven by the composer/reader. Each iteration reads one
|
|
133
|
+
// line (with the slash palette overlay, the dim status footer, and a
|
|
134
|
+
// placeholder inside the box), then dispatches it. Enter in the palette only
|
|
135
|
+
// inserts a command — a second Enter submits it — exactly like Claude Code.
|
|
136
|
+
const history = [];
|
|
137
|
+
let sigintArmed = false;
|
|
138
|
+
let conversationStarted = false; // only the first empty session shows the full welcome
|
|
139
|
+
/**
|
|
140
|
+
* The main turn runs in the BACKGROUND so the composer keeps reading.
|
|
141
|
+
*
|
|
142
|
+
* Only one may be in flight — a second `/v1/chat` would be a second
|
|
143
|
+
* conversation turn, which is not what "let me type while it answers" means.
|
|
144
|
+
* Commands stay awaited as before; they are fast and sequential, and awaiting
|
|
145
|
+
* a `/btw` does not block the main turn because that is already detached.
|
|
146
|
+
*/
|
|
147
|
+
let mainTask = null;
|
|
148
|
+
let mainAbort = null;
|
|
149
|
+
const mainRunning = () => mainTask !== null;
|
|
150
|
+
/**
|
|
151
|
+
* One message typed while a turn is still answering.
|
|
152
|
+
*
|
|
153
|
+
* A modern coding agent lets you line up the next thing to say instead of
|
|
154
|
+
* refusing it. Exactly one is held — the next turn is a real conversation
|
|
155
|
+
* turn, and stacking several would queue a pile of them behind an approval
|
|
156
|
+
* nobody is watching. It runs when the current turn finishes, and is dropped
|
|
157
|
+
* if that turn is cancelled (there is nothing to run it after).
|
|
158
|
+
*/
|
|
159
|
+
let queued = null;
|
|
160
|
+
/**
|
|
161
|
+
* Start a main turn detached, and — when it finishes — drain any message the
|
|
162
|
+
* user queued while it ran. Recursive on purpose: the drained turn can itself
|
|
163
|
+
* have a message queued behind it.
|
|
164
|
+
*/
|
|
165
|
+
const startMainTurn = (msg) => {
|
|
166
|
+
mainAbort = new AbortController();
|
|
167
|
+
ctx.mainTurnRunning = true;
|
|
168
|
+
const task = dispatchLine(ctx, program, client, msg, mainAbort.signal)
|
|
169
|
+
.catch(() => undefined)
|
|
170
|
+
.finally(() => {
|
|
171
|
+
if (mainTask === task) {
|
|
172
|
+
mainTask = null;
|
|
173
|
+
mainAbort = null;
|
|
174
|
+
ctx.mainTurnRunning = false;
|
|
175
|
+
if (queued !== null) {
|
|
176
|
+
const next = queued;
|
|
177
|
+
queued = null;
|
|
178
|
+
line(" " + c.dim("↳ Running the message you queued."));
|
|
179
|
+
startMainTurn(next);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
mainTask = task;
|
|
184
|
+
};
|
|
185
|
+
/** Cancel the running turn, if any. In its own closure so the type of
|
|
186
|
+
* mainAbort is not narrowed away at the call sites. */
|
|
187
|
+
const cancelMainTurn = () => {
|
|
188
|
+
mainAbort?.abort();
|
|
189
|
+
};
|
|
190
|
+
// Leaving the shell: restore cooked mode + a visible cursor (the reader keeps
|
|
191
|
+
// raw mode on for the session), then print the farewell.
|
|
192
|
+
//
|
|
193
|
+
// Leaving must also let the process END. A turn still running (a /exit typed
|
|
194
|
+
// while a reply streams, or a queued message) is cancelled through its own
|
|
195
|
+
// existing signal, so the stream, any command review and the coordinators'
|
|
196
|
+
// cleanup all run on the normal cancellation path. Then stdin is released:
|
|
197
|
+
// the composer resumed it for the whole session, and a flowing TTY stream
|
|
198
|
+
// keeps Node's event loop alive forever — the cause of `cos` lingering after
|
|
199
|
+
// "See you soon" with the terminal still owned by it.
|
|
200
|
+
const leave = () => {
|
|
201
|
+
clearInterval(availabilityTimer);
|
|
202
|
+
queued = null;
|
|
203
|
+
cancelMainTurn();
|
|
204
|
+
stopScreen(); // drop the pinned composer + scroll region before the farewell
|
|
205
|
+
if (process.stdin.isTTY)
|
|
206
|
+
process.stdin.setRawMode(false);
|
|
207
|
+
if (process.stdout.isTTY && process.env.TERM !== "dumb")
|
|
208
|
+
process.stdout.write("\x1b[?25h");
|
|
209
|
+
renderExit(ctx.config.get("sessionId"));
|
|
210
|
+
process.stdin.removeAllListeners("keypress");
|
|
211
|
+
process.stdin.removeAllListeners("data");
|
|
212
|
+
process.stdin.pause();
|
|
213
|
+
};
|
|
214
|
+
for (;;) {
|
|
215
|
+
const placeholder = ctx.chatType === "carrier" && ctx.carrierMaintenance !== false
|
|
216
|
+
? ctx.carrierMaintenance === true
|
|
217
|
+
? "Carrier Chat is under maintenance · /switch standard"
|
|
218
|
+
: "Carrier Chat status unavailable · /switch standard"
|
|
219
|
+
: conversationStarted ? COMPACT_PLACEHOLDER : WELCOME_PLACEHOLDER;
|
|
220
|
+
// One Ctrl+C swaps the status footer for a dim "again to exit" hint beneath
|
|
221
|
+
// the bar (no separate info line); a second Ctrl+C quits.
|
|
222
|
+
const footer = () => sigintArmed ? " " + c.dim("Press Ctrl-C again to exit") : buildFooter(ctx);
|
|
223
|
+
// Keep the palette in step with the chat type — /switch mid-session must
|
|
224
|
+
// add or remove the commands that only apply to one experience (e.g. /fast
|
|
225
|
+
// is Standard-only), the same way the web shows or hides its toggles.
|
|
226
|
+
setCommandScope(ctx.chatType);
|
|
227
|
+
const res = await readCommand(CARET, history, footer, placeholder, () => ctx.chatType === "carrier" && ctx.carrierMaintenance !== false);
|
|
228
|
+
if (res.type === "exit") {
|
|
229
|
+
leave();
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
// ←/→ switch chat type. No confirmation: the outgoing conversation is NOT
|
|
233
|
+
// deleted — setChatType only drops the local pointer to it, and the thread
|
|
234
|
+
// stays on the server. So the note says how to get back rather than asking
|
|
235
|
+
// permission to leave.
|
|
236
|
+
if (res.type === "switch") {
|
|
237
|
+
const target = res.dir === "left" ? "carrier" : "standard";
|
|
238
|
+
if (ctx.chatType === target)
|
|
239
|
+
continue; // already there — nothing to say
|
|
240
|
+
// Refused mid-turn: the in-flight reply belongs to the OUTGOING
|
|
241
|
+
// conversation, and clearing the pointer now would file its session id
|
|
242
|
+
// against the chat type you just left.
|
|
243
|
+
if (mainRunning()) {
|
|
244
|
+
line();
|
|
245
|
+
line(" " + c.warn("!") + " " + c.dim("Finish the current response before switching."));
|
|
246
|
+
line();
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const leaving = describeCurrentSession(ctx);
|
|
250
|
+
ctx.setChatType(target);
|
|
251
|
+
conversationStarted = false; // a fresh conversation starts on the next message
|
|
252
|
+
line();
|
|
253
|
+
line(" " + c.dim("Switched to ") + c.value(chatTypeLabel(target)) + c.dim("."));
|
|
254
|
+
if (leaving)
|
|
255
|
+
line(" " + c.dim(leaving));
|
|
256
|
+
line();
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (res.type === "sigint") {
|
|
260
|
+
// Ctrl+C with a turn in flight cancels the TURN, not the CLI — the same
|
|
261
|
+
// meaning it had when the turn owned stdin. Only an idle Ctrl+C arms the
|
|
262
|
+
// exit, so a mistaken keystroke mid-answer can never drop the shell.
|
|
263
|
+
if (mainRunning()) {
|
|
264
|
+
// Cancelling the running turn also drops whatever was queued behind it —
|
|
265
|
+
// there is nothing for it to run after now.
|
|
266
|
+
queued = null;
|
|
267
|
+
cancelMainTurn();
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (sigintArmed) {
|
|
271
|
+
leave();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
sigintArmed = true;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
sigintArmed = false;
|
|
278
|
+
let message = res.value.trim();
|
|
279
|
+
if (!message)
|
|
280
|
+
continue; // never auto-act on an empty prompt
|
|
281
|
+
history.push(message);
|
|
282
|
+
// Submitting always re-follows the newest output (in case they'd scrolled up).
|
|
283
|
+
screenScrollToBottom();
|
|
284
|
+
// /new is a friendly alias for /clear. A cleared/new session drops back to
|
|
285
|
+
// the welcome placeholder; sending a real message starts the conversation
|
|
286
|
+
// and switches to the compact placeholder.
|
|
287
|
+
if (message === "/new")
|
|
288
|
+
message = "/clear";
|
|
289
|
+
if (message === "/clear")
|
|
290
|
+
conversationStarted = false;
|
|
291
|
+
else if (!message.startsWith("/"))
|
|
292
|
+
conversationStarted = true;
|
|
293
|
+
// A main turn while one is already running is QUEUED, not refused — one at a
|
|
294
|
+
// time, so the pending one is next when the current turn finishes. A quick
|
|
295
|
+
// side question (/btw) is still the way to ask without waiting.
|
|
296
|
+
if (isMainTurn(message) && mainRunning()) {
|
|
297
|
+
if (queued !== null) {
|
|
298
|
+
line();
|
|
299
|
+
line(" " + c.warn("!") + " " + c.dim("A message is already queued — it runs next. Send this once it starts."));
|
|
300
|
+
line();
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
queued = message;
|
|
304
|
+
line(" " + c.dim("⏎ Queued — runs after the current response. Ctrl+C cancels both."));
|
|
305
|
+
}
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
// Main turns are detached so the composer keeps reading; the drain of a
|
|
309
|
+
// queued message is handled in startMainTurn's finally.
|
|
310
|
+
if (isMainTurn(message)) {
|
|
311
|
+
startMainTurn(message);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const { exit } = await dispatchLine(ctx, program, client, message);
|
|
315
|
+
if (exit) {
|
|
316
|
+
// Let an in-flight turn go rather than leaving it writing into a
|
|
317
|
+
// torn-down screen.
|
|
318
|
+
cancelMainTurn();
|
|
319
|
+
leave();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* "Your Carrier conversation "…" is saved — /session 3 to return.", or null when
|
|
326
|
+
* there is nothing to go back to.
|
|
327
|
+
*
|
|
328
|
+
* The ordinal comes from the list `/sessions` last printed, which is what the
|
|
329
|
+
* user would actually type; without it the message names the conversation but
|
|
330
|
+
* points at /sessions instead of inventing a number.
|
|
331
|
+
*/
|
|
332
|
+
function describeCurrentSession(ctx) {
|
|
333
|
+
const id = ctx.config.get("sessionId");
|
|
334
|
+
if (!id)
|
|
335
|
+
return null;
|
|
336
|
+
const title = ctx.config.get("sessionTitle");
|
|
337
|
+
const named = title ? `"${title}"` : "conversation";
|
|
338
|
+
const ordinal = (ctx.config.get("sessionOrdinals") ?? []).indexOf(id) + 1;
|
|
339
|
+
const back = ordinal > 0 ? `/session ${ordinal} to return` : "/sessions to return";
|
|
340
|
+
return `Your ${chatTypeLabel(ctx.chatType)} ${named} is saved — ${back}.`;
|
|
341
|
+
}
|
|
342
|
+
/** First empty session — the welcome placeholder doubles as the input area. */
|
|
343
|
+
const WELCOME_PLACEHOLDER = "What can I help you build today?";
|
|
344
|
+
/** Once the conversation is underway — a compact, unobtrusive prompt. */
|
|
345
|
+
const COMPACT_PLACEHOLDER = "Ask Carrier OS…";
|
|
346
|
+
/** Browser-based first-run sign-in (device authorization). Loops so a denied or
|
|
347
|
+
* expired attempt can be retried; returns false if the user declines or Ctrl+C. */
|
|
348
|
+
async function firstRunLogin(ctx) {
|
|
349
|
+
printWelcome();
|
|
350
|
+
const apiUrl = ctx.config.get("apiUrl") ?? DEFAULT_API_URL;
|
|
351
|
+
for (;;) {
|
|
352
|
+
try {
|
|
353
|
+
const scope = await deviceLogin(ctx, apiUrl);
|
|
354
|
+
const developer = ctx.config.get("auth")?.account?.name || scope.user?.email || "Developer";
|
|
355
|
+
// Claude-style two-step landing: confirm success, then a welcome screen,
|
|
356
|
+
// then into the shell — each gated by Enter.
|
|
357
|
+
line();
|
|
358
|
+
await pressEnter("Login successful. Press Enter to continue…");
|
|
359
|
+
renderWelcomeBack(scope, developer);
|
|
360
|
+
await pressEnter("Press Enter to start Carrier Chat…");
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
renderLoginFailure(err, apiUrl);
|
|
365
|
+
line();
|
|
366
|
+
let again;
|
|
367
|
+
try {
|
|
368
|
+
again = await confirm({ message: "Try again?", default: true });
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
return false; // Ctrl+C at the prompt
|
|
372
|
+
}
|
|
373
|
+
if (!again)
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
/** Print a dim prompt and resolve when the user presses Enter. Used for the
|
|
379
|
+
* Claude-style "Press Enter to continue…" gates before the shell starts (raw
|
|
380
|
+
* TUI mode is not active yet, so a line-mode readline is correct here). */
|
|
381
|
+
function pressEnter(prompt) {
|
|
382
|
+
return new Promise((resolve) => {
|
|
383
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
384
|
+
rl.question(" " + c.dim(prompt) + " ", () => {
|
|
385
|
+
rl.close();
|
|
386
|
+
resolve();
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { repositoryContext, repositoryState } from "../services/task-context.js";
|
|
2
|
+
import { renderTaskContextCard } from "../ui/task-context-card.js";
|
|
3
|
+
import { line } from "../services/output.js";
|
|
4
|
+
/** This conversation's Task Context, or null; never delays the caller by more than a moment. */
|
|
5
|
+
export async function fetchTaskContext(client, sessionId) {
|
|
6
|
+
if (typeof client.taskContext !== "function")
|
|
7
|
+
return null;
|
|
8
|
+
let timer;
|
|
9
|
+
try {
|
|
10
|
+
return await Promise.race([
|
|
11
|
+
client.taskContext(sessionId).catch(() => null),
|
|
12
|
+
new Promise((resolve) => { timer = setTimeout(() => resolve(null), 2500); timer.unref?.(); })
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
finally {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Show the TASK CONTEXT card for a conversation that has recorded coding work
|
|
21
|
+
* — on resume, and when the shell restarts into a remembered session. Context
|
|
22
|
+
* only: it restores nothing that could write a file or run a command.
|
|
23
|
+
*/
|
|
24
|
+
export async function showTaskContext(client, sessionId) {
|
|
25
|
+
if (!sessionId)
|
|
26
|
+
return false;
|
|
27
|
+
const context = await fetchTaskContext(client, sessionId);
|
|
28
|
+
if (!context?.current)
|
|
29
|
+
return false;
|
|
30
|
+
const scope = client.mutationRecoveryScope();
|
|
31
|
+
// Verify, before anything is shown as continuing: the repository this CLI is
|
|
32
|
+
// in now, and whether it is the one the earlier work used; file freshness for
|
|
33
|
+
// the files that work touched.
|
|
34
|
+
const repo = repositoryContext(scope, sessionId);
|
|
35
|
+
const state = repo?.same_repository === false ? [] : repositoryState(scope, sessionId);
|
|
36
|
+
for (const l of renderTaskContextCard(context, state, repo))
|
|
37
|
+
line(l);
|
|
38
|
+
line();
|
|
39
|
+
return true;
|
|
40
|
+
}
|
package/dist/staging.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Public /v1 API contract — mirrors the shapes returned by api.carrieros.ai's
|
|
2
|
+
// `src/routes/v1/*`. The CLI is a pure consumer: it never reimplements any of
|
|
3
|
+
// this logic, it only types the JSON it receives.
|
|
4
|
+
export function isMemoryMarker(m) {
|
|
5
|
+
return m.role === "marker";
|
|
6
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { c } from "./colors.js";
|
|
2
|
+
import { MARGIN, contentWidth, visibleWidth } from "./composer-layout.js";
|
|
3
|
+
import { clip, stripControl, wrapText } from "./conversation.js";
|
|
4
|
+
/**
|
|
5
|
+
* Small, shared building blocks for the coding-agent cards: a titled section,
|
|
6
|
+
* a labelled field, the approval card and the one-line workflow status track.
|
|
7
|
+
*
|
|
8
|
+
* Presentation only. Every value shown comes from an existing source of truth
|
|
9
|
+
* — the CodingWorkflow snapshot, the mutation plan the MutationCoordinator
|
|
10
|
+
* reviews, the command PolicyDecision, the recorded results. Nothing here
|
|
11
|
+
* decides, approves, or keeps state of its own. Layout adapts to the terminal
|
|
12
|
+
* width (no fixed widths), wraps rather than clips anything a decision depends
|
|
13
|
+
* on, and reads the same without color.
|
|
14
|
+
*/
|
|
15
|
+
export const INDENT = MARGIN + " ";
|
|
16
|
+
const safe = stripControl;
|
|
17
|
+
/** Width a card's text may use at the current terminal width. */
|
|
18
|
+
export const cardWidth = () => Math.max(20, contentWidth() - INDENT.length - 1);
|
|
19
|
+
/** A divider sized to the terminal, never wider than a comfortable card. */
|
|
20
|
+
export const rule = () => MARGIN + c.dim("─".repeat(Math.max(8, Math.min(contentWidth() - 1, 48))));
|
|
21
|
+
/** `TITLE` and its divider. `right` is optional, shown when it fits. */
|
|
22
|
+
export function cardHeader(title, paint = c.title, right = "") {
|
|
23
|
+
const head = paint(title);
|
|
24
|
+
const room = contentWidth() - 1 - visibleWidth(title) - 2;
|
|
25
|
+
const tail = right && visibleWidth(right) <= room ? " ".repeat(Math.max(2, room - visibleWidth(right) + 2)) + right : "";
|
|
26
|
+
return ["", MARGIN + head + tail, rule()];
|
|
27
|
+
}
|
|
28
|
+
/** `Label` on its own line, the value(s) indented beneath — the card's field shape. */
|
|
29
|
+
export function cardField(label, values, paint = c.value) {
|
|
30
|
+
const list = (Array.isArray(values) ? values : [values]).filter((v) => v !== undefined && v !== null && String(v).trim() !== "");
|
|
31
|
+
if (!list.length)
|
|
32
|
+
return [];
|
|
33
|
+
const out = [MARGIN + c.dim(label)];
|
|
34
|
+
for (const value of list)
|
|
35
|
+
for (const line of wrapText(safe(String(value)), cardWidth()))
|
|
36
|
+
out.push(INDENT + paint(line));
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
/** One `Label value` line, for compact metadata (clipped only when it is metadata). */
|
|
40
|
+
export function metaLine(label, value) {
|
|
41
|
+
return MARGIN + c.dim(label + " ") + c.value(clip(safe(value), Math.max(8, cardWidth() - label.length)));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* What is waiting for the person, with the keys that answer it. The keys are
|
|
45
|
+
* the existing approval contract (y/Y + Enter approves; n, Enter, Esc decline;
|
|
46
|
+
* Ctrl+C stops the turn) — this card only names them; the prompt below it is
|
|
47
|
+
* still the one that reads them.
|
|
48
|
+
*/
|
|
49
|
+
export function approvalCard(kind, detail, operationIds) {
|
|
50
|
+
const verb = kind === "command" ? "Approve command" : kind === "correction" ? "Approve correction" : "Approve change";
|
|
51
|
+
const out = [""];
|
|
52
|
+
// The approval state leads the line, so what is pending is never ambiguous.
|
|
53
|
+
for (const [i, line] of wrapText(`Awaiting approval — ${safe(detail)}`, cardWidth()).entries()) {
|
|
54
|
+
out.push(MARGIN + (i === 0 && line.startsWith("Awaiting approval") ? c.warn("Awaiting approval") + c.dim(line.slice("Awaiting approval".length)) : c.dim(line)));
|
|
55
|
+
}
|
|
56
|
+
out.push(MARGIN + c.key("[ y ]") + " " + c.value(verb) + " " + c.key("[ n ]") + " " + c.value("Reject"));
|
|
57
|
+
if (operationIds.length) {
|
|
58
|
+
const label = operationIds.length === 1 ? "Operation: " : "Operations: ";
|
|
59
|
+
for (const line of wrapText(label + operationIds.join(", "), cardWidth()))
|
|
60
|
+
out.push(MARGIN + c.dim(line));
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
// ── Status track ─────────────────────────────────────────────────────────────
|
|
65
|
+
// A projection of the EXISTING CodingWorkflow state (snapshot.state) onto the
|
|
66
|
+
// stages a person thinks in. It is not a second state machine: it holds no
|
|
67
|
+
// state, and every stage it shows is derived from the snapshot it is given.
|
|
68
|
+
const STAGES = ["Investigate", "Plan", "Review", "Apply", "Test", "Done"];
|
|
69
|
+
const STAGE_OF = {
|
|
70
|
+
TASK_RECEIVED: 0, INSPECTING: 0,
|
|
71
|
+
PLANNING: 1, CAPABILITY_CHECK: 1, READING: 1,
|
|
72
|
+
PROPOSING: 2, AWAITING_APPROVAL: 2, CORRECTIVE_PROPOSAL: 2, CORRECTIVE_APPROVAL: 2,
|
|
73
|
+
APPLYING: 3, REAPPLYING: 3,
|
|
74
|
+
TESTING: 4, RETESTING: 4, ANALYZING_FAILURE: 4,
|
|
75
|
+
COMPLETED: 5
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* `✓ Investigate › ✓ Plan › ● Review › ○ Apply › ○ Test › ○ Done`.
|
|
79
|
+
* `lastActive` is the stage the workflow was in before it stopped (the caller
|
|
80
|
+
* passes the last state it saw), so a stop is marked where it happened.
|
|
81
|
+
*/
|
|
82
|
+
export function statusTrack(snapshot, lastActive) {
|
|
83
|
+
const state = String(snapshot.state ?? "");
|
|
84
|
+
const corrections = Number(snapshot.corrections) || 0;
|
|
85
|
+
const stopped = ["FAILED", "CANCELLED", "UNRESOLVED"].includes(state);
|
|
86
|
+
const at = stopped ? STAGE_OF[lastActive ?? ""] ?? 0 : STAGE_OF[state] ?? 0;
|
|
87
|
+
const done = state === "COMPLETED";
|
|
88
|
+
const marks = STAGES.map((name, i) => {
|
|
89
|
+
let label = name;
|
|
90
|
+
if (i === 4 && state === "ANALYZING_FAILURE")
|
|
91
|
+
return c.err("✕") + " " + c.dim("Test") + c.dim(" › ") + c.warn("●") + " " + c.value("Analyze");
|
|
92
|
+
if (done || i < at)
|
|
93
|
+
return c.ok("✓") + " " + c.dim(label);
|
|
94
|
+
if (i === at) {
|
|
95
|
+
if (stopped)
|
|
96
|
+
return (state === "CANCELLED" ? c.warn("⊘") : c.err("✕")) + " " + c.value(label);
|
|
97
|
+
if (i === 5)
|
|
98
|
+
label = "Done";
|
|
99
|
+
return c.warn("●") + " " + c.value(label);
|
|
100
|
+
}
|
|
101
|
+
return c.dim("○ " + label);
|
|
102
|
+
});
|
|
103
|
+
const suffix = corrections ? c.dim(` · correction ${corrections}`) : "";
|
|
104
|
+
const full = marks.join(c.dim(" › ")) + suffix;
|
|
105
|
+
if (visibleWidth(full) <= contentWidth() - 1)
|
|
106
|
+
return MARGIN + full;
|
|
107
|
+
// Narrow terminal: the current stage and progress, nothing secondary.
|
|
108
|
+
const current = done ? "Done" : STAGES[Math.min(at, 5)];
|
|
109
|
+
const icon = done ? c.ok("✓") : stopped ? c.err("✕") : c.warn("●");
|
|
110
|
+
return MARGIN + icon + " " + c.value(current) + c.dim(` · ${done ? 6 : at + 1}/6`) + suffix;
|
|
111
|
+
}
|