@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
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { c } from "./colors.js";
|
|
2
|
+
import { MARGIN, contentWidth, visibleWidth } from "./composer-layout.js";
|
|
3
|
+
import { renderMarkdown } from "./markdown.js";
|
|
4
|
+
/** Elapsed time is noise below this; a person only cares once it drags. */
|
|
5
|
+
const SHOW_ELAPSED_AFTER_MS = 2000;
|
|
6
|
+
/**
|
|
7
|
+
* Text that cannot drive the terminal: escape sequences and control characters
|
|
8
|
+
* removed. Everything shown from a file, a command or its output goes through
|
|
9
|
+
* this — output is untrusted input, and a stray escape sequence could move the
|
|
10
|
+
* cursor, repaint rows the renderer owns, or hide text from the person
|
|
11
|
+
* approving a change.
|
|
12
|
+
*/
|
|
13
|
+
export function stripControl(text) {
|
|
14
|
+
return text
|
|
15
|
+
.replace(/\x1b\][^\x07\x1b]*(\x07|\x1b\\)/g, "")
|
|
16
|
+
.replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g, "")
|
|
17
|
+
.replace(/\x1b[@-_]/g, "")
|
|
18
|
+
// eslint-disable-next-line no-control-regex
|
|
19
|
+
.replace(/[\x00-\x08\x0b-\x1f\x7f]/g, "");
|
|
20
|
+
}
|
|
21
|
+
/** Trim to a visible width, ellipsising rather than wrapping. */
|
|
22
|
+
export function clip(text, width) {
|
|
23
|
+
const plain = stripControl(text);
|
|
24
|
+
if (visibleWidth(plain) <= width)
|
|
25
|
+
return plain;
|
|
26
|
+
return [...plain].slice(0, Math.max(1, width - 1)).join("") + "…";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Shorten a command for an activity line, keeping both ends: `npm run build …
|
|
30
|
+
* --sourcemap` says more than the first 60 characters do.
|
|
31
|
+
*/
|
|
32
|
+
export function clipCommand(text, width) {
|
|
33
|
+
const plain = stripControl(text);
|
|
34
|
+
if (visibleWidth(plain) <= width)
|
|
35
|
+
return plain;
|
|
36
|
+
if (width < 22)
|
|
37
|
+
return clip(plain, width);
|
|
38
|
+
const keepEnd = Math.max(8, Math.floor((width - 3) * 0.35));
|
|
39
|
+
const keepStart = Math.max(8, width - 3 - keepEnd);
|
|
40
|
+
return [...plain].slice(0, keepStart).join("") + " … " + [...plain].slice(-keepEnd).join("");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Wrap `text` to `width`, breaking on spaces but never dropping characters —
|
|
44
|
+
* for anything a person needs in full: a command, a path, a reason.
|
|
45
|
+
*/
|
|
46
|
+
export function wrapText(text, width) {
|
|
47
|
+
const w = Math.max(1, width);
|
|
48
|
+
const out = [];
|
|
49
|
+
for (const paragraph of text.split("\n")) {
|
|
50
|
+
let cur = "";
|
|
51
|
+
for (const word of paragraph.split(/\s+/).filter(Boolean)) {
|
|
52
|
+
if (!cur)
|
|
53
|
+
cur = word;
|
|
54
|
+
else if ([...cur].length + 1 + [...word].length <= w)
|
|
55
|
+
cur = `${cur} ${word}`;
|
|
56
|
+
else {
|
|
57
|
+
out.push(cur);
|
|
58
|
+
cur = word;
|
|
59
|
+
}
|
|
60
|
+
while ([...cur].length > w) {
|
|
61
|
+
out.push([...cur].slice(0, w).join(""));
|
|
62
|
+
cur = [...cur].slice(w).join("");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
out.push(cur);
|
|
66
|
+
}
|
|
67
|
+
return out.length ? out : [""];
|
|
68
|
+
}
|
|
69
|
+
/** Elapsed seconds, shown only once an operation has actually taken time. */
|
|
70
|
+
export function elapsedLabel(sinceMs, now = Date.now()) {
|
|
71
|
+
const ms = now - sinceMs;
|
|
72
|
+
if (ms < SHOW_ELAPSED_AFTER_MS)
|
|
73
|
+
return "";
|
|
74
|
+
return ms < 60_000 ? ` · ${Math.round(ms / 1000)}s` : ` · ${Math.floor(ms / 60_000)}m${Math.round((ms % 60_000) / 1000)}s`;
|
|
75
|
+
}
|
|
76
|
+
/** Keeps the last few lines of live command output for the transient tail. */
|
|
77
|
+
/**
|
|
78
|
+
* Lines worth NOT showing a person while a command runs.
|
|
79
|
+
*
|
|
80
|
+
* Display only — the model still receives the full bounded result from the
|
|
81
|
+
* process runner; this trims the live terminal tail so framework startup noise
|
|
82
|
+
* does not bury the test progress a person is watching for. Errors, failures,
|
|
83
|
+
* test counts and warnings that name a real problem are never matched here.
|
|
84
|
+
*/
|
|
85
|
+
export function isNoiseLine(line) {
|
|
86
|
+
const t = line.trim();
|
|
87
|
+
if (!t)
|
|
88
|
+
return true;
|
|
89
|
+
if (/\b(error|warn|warning|failed|failure)\b/i.test(t))
|
|
90
|
+
return false;
|
|
91
|
+
return (/^\(node:\d+\)\s+ExperimentalWarning/.test(t) ||
|
|
92
|
+
/^\(Use `node --trace-warnings/.test(t) ||
|
|
93
|
+
// Winston / pino style structured logs: "info:", "debug:", "http:", plus a
|
|
94
|
+
// trailing {"service":…,"timestamp":…} — never "error:" or "warn:".
|
|
95
|
+
/^(info|debug|verbose|silly|trace|http)\s*:/i.test(t) ||
|
|
96
|
+
/^\[\d{4}-\d\d-\d\dT[\d:.]+Z?\]\s*(info|debug|verbose|http)\b/i.test(t) ||
|
|
97
|
+
/"service"\s*:\s*"[^"]+"\s*,\s*"timestamp"/.test(t));
|
|
98
|
+
}
|
|
99
|
+
export class OutputTail {
|
|
100
|
+
max;
|
|
101
|
+
denoise;
|
|
102
|
+
lines = [""];
|
|
103
|
+
constructor(max = 5,
|
|
104
|
+
/** When true, framework/log noise is dropped from the live tail (display only). */
|
|
105
|
+
denoise = false) {
|
|
106
|
+
this.max = max;
|
|
107
|
+
this.denoise = denoise;
|
|
108
|
+
}
|
|
109
|
+
push(text) {
|
|
110
|
+
const parts = text.replace(/\r\n/g, "\n").split("\n");
|
|
111
|
+
this.lines[this.lines.length - 1] += parts[0];
|
|
112
|
+
for (const p of parts.slice(1))
|
|
113
|
+
this.lines.push(p);
|
|
114
|
+
if (this.denoise)
|
|
115
|
+
this.lines = this.dropNoise(this.lines);
|
|
116
|
+
if (this.lines.length > this.max + 1)
|
|
117
|
+
this.lines.splice(0, this.lines.length - (this.max + 1));
|
|
118
|
+
}
|
|
119
|
+
/** Drop noise lines, but keep the trailing (possibly partial) line intact. */
|
|
120
|
+
dropNoise(lines) {
|
|
121
|
+
const last = lines[lines.length - 1];
|
|
122
|
+
const kept = lines.slice(0, -1).filter((l) => !isNoiseLine(l));
|
|
123
|
+
kept.push(last);
|
|
124
|
+
return kept.length ? kept : [""];
|
|
125
|
+
}
|
|
126
|
+
clear() {
|
|
127
|
+
this.lines = [""];
|
|
128
|
+
}
|
|
129
|
+
view(width) {
|
|
130
|
+
const shown = this.lines[this.lines.length - 1] === "" ? this.lines.slice(0, -1) : this.lines;
|
|
131
|
+
return shown
|
|
132
|
+
.slice(-this.max)
|
|
133
|
+
.filter((l) => l.trim())
|
|
134
|
+
.map((l) => clip(l, width));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* "Read 2 files, ran 1 command" — the one line a finished step leaves behind.
|
|
139
|
+
* The order is fixed, so a step always reads the same way.
|
|
140
|
+
*/
|
|
141
|
+
export function summariseStep(counts) {
|
|
142
|
+
const parts = [];
|
|
143
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
144
|
+
const verb = (word) => (parts.length ? word.toLowerCase() : word);
|
|
145
|
+
if (counts.read)
|
|
146
|
+
parts.push(`${verb("Read")} ${plural(counts.read, "file", "files")}`);
|
|
147
|
+
if (counts.list)
|
|
148
|
+
parts.push(`${verb("Listed")} ${plural(counts.list, "directory", "directories")}`);
|
|
149
|
+
if (counts.search)
|
|
150
|
+
parts.push(`${verb("Searched")} ${plural(counts.search, "pattern", "patterns")}`);
|
|
151
|
+
if (counts.inspect)
|
|
152
|
+
parts.push(`${verb("Inspected")} Git ${plural(counts.inspect, "time", "times")}`);
|
|
153
|
+
if (counts.command)
|
|
154
|
+
parts.push(`${verb("Ran")} ${plural(counts.command, "command", "commands")}`);
|
|
155
|
+
if (counts.change)
|
|
156
|
+
parts.push(`${verb("Changed")} ${plural(counts.change, "file", "files")}`);
|
|
157
|
+
if (counts.other)
|
|
158
|
+
parts.push(`${verb("Completed")} ${plural(counts.other, "step", "steps")}`);
|
|
159
|
+
return parts.join(", ");
|
|
160
|
+
}
|
|
161
|
+
export function createRenderer(live) {
|
|
162
|
+
let statusLabel = "";
|
|
163
|
+
let statusSince = Date.now();
|
|
164
|
+
let step = null;
|
|
165
|
+
let command = null;
|
|
166
|
+
let preview = "";
|
|
167
|
+
let paused = false;
|
|
168
|
+
let frame = 0;
|
|
169
|
+
const width = () => Math.max(8, contentWidth() - 4);
|
|
170
|
+
const dot = () => c.accentLight("•");
|
|
171
|
+
const paint = () => {
|
|
172
|
+
if (paused)
|
|
173
|
+
return;
|
|
174
|
+
const lines = [];
|
|
175
|
+
const activity = () => c.accentLight(["·", "•", "◦", "•"][frame++ % 4]) + " ";
|
|
176
|
+
if (command) {
|
|
177
|
+
lines.push(MARGIN + " " + activity() + c.value(clip(command.label, width() - 14)) + c.dim(elapsedLabel(command.since)));
|
|
178
|
+
lines.push(MARGIN + " " + c.dim("└ $ " + clipCommand(command.command, width() - 8)));
|
|
179
|
+
for (const l of command.tail.view(width() - 6))
|
|
180
|
+
lines.push(MARGIN + " " + c.dim(l));
|
|
181
|
+
}
|
|
182
|
+
else if (step && step.running.length) {
|
|
183
|
+
lines.push(MARGIN + " " + activity() + c.value(clip(step.label, width() - 14)) + c.dim(elapsedLabel(step.started)));
|
|
184
|
+
if (step.running.length > 1) {
|
|
185
|
+
for (const [i, label] of step.running.slice(0, 3).entries()) {
|
|
186
|
+
const branch = i === step.running.length - 1 ? "└ " : "├ ";
|
|
187
|
+
lines.push(MARGIN + " " + c.dim(branch + clip(label, width() - 6)));
|
|
188
|
+
}
|
|
189
|
+
if (step.running.length > 3)
|
|
190
|
+
lines.push(MARGIN + " " + c.dim(`+${step.running.length - 3} more`));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (preview) {
|
|
194
|
+
lines.push(MARGIN + dot() + " " + c.dim(clip(preview, width())));
|
|
195
|
+
}
|
|
196
|
+
else if (statusLabel) {
|
|
197
|
+
lines.push(MARGIN + " " + activity() + c.dim(clip(statusLabel, width() - 2)) + c.dim(elapsedLabel(statusSince)));
|
|
198
|
+
}
|
|
199
|
+
live.setStatus(lines);
|
|
200
|
+
};
|
|
201
|
+
// One slow timer: nothing spins, but elapsed time stays honest.
|
|
202
|
+
const timer = setInterval(paint, 500);
|
|
203
|
+
timer.unref?.();
|
|
204
|
+
return {
|
|
205
|
+
user(text) {
|
|
206
|
+
const lines = wrapText(text.trim(), contentWidth() - 3);
|
|
207
|
+
live.commit(["", ...lines.map((l, i) => MARGIN + (i === 0 ? c.brand("›") : " ") + " " + c.title(l)), ""]);
|
|
208
|
+
},
|
|
209
|
+
assistant(text) {
|
|
210
|
+
const md = renderMarkdown(text.trim());
|
|
211
|
+
while (md.length && md[0].trim() === "")
|
|
212
|
+
md.shift();
|
|
213
|
+
while (md.length && md[md.length - 1].trim() === "")
|
|
214
|
+
md.pop();
|
|
215
|
+
if (!md.length)
|
|
216
|
+
return;
|
|
217
|
+
preview = "";
|
|
218
|
+
// The dot marks where a message starts. A message that opens with a list
|
|
219
|
+
// or a heading already has its own marker, so adding one stacks two
|
|
220
|
+
// bullets on the same line — indent the block instead.
|
|
221
|
+
const ownMarker = /^\s*([•\-*•]|\d+[.)]|#)/.test(md[0]);
|
|
222
|
+
live.commit([...md.map((l, i) => MARGIN + (i === 0 && !ownMarker ? dot() + " " : " ") + l), ""]);
|
|
223
|
+
},
|
|
224
|
+
writing(text) {
|
|
225
|
+
preview = text.split("\n").filter((l) => l.trim()).pop() ?? "";
|
|
226
|
+
if (!step && !command)
|
|
227
|
+
paint();
|
|
228
|
+
},
|
|
229
|
+
status(_next, label) {
|
|
230
|
+
if (label !== statusLabel)
|
|
231
|
+
statusSince = Date.now();
|
|
232
|
+
statusLabel = label;
|
|
233
|
+
if (!step && !command)
|
|
234
|
+
paint();
|
|
235
|
+
},
|
|
236
|
+
toolStart(label, kind) {
|
|
237
|
+
if (!step)
|
|
238
|
+
step = { label, started: Date.now(), running: [], kinds: [], counts: blankCounts(), targets: { read: [], search: [], list: [] } };
|
|
239
|
+
step.running.push(label);
|
|
240
|
+
step.kinds.push(kind);
|
|
241
|
+
// One tool at a time reads better as itself than as a group.
|
|
242
|
+
step.label = step.running.length === 1 ? label : "Inspecting repository";
|
|
243
|
+
paint();
|
|
244
|
+
},
|
|
245
|
+
toolEnd(label, kind, summary, ok = true) {
|
|
246
|
+
if (!step)
|
|
247
|
+
return;
|
|
248
|
+
const i = step.running.indexOf(label);
|
|
249
|
+
if (i !== -1) {
|
|
250
|
+
step.running.splice(i, 1);
|
|
251
|
+
const originalKind = step.kinds.splice(i, 1)[0];
|
|
252
|
+
const k = kind ?? originalKind;
|
|
253
|
+
if (ok)
|
|
254
|
+
step.counts[k] += 1;
|
|
255
|
+
// Name what was looked at, so investigation is visible without a line per read.
|
|
256
|
+
if (ok && (k === "read" || k === "search" || k === "list")) {
|
|
257
|
+
const target = stepTarget(label);
|
|
258
|
+
if (target && !step.targets[k].includes(target))
|
|
259
|
+
step.targets[k].push(target);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (step.running.length === 1)
|
|
263
|
+
step.label = step.running[0];
|
|
264
|
+
// A failed tool says so, concisely, right where it happened.
|
|
265
|
+
if (!ok && summary) {
|
|
266
|
+
live.commit([MARGIN + " " + c.err("✕ ") + c.dim(clip(summary, width()))]);
|
|
267
|
+
}
|
|
268
|
+
else if (ok && summary && kind === "inspect") {
|
|
269
|
+
// Git inspections each leave a result line; reads/searches aggregate
|
|
270
|
+
// into the step summary so many small reads stay quiet.
|
|
271
|
+
live.commit([MARGIN + " " + c.ok("✓ ") + c.dim(clip(summary, width()))]);
|
|
272
|
+
}
|
|
273
|
+
paint();
|
|
274
|
+
},
|
|
275
|
+
stepEnd() {
|
|
276
|
+
if (!step)
|
|
277
|
+
return;
|
|
278
|
+
// Inspections already left their own ✓ lines; the aggregate is the reads
|
|
279
|
+
// and searches that were kept quiet during the step.
|
|
280
|
+
const summary = summariseStep({ ...step.counts, inspect: 0, command: 0, change: 0, other: 0 });
|
|
281
|
+
const took = elapsedLabel(step.started);
|
|
282
|
+
const hadInspect = step.counts.inspect > 0;
|
|
283
|
+
const targets = step.targets;
|
|
284
|
+
const counts = step.counts;
|
|
285
|
+
step = null;
|
|
286
|
+
if (summary)
|
|
287
|
+
live.commit([...investigationBlock(counts, targets, took, width()), ""]);
|
|
288
|
+
else if (hadInspect)
|
|
289
|
+
live.commit([""]); // spacer after the ✓ inspection lines
|
|
290
|
+
paint();
|
|
291
|
+
},
|
|
292
|
+
commit(lines) {
|
|
293
|
+
live.commit(lines);
|
|
294
|
+
},
|
|
295
|
+
async borrow(fn) {
|
|
296
|
+
paused = true;
|
|
297
|
+
live.setStatus([]);
|
|
298
|
+
try {
|
|
299
|
+
return await fn();
|
|
300
|
+
}
|
|
301
|
+
finally {
|
|
302
|
+
paused = false;
|
|
303
|
+
paint();
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
commandStarted(label, cmd) {
|
|
307
|
+
command = { label, command: cmd, since: Date.now(), tail: new OutputTail(5, true) };
|
|
308
|
+
paint();
|
|
309
|
+
},
|
|
310
|
+
commandOutput(text) {
|
|
311
|
+
command?.tail.push(text);
|
|
312
|
+
},
|
|
313
|
+
commandEnded() {
|
|
314
|
+
command = null;
|
|
315
|
+
paint();
|
|
316
|
+
},
|
|
317
|
+
clear() {
|
|
318
|
+
step = null;
|
|
319
|
+
command = null;
|
|
320
|
+
preview = "";
|
|
321
|
+
statusLabel = "";
|
|
322
|
+
live.setStatus([]);
|
|
323
|
+
},
|
|
324
|
+
stop() {
|
|
325
|
+
clearInterval(timer);
|
|
326
|
+
live.setStatus([]);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The grouped record of what a step read, searched and listed: one heading and
|
|
332
|
+
* a row per kind, each naming its targets (paths and queries only — never model
|
|
333
|
+
* text). Rows are clipped to the terminal; the full list is the tool record.
|
|
334
|
+
*/
|
|
335
|
+
function investigationBlock(counts, targets, took, width) {
|
|
336
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
337
|
+
const named = (list) => (list.length ? " · " + list.slice(0, 4).join(", ") + (list.length > 4 ? `, +${list.length - 4} more` : "") : "");
|
|
338
|
+
// Phases in the order an investigation runs, each present only when a tool
|
|
339
|
+
// of that kind actually ran — never inferred from model text.
|
|
340
|
+
const rows = [
|
|
341
|
+
[counts.list + counts.inspect > 0, "Inspecting repository structure", named(targets.list)],
|
|
342
|
+
[counts.search > 0, "Searching for related code", named(targets.search)],
|
|
343
|
+
[counts.read > 0, `Reading relevant files (${plural(counts.read, "file", "files")})`, named(targets.read)]
|
|
344
|
+
];
|
|
345
|
+
return [
|
|
346
|
+
MARGIN + c.title("Agent investigation") + c.dim(took),
|
|
347
|
+
...rows.filter(([ran]) => ran).map(([, text, list]) => MARGIN + " " + c.ok("✓ ") + c.value(clip(text, width - 4)) + c.dim(clip(list, Math.max(0, width - 6 - visibleWidth(text)))))
|
|
348
|
+
];
|
|
349
|
+
}
|
|
350
|
+
/** "Reading src/a.ts" → "src/a.ts"; a label with no target names nothing. */
|
|
351
|
+
function stepTarget(label) {
|
|
352
|
+
const m = stripControl(label).match(/^(?:Reading|Searching|Finding files|Finding file|Finding definition|Finding usages|Outlining|Inspecting repository|Listing)\s+(.+)$/);
|
|
353
|
+
const target = m ? m[1].trim().slice(0, 80) : "";
|
|
354
|
+
// Generic activity words name nothing the user could look at.
|
|
355
|
+
return /^(project files|the project|repository|files)$/i.test(target) ? "" : target;
|
|
356
|
+
}
|
|
357
|
+
function blankCounts() {
|
|
358
|
+
return { read: 0, list: 0, search: 0, inspect: 0, command: 0, change: 0, other: 0 };
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* The compact result line for one completed tool, or undefined when the step's
|
|
362
|
+
* aggregate should speak for it instead.
|
|
363
|
+
*
|
|
364
|
+
* Reads and searches return undefined on success — they are summed into the
|
|
365
|
+
* step line ("Read 3 files") rather than printed one by one. Git inspections
|
|
366
|
+
* return a real one-liner. Any failure returns a concise reason, so a broken
|
|
367
|
+
* tool reads as "✕ git_diff failed · <reason>" instead of a stack trace.
|
|
368
|
+
*
|
|
369
|
+
* `detail` is the tool's result object on success, or an error message string
|
|
370
|
+
* on failure. Nothing here exposes protocol fields.
|
|
371
|
+
*/
|
|
372
|
+
export function toolSummary(name, ok, detail) {
|
|
373
|
+
if (!ok) {
|
|
374
|
+
const reason = typeof detail === "string" && detail.trim() ? ` · ${detail.trim()}` : "";
|
|
375
|
+
return `${name} failed${reason}`;
|
|
376
|
+
}
|
|
377
|
+
const r = (detail ?? {});
|
|
378
|
+
const n = (v) => (typeof v === "number" && Number.isFinite(v) ? v : 0);
|
|
379
|
+
const arr = (v) => (Array.isArray(v) ? v.length : 0);
|
|
380
|
+
if (name === "resolve_local_file") {
|
|
381
|
+
if (r.status === "resolved")
|
|
382
|
+
return `Resolved → ${r.repository}/${r.path}`;
|
|
383
|
+
if (r.status === "ambiguous")
|
|
384
|
+
return `${Array.isArray(r.candidates) ? r.candidates.length : 0} matching files — pick one`;
|
|
385
|
+
if (r.status === "not_found")
|
|
386
|
+
return "no match found";
|
|
387
|
+
return "resolve_local_file";
|
|
388
|
+
}
|
|
389
|
+
if (name === "git_status") {
|
|
390
|
+
if (r.clean === true)
|
|
391
|
+
return `git_status · clean${r.branch ? ` · branch ${r.branch}` : ""}`;
|
|
392
|
+
const parts = [];
|
|
393
|
+
const modified = arr(r.staged) + arr(r.unstaged);
|
|
394
|
+
if (modified)
|
|
395
|
+
parts.push(`${modified} modified`);
|
|
396
|
+
if (arr(r.untracked))
|
|
397
|
+
parts.push(`${arr(r.untracked)} untracked`);
|
|
398
|
+
if (r.branch)
|
|
399
|
+
parts.push(`branch ${r.branch}`);
|
|
400
|
+
else if (r.detached)
|
|
401
|
+
parts.push(`detached ${r.head ?? ""}`.trim());
|
|
402
|
+
return `git_status · ${parts.join(" · ")}`;
|
|
403
|
+
}
|
|
404
|
+
if (name === "git_diff") {
|
|
405
|
+
if (n(r.files_changed) === 0)
|
|
406
|
+
return "git_diff · no changes";
|
|
407
|
+
return `git_diff · ${n(r.files_changed)} ${n(r.files_changed) === 1 ? "file" : "files"} · +${n(r.additions)} −${n(r.deletions)}`;
|
|
408
|
+
}
|
|
409
|
+
if (name === "git_log")
|
|
410
|
+
return `git_log · ${arr(r.commits)} ${arr(r.commits) === 1 ? "commit" : "commits"}${r.path ? ` · ${r.path}` : ""}`;
|
|
411
|
+
if (name === "git_blame")
|
|
412
|
+
return `git_blame · ${r.path ?? ""} lines ${n(r.start_line)}–${n(r.end_line)}`;
|
|
413
|
+
if (name === "git_show")
|
|
414
|
+
return `git_show · ${r.short ?? ""} ${typeof r.subject === "string" ? r.subject.slice(0, 60) : ""}`.trimEnd();
|
|
415
|
+
// read_file / list_files / find_files / search_files are aggregated by the step summary.
|
|
416
|
+
return undefined;
|
|
417
|
+
}
|
|
418
|
+
/** The kind of activity a tool name represents, for the step summary. */
|
|
419
|
+
export function toolKind(name) {
|
|
420
|
+
switch (name) {
|
|
421
|
+
case "read_file":
|
|
422
|
+
return "read";
|
|
423
|
+
case "list_files":
|
|
424
|
+
return "list";
|
|
425
|
+
case "find_files":
|
|
426
|
+
case "search_files":
|
|
427
|
+
case "find_symbol":
|
|
428
|
+
case "find_references":
|
|
429
|
+
return "search";
|
|
430
|
+
case "code_outline":
|
|
431
|
+
return "read";
|
|
432
|
+
case "resolve_local_file":
|
|
433
|
+
case "git_status":
|
|
434
|
+
case "git_diff":
|
|
435
|
+
case "git_log":
|
|
436
|
+
case "git_blame":
|
|
437
|
+
case "git_show":
|
|
438
|
+
return "inspect";
|
|
439
|
+
case "run_command":
|
|
440
|
+
return "command";
|
|
441
|
+
case "create_file":
|
|
442
|
+
case "write_file":
|
|
443
|
+
case "edit_file":
|
|
444
|
+
case "delete_file":
|
|
445
|
+
case "revert_change":
|
|
446
|
+
return "change";
|
|
447
|
+
default:
|
|
448
|
+
return "other";
|
|
449
|
+
}
|
|
450
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ctrl+C while a turn is in flight.
|
|
3
|
+
*
|
|
4
|
+
* Between prompts the terminal is deliberately left in RAW mode (see the setup
|
|
5
|
+
* note in command-palette.ts), and the composer removes its `keypress` listener
|
|
6
|
+
* as soon as it hands the line back. Raw mode means the tty does not raise
|
|
7
|
+
* SIGINT, so during a request Ctrl+C arrives as a bare 0x03 byte with nothing
|
|
8
|
+
* listening — which is why it currently does nothing at all.
|
|
9
|
+
*
|
|
10
|
+
* This attaches a listener for exactly that byte, for exactly as long as the
|
|
11
|
+
* request is running, and detaches it again so the composer's own Ctrl+C
|
|
12
|
+
* (arm-then-exit) behaviour is untouched.
|
|
13
|
+
*/
|
|
14
|
+
export function watchForInterrupt(onAbort) {
|
|
15
|
+
const stdin = process.stdin;
|
|
16
|
+
if (!stdin.isTTY)
|
|
17
|
+
return () => undefined;
|
|
18
|
+
let done = false;
|
|
19
|
+
const cleanup = () => {
|
|
20
|
+
if (done)
|
|
21
|
+
return;
|
|
22
|
+
done = true;
|
|
23
|
+
stdin.removeListener("data", onData);
|
|
24
|
+
};
|
|
25
|
+
function onData(chunk) {
|
|
26
|
+
const buf = typeof chunk === "string" ? Buffer.from(chunk, "utf8") : chunk;
|
|
27
|
+
// 0x03 = ETX, what Ctrl+C sends in raw mode.
|
|
28
|
+
if (buf.includes(0x03)) {
|
|
29
|
+
cleanup();
|
|
30
|
+
onAbort();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
stdin.on("data", onData);
|
|
34
|
+
return cleanup;
|
|
35
|
+
}
|
package/dist/ui/live.js
CHANGED
|
@@ -28,11 +28,13 @@ export function startLiveComposer(footer = "") {
|
|
|
28
28
|
stop: () => screenTransient([])
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
if (!stdout.isTTY)
|
|
31
|
+
if (!stdout.isTTY || process.env.TERM === "dumb")
|
|
32
32
|
return passthrough;
|
|
33
33
|
let status = [];
|
|
34
34
|
let shown = []; // the transient region currently on screen (status + bar)
|
|
35
|
-
|
|
35
|
+
// SGR colour runs plus OSC strings — an OSC payload occupies no columns, so
|
|
36
|
+
// stripping only SGR would over-count the width of any line carrying one.
|
|
37
|
+
const ANSI = /\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b\[[0-9;]*m/g;
|
|
36
38
|
// Full row width (margin + fixed content column) — used only to pad rows so an
|
|
37
39
|
// overwrite fully covers the previous content; the composer itself is fixed.
|
|
38
40
|
const width = () => MARGIN.length + contentWidth() + 1;
|
package/dist/ui/markdown.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { c } from "./colors.js";
|
|
3
3
|
import { renderCodeBlock } from "./code-block.js";
|
|
4
|
-
import { textWidth } from "./composer-layout.js";
|
|
4
|
+
import { clampAnsi, contentWidth, MARGIN, textWidth } from "./composer-layout.js";
|
|
5
5
|
/**
|
|
6
6
|
* Self-contained Markdown → ANSI renderer (no dependency). Supports headings,
|
|
7
7
|
* bold/italic, inline code, links, bullet/numbered/task lists, blockquotes,
|
|
8
8
|
* horizontal rules, tables and fenced code blocks — with soft word-wrap so long
|
|
9
9
|
* paragraphs never overflow or cut words. Returns col-0 lines; callers indent.
|
|
10
10
|
*/
|
|
11
|
-
export function renderMarkdown(md) {
|
|
12
|
-
|
|
11
|
+
export function renderMarkdown(md, maxWidth) {
|
|
12
|
+
// `maxWidth` lets a caller render into something narrower than the transcript
|
|
13
|
+
// — the /btw box, which spends 4 columns on its own borders. Without it the
|
|
14
|
+
// body would wrap to the full width and overflow the frame it sits in.
|
|
15
|
+
const wrap = Math.max(20, (maxWidth ?? textWidth()) - 4);
|
|
13
16
|
const out = [];
|
|
14
17
|
const lines = md.replace(/\r/g, "").split("\n");
|
|
15
18
|
let i = 0;
|
|
@@ -44,10 +47,12 @@ export function renderMarkdown(md) {
|
|
|
44
47
|
i++;
|
|
45
48
|
continue;
|
|
46
49
|
}
|
|
47
|
-
// Heading.
|
|
50
|
+
// Heading — wrapped like body text; a long one would otherwise overflow.
|
|
48
51
|
const h = raw.match(/^(#{1,6})\s+(.*)$/);
|
|
49
52
|
if (h) {
|
|
50
|
-
|
|
53
|
+
const paint = h[1].length === 1 ? c.brand : c.title;
|
|
54
|
+
for (const w of wrapText(h[2], wrap))
|
|
55
|
+
out.push(paint(inline(w)));
|
|
51
56
|
i++;
|
|
52
57
|
continue;
|
|
53
58
|
}
|
|
@@ -102,9 +107,24 @@ export function renderMarkdown(md) {
|
|
|
102
107
|
out.push(inline(w));
|
|
103
108
|
i++;
|
|
104
109
|
}
|
|
105
|
-
|
|
110
|
+
// Backstop. Code blocks and tables size themselves from their content, and a
|
|
111
|
+
// future block type could forget to wrap entirely — any of which would emit a
|
|
112
|
+
// line wider than the terminal and corrupt the pinned composer. Callers indent
|
|
113
|
+
// by MARGIN, so leave room for it.
|
|
114
|
+
const limit = Math.max(20, contentWidth() - MARGIN.length);
|
|
115
|
+
return out.map((l) => clampAnsi(l, limit));
|
|
106
116
|
}
|
|
107
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Word-wrap plain text to `width`, never cutting a word — EXCEPT a word that
|
|
119
|
+
* cannot fit on a line of its own.
|
|
120
|
+
*
|
|
121
|
+
* A 250-character URL, hash or base64 blob has no break point, so pure
|
|
122
|
+
* word-wrapping emits it as one over-wide line. The terminal then wraps it into
|
|
123
|
+
* several physical rows while the screen engine still counts one, and the
|
|
124
|
+
* pinned composer below gets overwritten. Splitting such a token across lines
|
|
125
|
+
* keeps every character (nothing is lost, unlike clipping) while holding the
|
|
126
|
+
* one-line-per-row invariant everything else depends on.
|
|
127
|
+
*/
|
|
108
128
|
function wrapText(text, width) {
|
|
109
129
|
const w = Math.max(20, width);
|
|
110
130
|
const words = text.trim().split(/\s+/).filter(Boolean);
|
|
@@ -113,7 +133,18 @@ function wrapText(text, width) {
|
|
|
113
133
|
const lines = [];
|
|
114
134
|
let cur = "";
|
|
115
135
|
for (const word of words) {
|
|
116
|
-
|
|
136
|
+
const len = [...word].length;
|
|
137
|
+
if (len > w) {
|
|
138
|
+
if (cur) {
|
|
139
|
+
lines.push(cur);
|
|
140
|
+
cur = "";
|
|
141
|
+
}
|
|
142
|
+
const chars = [...word];
|
|
143
|
+
for (let i = 0; i < chars.length; i += w)
|
|
144
|
+
lines.push(chars.slice(i, i + w).join(""));
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (cur && [...cur].length + 1 + len > w) {
|
|
117
148
|
lines.push(cur);
|
|
118
149
|
cur = word;
|
|
119
150
|
}
|
|
@@ -125,12 +156,35 @@ function wrapText(text, width) {
|
|
|
125
156
|
lines.push(cur);
|
|
126
157
|
return lines;
|
|
127
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* A code-review severity, coloured by weight. A review's findings arrive as
|
|
161
|
+
* bold headers like `**High — \`src/x.js:12\`**`; recognising the leading
|
|
162
|
+
* severity word lets the terminal show it as a subtle marker (red for the
|
|
163
|
+
* serious ones, dim for the quiet ones) instead of undifferentiated bold. It is
|
|
164
|
+
* deliberately narrow — only a bold segment that STARTS with one of these five
|
|
165
|
+
* words is touched, so ordinary bold text is unaffected.
|
|
166
|
+
*/
|
|
167
|
+
const SEVERITY_COLOR = {
|
|
168
|
+
critical: c.err,
|
|
169
|
+
high: c.err,
|
|
170
|
+
medium: c.warn,
|
|
171
|
+
low: c.dim,
|
|
172
|
+
info: c.accent
|
|
173
|
+
};
|
|
174
|
+
function styleBold(b) {
|
|
175
|
+
const m = b.match(/^(critical|high|medium|low|info)\b(.*)$/i);
|
|
176
|
+
if (m) {
|
|
177
|
+
const paint = SEVERITY_COLOR[m[1].toLowerCase()];
|
|
178
|
+
return chalk.bold(paint(m[1].toUpperCase())) + chalk.bold(m[2]);
|
|
179
|
+
}
|
|
180
|
+
return chalk.bold(b);
|
|
181
|
+
}
|
|
128
182
|
/** Inline spans: links, `code`, **bold**, *italic*, ~~strike~~. */
|
|
129
183
|
function inline(text) {
|
|
130
184
|
return text
|
|
131
185
|
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, label) => c.accent(label))
|
|
132
186
|
.replace(/`([^`]+)`/g, (_m, code) => c.accent(code))
|
|
133
|
-
.replace(/\*\*([^*]+)\*\*/g, (_m, b) =>
|
|
187
|
+
.replace(/\*\*([^*]+)\*\*/g, (_m, b) => styleBold(b))
|
|
134
188
|
.replace(/~~([^~]+)~~/g, (_m, s) => chalk.strikethrough(s))
|
|
135
189
|
.replace(/(^|[^*])\*([^*]+)\*/g, (_m, pre, it) => `${pre}${chalk.italic(it)}`);
|
|
136
190
|
}
|
package/dist/ui/message.js
CHANGED
|
@@ -1,38 +1,21 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
1
|
import { line } from "../services/output.js";
|
|
2
|
+
import { c } from "./colors.js";
|
|
3
3
|
import { MARGIN, contentWidth } from "./composer-layout.js";
|
|
4
|
+
import { wrapText } from "./conversation.js";
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* A user turn: the accent caret the composer uses, then the message.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately light. This used to be a full-width shaded band, which made
|
|
9
|
+
* every question look like a UI panel and gave the eye something heavier than
|
|
10
|
+
* the answer below it. The caret alone is enough to say "you said this", and it
|
|
11
|
+
* matches what the composer shows while typing, so a sent message reads as the
|
|
12
|
+
* same thing it was a moment ago.
|
|
8
13
|
*/
|
|
9
|
-
const BAR_BG = "#2b2b2e";
|
|
10
14
|
export function renderUserMessage(text) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
for (const [i, l] of
|
|
14
|
-
|
|
15
|
-
line(MARGIN + bar(content.padEnd(w)));
|
|
15
|
+
const lines = wrapText(text.trim(), contentWidth() - 3);
|
|
16
|
+
line();
|
|
17
|
+
for (const [i, l] of lines.entries()) {
|
|
18
|
+
line(MARGIN + (i === 0 ? c.brandFixed("›") : " ") + " " + c.title(l));
|
|
16
19
|
}
|
|
17
|
-
line();
|
|
18
|
-
}
|
|
19
|
-
function wrap(text, width) {
|
|
20
|
-
const w = Math.max(20, width);
|
|
21
|
-
const words = text.trim().split(/\s+/).filter(Boolean);
|
|
22
|
-
if (!words.length)
|
|
23
|
-
return [""];
|
|
24
|
-
const lines = [];
|
|
25
|
-
let cur = "";
|
|
26
|
-
for (const word of words) {
|
|
27
|
-
if (cur && [...cur].length + 1 + [...word].length > w) {
|
|
28
|
-
lines.push(cur);
|
|
29
|
-
cur = word;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
cur = cur ? `${cur} ${word}` : word;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (cur)
|
|
36
|
-
lines.push(cur);
|
|
37
|
-
return lines;
|
|
20
|
+
line();
|
|
38
21
|
}
|