@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
package/dist/shell/shell.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import readline from "node:readline";
|
|
2
2
|
import { confirm } from "@inquirer/prompts";
|
|
3
3
|
import { DEFAULT_API_URL } from "../services/config.js";
|
|
4
|
+
import { isPackaged } from "../services/packaged.js";
|
|
5
|
+
import { refreshPackagedUpdateCache } from "../services/packaged-update.js";
|
|
4
6
|
import { deviceLogin, renderLoginFailure } from "../services/login-flow.js";
|
|
5
7
|
import { line } from "../services/output.js";
|
|
8
|
+
import { showTaskContext } from "./task-context-view.js";
|
|
6
9
|
import { renderWelcomeBanner } from "../ui/banner.js";
|
|
7
10
|
import { renderExit } from "../ui/chat-renderer.js";
|
|
8
11
|
import { c } from "../ui/colors.js";
|
|
9
12
|
import { readCommand } from "../ui/command-palette.js";
|
|
13
|
+
import { setCommandScope } from "../ui/command-item.js";
|
|
10
14
|
import { startScreen, stopScreen, screenScrollToBottom } from "../ui/screen.js";
|
|
11
|
-
import {
|
|
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";
|
|
12
19
|
import { CARET, buildFooter } from "./shell-prompt.js";
|
|
13
|
-
import { dispatchLine } from "./shell-router.js";
|
|
20
|
+
import { dispatchLine, isMainTurn } from "./shell-router.js";
|
|
14
21
|
import { printWelcome, renderWelcomeBack } from "./shell-renderer.js";
|
|
15
22
|
/**
|
|
16
23
|
* The interactive Carrier OS shell — the default experience when you run
|
|
@@ -19,6 +26,12 @@ import { printWelcome, renderWelcomeBack } from "./shell-renderer.js";
|
|
|
19
26
|
* through the same Commander program, so no logic is duplicated.
|
|
20
27
|
*/
|
|
21
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;
|
|
22
35
|
// Returning users see the branded banner once; a fresh login already showed
|
|
23
36
|
// the branding + scope in the welcome / auth-success screens, so we don't
|
|
24
37
|
// repeat it after logging in.
|
|
@@ -29,29 +42,93 @@ export async function runShell(ctx, program) {
|
|
|
29
42
|
return; // user chose /exit or Ctrl+C
|
|
30
43
|
}
|
|
31
44
|
const client = ctx.requireAuth();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
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.
|
|
36
54
|
// Preload the mode + model lists so the prompt/banner can show friendly labels
|
|
37
55
|
// (e.g. the "Carrier OS" mode name rather than the raw id).
|
|
38
|
-
await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => [])]);
|
|
56
|
+
await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => []), loadFastModel(client)]);
|
|
39
57
|
// Enter TUI mode: pin the composer to the bottom of the terminal and give the
|
|
40
58
|
// transcript its own scrolling region above it (Claude-style). From here, all
|
|
41
59
|
// output flows into the transcript via the screen engine.
|
|
42
60
|
startScreen();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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"));
|
|
53
79
|
}
|
|
54
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
|
+
}
|
|
55
132
|
// Interactive loop driven by the composer/reader. Each iteration reads one
|
|
56
133
|
// line (with the slash palette overlay, the dim status footer, and a
|
|
57
134
|
// placeholder inside the box), then dispatches it. Enter in the palette only
|
|
@@ -59,26 +136,137 @@ export async function runShell(ctx, program) {
|
|
|
59
136
|
const history = [];
|
|
60
137
|
let sigintArmed = false;
|
|
61
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
|
+
};
|
|
62
190
|
// Leaving the shell: restore cooked mode + a visible cursor (the reader keeps
|
|
63
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.
|
|
64
200
|
const leave = () => {
|
|
201
|
+
clearInterval(availabilityTimer);
|
|
202
|
+
queued = null;
|
|
203
|
+
cancelMainTurn();
|
|
65
204
|
stopScreen(); // drop the pinned composer + scroll region before the farewell
|
|
66
205
|
if (process.stdin.isTTY)
|
|
67
206
|
process.stdin.setRawMode(false);
|
|
68
|
-
process.stdout.
|
|
207
|
+
if (process.stdout.isTTY && process.env.TERM !== "dumb")
|
|
208
|
+
process.stdout.write("\x1b[?25h");
|
|
69
209
|
renderExit(ctx.config.get("sessionId"));
|
|
210
|
+
process.stdin.removeAllListeners("keypress");
|
|
211
|
+
process.stdin.removeAllListeners("data");
|
|
212
|
+
process.stdin.pause();
|
|
70
213
|
};
|
|
71
214
|
for (;;) {
|
|
72
|
-
const placeholder =
|
|
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;
|
|
73
220
|
// One Ctrl+C swaps the status footer for a dim "again to exit" hint beneath
|
|
74
221
|
// the bar (no separate info line); a second Ctrl+C quits.
|
|
75
|
-
const footer = sigintArmed ? " " + c.dim("Press Ctrl-C again to exit") : buildFooter(ctx);
|
|
76
|
-
|
|
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);
|
|
77
228
|
if (res.type === "exit") {
|
|
78
229
|
leave();
|
|
79
230
|
return;
|
|
80
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
|
+
}
|
|
81
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
|
+
}
|
|
82
270
|
if (sigintArmed) {
|
|
83
271
|
leave();
|
|
84
272
|
return;
|
|
@@ -89,7 +277,7 @@ export async function runShell(ctx, program) {
|
|
|
89
277
|
sigintArmed = false;
|
|
90
278
|
let message = res.value.trim();
|
|
91
279
|
if (!message)
|
|
92
|
-
continue;
|
|
280
|
+
continue; // never auto-act on an empty prompt
|
|
93
281
|
history.push(message);
|
|
94
282
|
// Submitting always re-follows the newest output (in case they'd scrolled up).
|
|
95
283
|
screenScrollToBottom();
|
|
@@ -102,13 +290,55 @@ export async function runShell(ctx, program) {
|
|
|
102
290
|
conversationStarted = false;
|
|
103
291
|
else if (!message.startsWith("/"))
|
|
104
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
|
+
}
|
|
105
314
|
const { exit } = await dispatchLine(ctx, program, client, message);
|
|
106
315
|
if (exit) {
|
|
316
|
+
// Let an in-flight turn go rather than leaving it writing into a
|
|
317
|
+
// torn-down screen.
|
|
318
|
+
cancelMainTurn();
|
|
107
319
|
leave();
|
|
108
320
|
return;
|
|
109
321
|
}
|
|
110
322
|
}
|
|
111
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
|
+
}
|
|
112
342
|
/** First empty session — the welcome placeholder doubles as the input area. */
|
|
113
343
|
const WELCOME_PLACEHOLDER = "What can I help you build today?";
|
|
114
344
|
/** Once the conversation is underway — a compact, unobtrusive prompt. */
|
|
@@ -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/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,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
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { c } from './colors.js';
|
|
3
|
+
import { MARGIN, contentWidth } from './composer-layout.js';
|
|
4
|
+
import { clip, stripControl, wrapText } from './conversation.js';
|
|
5
|
+
import { INDENT, cardField, cardHeader, cardWidth } from './agent-cards.js';
|
|
6
|
+
import { displayCommand } from '../services/command-policy.js';
|
|
7
|
+
export const ACTIVITY = {
|
|
8
|
+
IDLE: 'Ready', THINKING: 'Thinking', INSPECTING: 'Inspecting repository', SEARCHING: 'Searching repository', READING: 'Reading files', PLANNING: 'Creating plan', PROPOSAL_READY: 'Change proposed', WAITING_FOR_MUTATION_APPROVAL: 'Waiting for change approval', APPLYING: 'Applying changes', VALIDATION_PENDING: 'Validation pending', WAITING_FOR_COMMAND_APPROVAL: 'Waiting for command approval', RUNNING_COMMAND: 'Running command', ANALYZING_FAILURE: 'Analyzing failure', CORRECTION_PROPOSED: 'Correction proposed', WAITING_FOR_CORRECTION_APPROVAL: 'Waiting for correction approval', RETESTING: 'Retesting', COMPLETED: 'Completed', FAILED: 'Failed', CANCELLED: 'Cancelled', UNRESOLVED: 'Unresolved'
|
|
9
|
+
};
|
|
10
|
+
export function workflowActivity(snapshot) {
|
|
11
|
+
const state = String(snapshot.state), correction = Number(snapshot.corrections) > 0;
|
|
12
|
+
if (state === 'COMPLETED')
|
|
13
|
+
return 'Validation passed · awaiting completion';
|
|
14
|
+
if (state === 'READING')
|
|
15
|
+
return correction ? 'Preparing correction' : 'Preparing changes';
|
|
16
|
+
if (state === 'APPLYING' || state === 'REAPPLYING') {
|
|
17
|
+
const validation = snapshot.validation;
|
|
18
|
+
if (validation?.some(v => v.status === 'PENDING_REVIEW'))
|
|
19
|
+
return correction ? 'Retest required' : 'Validation pending';
|
|
20
|
+
return correction ? 'Applying correction' : 'Applying changes';
|
|
21
|
+
}
|
|
22
|
+
const names = { TASK_RECEIVED: 'Thinking', INSPECTING: 'Inspecting repository', PLANNING: 'Creating plan', CAPABILITY_CHECK: 'Checking execution capability', READING: correction ? 'Preparing correction' : 'Preparing changes', PROPOSING: 'Change proposed', AWAITING_APPROVAL: 'Waiting for change approval', APPLYING: correction ? 'Applying correction' : 'Applying changes', TESTING: 'Running validation', ANALYZING_FAILURE: 'Analyzing failure', CORRECTIVE_PROPOSAL: 'Correction proposed', CORRECTIVE_APPROVAL: 'Waiting for correction approval', REAPPLYING: 'Applying correction', RETESTING: 'Retesting', COMPLETED: 'Completed', FAILED: 'Failed', CANCELLED: 'Cancelled', UNRESOLVED: 'Unresolved' };
|
|
23
|
+
return names[state] ?? 'Working';
|
|
24
|
+
}
|
|
25
|
+
const commandLabel = (t) => typeof t.program === 'string' ? `${displayCommand(t.program, Array.isArray(t.args) ? t.args.map(String) : [])}${t.cwd && t.cwd !== '.' ? ` · ${t.cwd}` : ''}` : '';
|
|
26
|
+
/** The recorded analysis text, from the workflow's own "Failure analysis (…): …" line. */
|
|
27
|
+
export function analysisExplanation(lines) {
|
|
28
|
+
const m = /^Failure analysis \(([^)]+)\):\s*([\s\S]*)$/.exec(stripControl(lines.join(' ')));
|
|
29
|
+
return { classification: m?.[1] ?? 'recorded', explanation: m?.[2] ?? stripControl(lines.join(' ')) };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The PLAN card: the workflow's own structured plan (snapshot.plan), not a copy.
|
|
33
|
+
* "Root cause" appears only where the workflow recorded one — the failure
|
|
34
|
+
* analysis behind a corrective plan. An initial plan has no such field, so it
|
|
35
|
+
* shows the planned expected behavior instead of inventing a cause.
|
|
36
|
+
*/
|
|
37
|
+
export function renderAgentPlan(snapshot, opts = {}) {
|
|
38
|
+
const plan = snapshot.plan;
|
|
39
|
+
if (!plan)
|
|
40
|
+
return [];
|
|
41
|
+
const corrective = Number(snapshot.corrections) > 0;
|
|
42
|
+
const rows = [...cardHeader(corrective ? 'CORRECTIVE PLAN' : 'PLAN', c.title)];
|
|
43
|
+
rows.push(...cardField('Task', clip(stripControl(plan.summary), 240)));
|
|
44
|
+
const inv = plan.investigation;
|
|
45
|
+
if (corrective && opts.rootCause)
|
|
46
|
+
rows.push(...cardField('Root cause', clip(stripControl(opts.rootCause), 240)));
|
|
47
|
+
else if (inv) {
|
|
48
|
+
// The investigation the workflow verified, symptom first: where it shows, why, where to change.
|
|
49
|
+
rows.push(...cardField('Symptom', clip(stripControl(inv.symptom), 200), c.dim));
|
|
50
|
+
rows.push(...cardField('Path', inv.execution_path.slice(0, 8).map(s => s.symbol ? `${s.path} · ${s.symbol}` : s.path), c.file));
|
|
51
|
+
rows.push(...cardField('Root cause', clip(stripControl(inv.root_cause), 240)));
|
|
52
|
+
rows.push(...cardField('Change at', `${inv.change_location.path}${inv.change_location.symbol ? ` · ${inv.change_location.symbol}` : ''}`, c.file));
|
|
53
|
+
if (inv.evidence?.length)
|
|
54
|
+
rows.push(...cardField('Evidence', inv.evidence.slice(0, 4).map(e => clip(stripControl(`${e.path}${e.lines ? `:${e.lines}` : ''} — ${e.note}`), 160)), c.dim));
|
|
55
|
+
if (inv.ruled_out?.length)
|
|
56
|
+
rows.push(...cardField('Ruled out', inv.ruled_out.slice(0, 4).map(r => clip(stripControl(`${r.path} — ${r.reason}`), 160)), c.dim));
|
|
57
|
+
}
|
|
58
|
+
else if (plan.expected)
|
|
59
|
+
rows.push(...cardField('Expected', clip(stripControl(plan.expected), 200), c.dim));
|
|
60
|
+
rows.push(...cardField('Files', plan.files.slice(0, 8).map(f => f.path), c.file));
|
|
61
|
+
if (plan.files.length > 8)
|
|
62
|
+
rows.push(INDENT + c.dim(`+${plan.files.length - 8} more planned files`));
|
|
63
|
+
rows.push(...cardField('Validation', plan.tests.slice(0, 3).map(t => commandLabel(t)).filter(Boolean)));
|
|
64
|
+
if (plan.risks)
|
|
65
|
+
rows.push(...cardField('Risk', clip(stripControl(plan.risks), 160), c.dim));
|
|
66
|
+
rows.push('');
|
|
67
|
+
return rows;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The analysis the workflow recorded after a failed validation — classification
|
|
71
|
+
* and the stated evidence, as recorded by coding_workflow(analyze). It is the
|
|
72
|
+
* tool's input, shown as an operational record, not hidden reasoning.
|
|
73
|
+
*/
|
|
74
|
+
export function renderFailureAnalysis(lines) {
|
|
75
|
+
const { classification, explanation } = analysisExplanation(lines);
|
|
76
|
+
const out = ['', MARGIN + c.title('Analyzing failure…'), MARGIN + ' ' + c.ok('✓ ') + c.value('Failure evidence captured') + c.dim(` · ${classification}`)];
|
|
77
|
+
for (const line of wrapText(explanation, cardWidth() - 2))
|
|
78
|
+
out.push(INDENT + ' ' + c.dim(line));
|
|
79
|
+
out.push(MARGIN + c.dim('Fresh reads and a new plan come next; any correction needs its own approval.'), '');
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
/** Called only after the shell's existing interrupt/acknowledged-finish guard. */
|
|
83
|
+
export function renderAgentOutcome(snapshot, ctx = {}) {
|
|
84
|
+
if (!snapshot.plan)
|
|
85
|
+
return [];
|
|
86
|
+
const plan = snapshot.plan;
|
|
87
|
+
const state = String(snapshot.state), files = Array.isArray(snapshot.files) ? snapshot.files.map(String) : [];
|
|
88
|
+
const validation = (snapshot.validation ?? []);
|
|
89
|
+
const corrections = Number(snapshot.corrections) || 0;
|
|
90
|
+
const applied = ctx.applied ?? [];
|
|
91
|
+
// A person's "no" is a decision, not a failure (the workflow still records
|
|
92
|
+
// FAILED), and an invalidated change is a safety stop. Each already has its
|
|
93
|
+
// own card at the moment it happened (CHANGE REJECTED / CHANGE INVALIDATED),
|
|
94
|
+
// so the turn ends there — no second card, and never "Failed".
|
|
95
|
+
if (ctx.declined && applied.length === 0)
|
|
96
|
+
return [];
|
|
97
|
+
const changed = files.length ? files : [...new Set(applied.map(a => a.rel))];
|
|
98
|
+
const commands = validation.map(t => commandLabel(t) + (t.status ? ` — ${t.status === 'PASSED' ? 'passed' : t.status === 'FAILED' ? 'failed' : 'not completed'}` : '')).filter(Boolean);
|
|
99
|
+
if (state === 'COMPLETED') {
|
|
100
|
+
// The validation counts arrive as "3 passed · 0 failed"; one fact per line.
|
|
101
|
+
const counts = (ctx.validationCounts ?? '').split(' · ').filter(Boolean);
|
|
102
|
+
const changes = `${changed.length} file${changed.length === 1 ? '' : 's'} modified${applied.length > changed.length ? ` · ${applied.length} approved changes` : ''}`;
|
|
103
|
+
return [...cardHeader('✓ COMPLETED', c.ok),
|
|
104
|
+
...cardField('Task', clip(stripControl(ctx.task ?? plan.summary), 200)),
|
|
105
|
+
...cardField('Changes', changes),
|
|
106
|
+
...cardField('Validation', [...validation.map(commandLabel).filter(Boolean), ...counts]),
|
|
107
|
+
...cardField('Corrections', String(corrections)),
|
|
108
|
+
...cardField('Files modified', changed.slice(0, 8), c.file),
|
|
109
|
+
...(changed.length > 8 ? [INDENT + c.dim(`+${changed.length - 8} more`)] : []),
|
|
110
|
+
...cardField('Operation IDs', applied.map(a => a.operationId), c.dim),
|
|
111
|
+
'', MARGIN + c.ok('✓ ') + c.value(validation.length && validation.every(v => v.status === 'PASSED') ? 'The issue has been fixed and verified.' : 'The task completed.'), ''];
|
|
112
|
+
}
|
|
113
|
+
const title = state === 'CANCELLED' ? '⊘ CANCELLED' : state === 'FAILED' ? '✗ FAILED' : '! UNRESOLVED';
|
|
114
|
+
const reason = state === 'CANCELLED' ? 'The turn stopped. Review retained changes before continuing.' : state === 'FAILED' ? 'The workflow stopped. Review the step above, then start a new task.' : 'Required validation or acknowledgment is incomplete. Nothing resumes automatically.';
|
|
115
|
+
return [...cardHeader(title, state === 'CANCELLED' ? c.warn : c.err), ...wrapText(reason, cardWidth()).map(l => MARGIN + c.dim(l)),
|
|
116
|
+
...cardField('Applied', applied.map(a => `${a.rel} · +${a.added} −${a.removed} · ${a.operationId}`), c.file),
|
|
117
|
+
...cardField('Validation', commands), ''];
|
|
118
|
+
}
|
|
119
|
+
export function toolActivity(name, args, root) {
|
|
120
|
+
// A search is named by what it looks for; its directory only narrows it.
|
|
121
|
+
if (name === 'search_files' && typeof args.query === 'string')
|
|
122
|
+
return clip(`Searching ${stripControl(args.query)}${typeof args.path === 'string' && args.path ? ` in ${stripControl(args.path)}` : ''}`, contentWidth() - 6);
|
|
123
|
+
if (name === 'find_symbol' && typeof args.name === 'string')
|
|
124
|
+
return clip(`Finding definition ${stripControl(args.name)}`, contentWidth() - 6);
|
|
125
|
+
if (name === 'find_references' && typeof args.name === 'string')
|
|
126
|
+
return clip(`Finding usages ${stripControl(args.name)}`, contentWidth() - 6);
|
|
127
|
+
const raw = String(args.path ?? args.query ?? args.pattern ?? args.reference ?? args.revision ?? '');
|
|
128
|
+
const value = path.isAbsolute(raw) && !path.relative(root, raw).startsWith('..') ? path.relative(root, raw) : raw;
|
|
129
|
+
const labels = { read_file: 'Reading', search_files: 'Searching', list_files: 'Inspecting repository', find_files: 'Finding files', git_log: 'Reading history', git_blame: 'Reading blame', git_show: 'Reading commit', git_status: 'Inspecting repository', git_diff: 'Inspecting changes', resolve_local_file: 'Finding file', code_outline: 'Outlining', coding_workflow: args.action === 'analyze' ? 'Analyzing failure' : args.action === 'plan' ? 'Creating plan' : 'Checking workflow', run_command: 'Preparing command', edit_file: 'Preparing change', write_file: 'Preparing change', create_file: 'Preparing change', delete_file: 'Preparing deletion', revert_change: 'Preparing revert' };
|
|
130
|
+
return clip(`${labels[name] ?? 'Inspecting'}${value ? ' ' + stripControl(value) : ''}`, contentWidth() - 6);
|
|
131
|
+
}
|