@carrieros/cli-staging 0.0.0-stage → 0.4.1

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.
Files changed (137) hide show
  1. package/README.md +6 -2
  2. package/dist/commands/attach.js +45 -0
  3. package/dist/commands/auth.js +60 -0
  4. package/dist/commands/btw.js +78 -0
  5. package/dist/commands/changes.js +167 -0
  6. package/dist/commands/chat.js +182 -0
  7. package/dist/commands/context.js +200 -0
  8. package/dist/commands/doctor.js +119 -0
  9. package/dist/commands/files.js +94 -0
  10. package/dist/commands/help.js +37 -0
  11. package/dist/commands/history.js +112 -0
  12. package/dist/commands/login.js +62 -0
  13. package/dist/commands/logout.js +26 -0
  14. package/dist/commands/memory.js +162 -0
  15. package/dist/commands/mode-model.js +64 -0
  16. package/dist/commands/models.js +28 -0
  17. package/dist/commands/modes.js +30 -0
  18. package/dist/commands/permissions.js +78 -0
  19. package/dist/commands/project.js +106 -0
  20. package/dist/commands/repo.js +146 -0
  21. package/dist/commands/repos.js +61 -0
  22. package/dist/commands/review.js +92 -0
  23. package/dist/commands/scope.js +155 -0
  24. package/dist/commands/search.js +92 -0
  25. package/dist/commands/sessions.js +282 -0
  26. package/dist/commands/settings.js +160 -0
  27. package/dist/commands/update.js +285 -0
  28. package/dist/commands/upload.js +223 -0
  29. package/dist/commands/usage.js +229 -0
  30. package/dist/commands/version.js +26 -0
  31. package/dist/commands/whoami.js +44 -0
  32. package/dist/ide/editor-context.js +275 -0
  33. package/dist/ide/ide-session.js +364 -0
  34. package/dist/ide/tool-host.js +109 -0
  35. package/dist/main.js +132 -0
  36. package/dist/services/api.js +441 -0
  37. package/dist/services/auth-origin.js +20 -0
  38. package/dist/services/auto-update.js +221 -0
  39. package/dist/services/chat-stream.js +168 -0
  40. package/dist/services/checkpoints.js +278 -0
  41. package/dist/services/client-tools.js +356 -0
  42. package/dist/services/code-intel.js +243 -0
  43. package/dist/services/code-symbols.js +94 -0
  44. package/dist/services/coding-workflow.js +554 -0
  45. package/dist/services/command-coordinator.js +273 -0
  46. package/dist/services/command-policy.js +434 -0
  47. package/dist/services/config.js +384 -0
  48. package/dist/services/container-runner.js +254 -0
  49. package/dist/services/container-supervisor.js +38 -0
  50. package/dist/services/context.js +416 -0
  51. package/dist/services/device-auth.js +288 -0
  52. package/dist/services/diff.js +196 -0
  53. package/dist/services/env-policy.js +108 -0
  54. package/dist/services/execution-platform.js +30 -0
  55. package/dist/services/file-detect.js +104 -0
  56. package/dist/services/file-resolver.js +199 -0
  57. package/dist/services/file-upload.js +126 -0
  58. package/dist/services/folder-key.js +22 -0
  59. package/dist/services/git-tools.js +429 -0
  60. package/dist/services/glob-match.js +164 -0
  61. package/dist/services/helper-bin.js +85 -0
  62. package/dist/services/ignore-rules.js +189 -0
  63. package/dist/services/instruction-resolver.js +54 -0
  64. package/dist/services/job-helper.js +328 -0
  65. package/dist/services/local-files.js +639 -0
  66. package/dist/services/local-tools.js +937 -0
  67. package/dist/services/login-flow.js +156 -0
  68. package/dist/services/meta.js +42 -0
  69. package/dist/services/mutation-coordinator.js +327 -0
  70. package/dist/services/mutation-groups.js +309 -0
  71. package/dist/services/mutation-recovery.js +159 -0
  72. package/dist/services/mutations.js +679 -0
  73. package/dist/services/open-url.js +68 -0
  74. package/dist/services/output.js +62 -0
  75. package/dist/services/packaged-update.js +403 -0
  76. package/dist/services/packaged.js +39 -0
  77. package/dist/services/permission-mode.js +78 -0
  78. package/dist/services/process-runner.js +412 -0
  79. package/dist/services/project-context.js +298 -0
  80. package/dist/services/redaction.js +201 -0
  81. package/dist/services/result-reconciliation.js +49 -0
  82. package/dist/services/secure-store.js +217 -0
  83. package/dist/services/session-resolver.js +115 -0
  84. package/dist/services/sia.js +51 -0
  85. package/dist/services/spinner.js +40 -0
  86. package/dist/services/supported-runtime.js +59 -0
  87. package/dist/services/task-context.js +212 -0
  88. package/dist/services/task-snapshot.js +38 -0
  89. package/dist/services/tool-result-outbox.js +195 -0
  90. package/dist/services/update.js +730 -0
  91. package/dist/services/workspace-registry.js +310 -0
  92. package/dist/services/workspace.js +580 -0
  93. package/dist/shell/shell-chat.js +1622 -0
  94. package/dist/shell/shell-commands.js +411 -0
  95. package/dist/shell/shell-prompt.js +110 -0
  96. package/dist/shell/shell-renderer.js +51 -0
  97. package/dist/shell/shell-router.js +37 -0
  98. package/dist/shell/shell.js +414 -0
  99. package/dist/shell/task-context-view.js +40 -0
  100. package/dist/staging.js +5 -0
  101. package/dist/types/index.js +6 -0
  102. package/dist/ui/agent-cards.js +111 -0
  103. package/dist/ui/agent-presentation.js +131 -0
  104. package/dist/ui/approval.js +111 -0
  105. package/dist/ui/banner.js +56 -0
  106. package/dist/ui/btw-overlay.js +230 -0
  107. package/dist/ui/change-review.js +334 -0
  108. package/dist/ui/chat-renderer.js +463 -0
  109. package/dist/ui/code-block.js +52 -0
  110. package/dist/ui/color-picker.js +100 -0
  111. package/dist/ui/colors.js +55 -0
  112. package/dist/ui/command-details.js +11 -0
  113. package/dist/ui/command-filter.js +92 -0
  114. package/dist/ui/command-item.js +6 -0
  115. package/dist/ui/command-palette.js +383 -0
  116. package/dist/ui/command-registry.js +128 -0
  117. package/dist/ui/command-renderer.js +55 -0
  118. package/dist/ui/command-review.js +187 -0
  119. package/dist/ui/composer-layout.js +74 -0
  120. package/dist/ui/conversation.js +450 -0
  121. package/dist/ui/interrupt.js +35 -0
  122. package/dist/ui/live.js +141 -0
  123. package/dist/ui/logo.js +58 -0
  124. package/dist/ui/markdown.js +205 -0
  125. package/dist/ui/message.js +21 -0
  126. package/dist/ui/screen-prompt.js +181 -0
  127. package/dist/ui/screen.js +297 -0
  128. package/dist/ui/select.js +284 -0
  129. package/dist/ui/sia-qa.js +213 -0
  130. package/dist/ui/spinner.js +23 -0
  131. package/dist/ui/sticky-stream.js +64 -0
  132. package/dist/ui/task-context-card.js +99 -0
  133. package/dist/ui/text-prompt.js +74 -0
  134. package/dist/ui/theme.js +80 -0
  135. package/dist/ui/trust.js +88 -0
  136. package/dist/ui/ui.js +101 -0
  137. package/package.json +33 -4
@@ -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
+ }
@@ -0,0 +1,141 @@
1
+ import * as readline from "node:readline";
2
+ import { c } from "./colors.js";
3
+ import { MARGIN, contentWidth } from "./composer-layout.js";
4
+ import { screenActive, screenCommitTransient, screenPrint, screenTransient } from "./screen.js";
5
+ /** Non-TTY fallback: commits print normally, the bar/status are no-ops. */
6
+ const passthrough = {
7
+ setStatus: () => { },
8
+ commitStatus: () => { },
9
+ commit: (lines) => {
10
+ if (lines.length)
11
+ process.stdout.write(lines.join("\n") + "\n");
12
+ },
13
+ stop: () => { }
14
+ };
15
+ export function startLiveComposer(footer = "") {
16
+ const stdout = process.stdout;
17
+ // In the persistent-composer shell the screen engine owns the input bar, so a
18
+ // live turn just streams into the transcript above it: transient lines (spinner
19
+ // / word-by-word reveal) go to the transient tail; finished lines are committed.
20
+ if (screenActive()) {
21
+ return {
22
+ setStatus: (lines) => screenTransient(lines),
23
+ commitStatus: () => screenCommitTransient(),
24
+ commit: (lines) => {
25
+ if (lines.length)
26
+ screenPrint(lines);
27
+ },
28
+ stop: () => screenTransient([])
29
+ };
30
+ }
31
+ if (!stdout.isTTY || process.env.TERM === "dumb")
32
+ return passthrough;
33
+ let status = [];
34
+ let shown = []; // the transient region currently on screen (status + bar)
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;
38
+ // Full row width (margin + fixed content column) — used only to pad rows so an
39
+ // overwrite fully covers the previous content; the composer itself is fixed.
40
+ const width = () => MARGIN.length + contentWidth() + 1;
41
+ const pad = (s) => {
42
+ const vis = s.replace(ANSI, "").length;
43
+ const w = width();
44
+ return vis >= w ? s : s + " ".repeat(w - vis);
45
+ };
46
+ const barLines = () => {
47
+ const inner = contentWidth();
48
+ const rule = MARGIN + c.rule("─".repeat(inner));
49
+ const prompt = MARGIN + c.brand("❯") + " " + " ".repeat(Math.max(0, inner - 2));
50
+ return footer ? [rule, prompt, rule, footer] : [rule, prompt, rule];
51
+ };
52
+ const region = () => [...status, ...barLines()];
53
+ // Move the cursor from the bottom of the current region up to its top row.
54
+ const toTop = () => {
55
+ const bottom = Math.max(0, shown.length - 1);
56
+ if (bottom > 0)
57
+ readline.moveCursor(stdout, 0, -bottom);
58
+ readline.cursorTo(stdout, 0);
59
+ };
60
+ // In-place, line-diffed repaint. Only rewrites lines that changed, and writes
61
+ // each row padded to full width so the new content OVERWRITES the old with no
62
+ // intermediate clear — no blank flash, so no flicker. Navigation uses relative
63
+ // cursor moves (existing rows), never "\n", so nothing scrolls.
64
+ const repaint = () => {
65
+ const next = region();
66
+ toTop();
67
+ const n = Math.max(next.length, shown.length);
68
+ for (let i = 0; i < n; i++) {
69
+ readline.cursorTo(stdout, 0);
70
+ if (i >= next.length) {
71
+ stdout.write(pad("")); // blank a now-removed row (full-width spaces)
72
+ }
73
+ else if (next[i] !== shown[i]) {
74
+ stdout.write(pad(next[i]));
75
+ }
76
+ if (i < n - 1)
77
+ readline.moveCursor(stdout, 0, 1);
78
+ }
79
+ // Park the cursor at the bottom row of the new region.
80
+ const cur = n - 1;
81
+ const bottom = Math.max(0, next.length - 1);
82
+ if (cur > bottom)
83
+ readline.moveCursor(stdout, 0, -(cur - bottom));
84
+ readline.cursorTo(stdout, 0);
85
+ shown = next;
86
+ };
87
+ // Print permanent lines above the bar, then redraw the region beneath them.
88
+ // Full-width overwrites (no clears) + "\n" so growth scrolls into history.
89
+ const commit = (committed) => {
90
+ toTop();
91
+ const next = region();
92
+ const block = [...committed, ...next];
93
+ for (let i = 0; i < block.length; i++) {
94
+ readline.cursorTo(stdout, 0);
95
+ stdout.write(pad(block[i]));
96
+ if (i < block.length - 1)
97
+ stdout.write("\n");
98
+ }
99
+ // If the previous region was taller than the block, blank the leftover rows.
100
+ const extra = shown.length - block.length;
101
+ for (let k = 0; k < extra; k++) {
102
+ stdout.write("\n");
103
+ readline.cursorTo(stdout, 0);
104
+ stdout.write(pad(""));
105
+ }
106
+ if (extra > 0)
107
+ readline.moveCursor(stdout, 0, -extra);
108
+ shown = next;
109
+ };
110
+ // Hide the real cursor while the region redraws — otherwise it visibly
111
+ // flickers as it jumps between the spinner and the bar on every frame.
112
+ stdout.write("\x1b[?25l");
113
+ // Initial draw.
114
+ stdout.write(region().join("\n"));
115
+ shown = region();
116
+ return {
117
+ setStatus: (lines) => {
118
+ status = lines;
119
+ // Same height → in-place diff (flicker-free spinner frames). Height change
120
+ // (spinner appearing/clearing) → scroll-safe redraw via commit([]).
121
+ if (region().length === shown.length)
122
+ repaint();
123
+ else
124
+ commit([]);
125
+ },
126
+ commitStatus: () => {
127
+ // The status lines are already drawn where they'll stay; re-emit them as
128
+ // committed (with an empty status) so the on-screen result is identical.
129
+ const promoted = status;
130
+ status = [];
131
+ commit(promoted);
132
+ },
133
+ commit,
134
+ stop: () => {
135
+ toTop();
136
+ readline.clearScreenDown(stdout);
137
+ stdout.write("\x1b[?25h"); // restore the cursor for the interactive reader
138
+ shown = [];
139
+ }
140
+ };
141
+ }
@@ -0,0 +1,58 @@
1
+ // Terminal-native Carrier OS logo — pure Unicode + block-drawing characters,
2
+ // no images / sixel / iTerm protocol. Coloring is applied in ui/banner.ts via
3
+ // ui/colors.ts; these are stored plain so they stay portable and testable.
4
+ /** Neural-network node mark (rendered in bright green). */
5
+ export const NEURAL_NODE = ` ◉
6
+ ╱──┼──╲
7
+ ◉───●───◉
8
+ ╲──┼──╱
9
+ ◉`;
10
+ /**
11
+ * A decorative "neural constellation" scene shown above the wordmark — glowing
12
+ * nodes wired into a small network amongst a scattering of stars, framed by a
13
+ * dotted rule. Carrier's own take on a premium welcome scene.
14
+ */
15
+ export const SCENE = [
16
+ "· · · · · · · · · · · · · · · · · · · · · · · · · · ·",
17
+ " ✦ · ◦ ·",
18
+ " ◉───────────●───────────◉ ·",
19
+ " ╲ ╱ ╲ ╱ ✦",
20
+ " · ●───────◉ ◉───────● ◦",
21
+ " ╱ ╲ ╱ ╲ ·",
22
+ " ◉───────────●───────────◉ ✦",
23
+ " · ✦ ◦",
24
+ "· · · · · · · · · · · · · · · · · · · · · · · · · · ·"
25
+ ].join("\n");
26
+ // The "CARRIER OS" wordmark, composed letter-by-letter so we can control the gap
27
+ // between glyphs (the packed font ran them together). A space glyph gives a wider
28
+ // word break between CARRIER and OS.
29
+ const GLYPHS = {
30
+ C: [" ██████╗", "██╔════╝", "██║ ", "██║ ", "╚██████╗", " ╚═════╝"],
31
+ A: [" █████╗ ", "██╔══██╗", "███████║", "██╔══██║", "██║ ██║", "╚═╝ ╚═╝"],
32
+ R: ["██████╗ ", "██╔══██╗", "██████╔╝", "██╔══██╗", "██║ ╚██╗", "╚═╝ ╚═╝"],
33
+ I: ["██╗", "██║", "██║", "██║", "██║", "╚═╝"],
34
+ E: ["███████╗", "██╔════╝", "█████╗ ", "██╔══╝ ", "███████╗", "╚══════╝"],
35
+ O: [" ██████╗ ", "██╔═══██╗", "██║ ██║", "██║ ██║", "╚██████╔╝", " ╚═════╝ "],
36
+ S: ["███████╗", "██╔════╝", "███████╗", "╚════██║", "███████║", "╚══════╝"],
37
+ " ": [" ", " ", " ", " ", " ", " "]
38
+ };
39
+ // A gentle forward-lean (italic) shear applied per row, top → bottom. Upper rows
40
+ // shift right so each letter slants slightly, like an italic wordmark.
41
+ const SHEAR = [1, 1, 1, 0, 0, 0];
42
+ /** Skew a 6-row glyph and pad it back to a fixed-width box. */
43
+ function shearGlyph(rows) {
44
+ const shifted = rows.map((r, i) => " ".repeat(SHEAR[i] ?? 0) + r);
45
+ const w = Math.max(...shifted.map((r) => [...r].length));
46
+ return shifted.map((r) => r.padEnd(w));
47
+ }
48
+ function composeWordmark(word, gap = " ") {
49
+ const letters = [...word].map((ch) => shearGlyph(GLYPHS[ch]));
50
+ const rows = [];
51
+ for (let r = 0; r < 6; r++)
52
+ rows.push(letters.map((g) => g[r]).join(gap));
53
+ return rows.join("\n");
54
+ }
55
+ /** "CARRIER OS" slightly-inclined block wordmark (rendered in white). */
56
+ export const WORDMARK = composeWordmark("CARRIER OS", " ");
57
+ /** Compact mark for very narrow terminals (avoids wrapping the block art). */
58
+ export const COMPACT_MARK = "◉─●─◉";