@carrieros/cli 0.3.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.
Files changed (86) hide show
  1. package/README.md +34 -13
  2. package/dist/commands/chat.js +3 -3
  3. package/dist/commands/context.js +40 -0
  4. package/dist/commands/doctor.js +27 -12
  5. package/dist/commands/logout.js +1 -0
  6. package/dist/commands/permissions.js +77 -0
  7. package/dist/commands/scope.js +9 -6
  8. package/dist/commands/sessions.js +5 -0
  9. package/dist/commands/settings.js +8 -1
  10. package/dist/commands/update.js +79 -9
  11. package/dist/commands/usage.js +5 -5
  12. package/dist/commands/whoami.js +12 -9
  13. package/dist/ide/editor-context.js +115 -12
  14. package/dist/ide/ide-session.js +274 -13
  15. package/dist/ide/tool-host.js +2 -2
  16. package/dist/main.js +0 -0
  17. package/dist/services/api.js +178 -12
  18. package/dist/services/auth-origin.js +20 -0
  19. package/dist/services/chat-stream.js +26 -3
  20. package/dist/services/checkpoints.js +176 -14
  21. package/dist/services/client-tools.js +113 -21
  22. package/dist/services/code-intel.js +243 -0
  23. package/dist/services/code-symbols.js +94 -0
  24. package/dist/services/coding-workflow.js +554 -0
  25. package/dist/services/command-coordinator.js +85 -12
  26. package/dist/services/command-policy.js +34 -4
  27. package/dist/services/config.js +67 -5
  28. package/dist/services/container-runner.js +254 -0
  29. package/dist/services/container-supervisor.js +38 -0
  30. package/dist/services/context.js +45 -17
  31. package/dist/services/device-auth.js +30 -5
  32. package/dist/services/execution-platform.js +30 -0
  33. package/dist/services/file-resolver.js +1 -1
  34. package/dist/services/folder-key.js +22 -0
  35. package/dist/services/git-tools.js +181 -0
  36. package/dist/services/helper-bin.js +56 -35
  37. package/dist/services/instruction-resolver.js +54 -0
  38. package/dist/services/job-helper.js +31 -10
  39. package/dist/services/local-files.js +148 -26
  40. package/dist/services/local-tools.js +540 -35
  41. package/dist/services/login-flow.js +43 -12
  42. package/dist/services/mutation-coordinator.js +186 -20
  43. package/dist/services/mutation-groups.js +309 -0
  44. package/dist/services/mutation-recovery.js +159 -0
  45. package/dist/services/mutations.js +264 -78
  46. package/dist/services/packaged-update.js +403 -0
  47. package/dist/services/packaged.js +15 -0
  48. package/dist/services/permission-mode.js +60 -0
  49. package/dist/services/process-runner.js +7 -1
  50. package/dist/services/project-context.js +4 -4
  51. package/dist/services/result-reconciliation.js +49 -0
  52. package/dist/services/secure-store.js +21 -1
  53. package/dist/services/session-resolver.js +5 -0
  54. package/dist/services/supported-runtime.js +59 -0
  55. package/dist/services/task-context.js +212 -0
  56. package/dist/services/task-snapshot.js +38 -0
  57. package/dist/services/tool-result-outbox.js +195 -0
  58. package/dist/services/update.js +37 -12
  59. package/dist/services/workspace-registry.js +4 -3
  60. package/dist/services/workspace.js +8 -1
  61. package/dist/shell/shell-chat.js +299 -32
  62. package/dist/shell/shell-commands.js +46 -4
  63. package/dist/shell/shell-prompt.js +21 -11
  64. package/dist/shell/shell-renderer.js +1 -1
  65. package/dist/shell/shell.js +69 -7
  66. package/dist/shell/task-context-view.js +40 -0
  67. package/dist/ui/agent-cards.js +111 -0
  68. package/dist/ui/agent-presentation.js +131 -0
  69. package/dist/ui/approval.js +46 -16
  70. package/dist/ui/banner.js +31 -87
  71. package/dist/ui/change-review.js +293 -46
  72. package/dist/ui/chat-renderer.js +6 -6
  73. package/dist/ui/colors.js +9 -9
  74. package/dist/ui/command-details.js +11 -0
  75. package/dist/ui/command-palette.js +27 -10
  76. package/dist/ui/command-registry.js +9 -2
  77. package/dist/ui/command-review.js +77 -28
  78. package/dist/ui/composer-layout.js +26 -20
  79. package/dist/ui/conversation.js +77 -25
  80. package/dist/ui/live.js +1 -1
  81. package/dist/ui/screen.js +19 -11
  82. package/dist/ui/select.js +6 -0
  83. package/dist/ui/task-context-card.js +99 -0
  84. package/dist/ui/trust.js +7 -12
  85. package/dist/ui/ui.js +23 -0
  86. package/package.json +8 -5
@@ -5,6 +5,7 @@ import { contentWidth } from "./composer-layout.js";
5
5
  import { renderMarkdown } from "./markdown.js";
6
6
  import { renderUserMessage } from "./message.js";
7
7
  import { thinking } from "./spinner.js";
8
+ import { formatCredits } from "./ui.js";
8
9
  /**
9
10
  * Presentation layer for the conversation, styled after Claude Code:
10
11
  * ❯ <your message> (full-width bar — see message.ts)
@@ -66,9 +67,8 @@ function completionLabel(seconds, spend) {
66
67
  return `${phrase} ${Math.max(0.1, seconds).toFixed(1)}s${spendSuffix(spend)}`;
67
68
  }
68
69
  /** Format a number with thousands separators, trimming pointless decimals. */
69
- const num = (n, dp = 0) => n.toLocaleString("en-US", { minimumFractionDigits: dp, maximumFractionDigits: dp });
70
70
  /**
71
- * " · 412.6 credits left"
71
+ * " · 412.60 credits left"
72
72
  *
73
73
  * Balance only. Tokens and dollar cost are still returned by the API (and used
74
74
  * for request logging), but three numbers on a completion line is a bill, not a
@@ -85,7 +85,7 @@ export function spendSuffix(spend) {
85
85
  // cost. The balance itself is unchanged and still shown by /usage.
86
86
  if (spend?.unlimited === true) {
87
87
  return typeof spend.sessionSpent === "number"
88
- ? ` · Unlimited · session ${num(spend.sessionSpent, 2)} credits`
88
+ ? ` · Unlimited · session ${formatCredits(spend.sessionSpent)} credits`
89
89
  : " · Unlimited";
90
90
  }
91
91
  const credits = spend?.creditsRemaining;
@@ -93,8 +93,8 @@ export function spendSuffix(spend) {
93
93
  return "";
94
94
  // A negative balance is an overdraft, not "-556 left" — say what it is.
95
95
  return credits < 0
96
- ? ` · ${num(Math.abs(credits), 1)} credits overdrawn`
97
- : ` · ${num(credits, 1)} credits left`;
96
+ ? ` · ${formatCredits(Math.abs(credits))} credits overdrawn`
97
+ : ` · ${formatCredits(credits)} credits left`;
98
98
  }
99
99
  // Rotating tips shown beneath the spinner while Carrier is responding — a chance
100
100
  // to surface a handy shortcut, the way Claude Code does.
@@ -280,7 +280,7 @@ export async function streamAssistant(text) {
280
280
  md.shift();
281
281
  while (md.length && md[md.length - 1].trim() === "")
282
282
  md.pop();
283
- const tty = process.stdout.isTTY;
283
+ const tty = process.stdout.isTTY && process.env.TERM !== "dumb";
284
284
  if (tty)
285
285
  process.stdout.write("\x1b[?25l"); // hide the caret; ▋ is the cursor
286
286
  for (let i = 0; i < md.length; i++) {
package/dist/ui/colors.js CHANGED
@@ -24,8 +24,8 @@ export const c = {
24
24
  brandFixed: chalk.hex(BRAND_HEX), // fixed brand green — wordmark + prompt marker, never follows /color
25
25
  wordmark: chalk.whiteBright.bold, // CARRIER block logo (never recolored)
26
26
  // Text
27
- title: chalk.whiteBright.bold, // section titles / headings
28
- value: chalk.white, // primary values
27
+ title: chalk.bold, // section titles / headings
28
+ value: chalk, // primary values
29
29
  dim: chalk.dim, // secondary text
30
30
  subtitle: chalk.dim,
31
31
  label: chalk.dim, // metadata labels
@@ -33,23 +33,23 @@ export const c = {
33
33
  rule: chalk.dim, // separators / rules
34
34
  placeholder: chalk.dim.italic, // composer placeholder (fades into the background)
35
35
  // Interactive
36
- cmd: chalk.cyan, // slash commands
37
- key: chalk.cyan, // keybindings / command keys
38
- accent: chalk.cyan,
36
+ get cmd() { return chalk.hex(accentHex()); }, // slash commands
37
+ get key() { return chalk.hex(accentHex()); }, // keybindings / command keys
38
+ get accent() { return chalk.hex(accentHex()); },
39
39
  get sel() {
40
40
  return chalk.bgHex(accentHex()).black.bold;
41
41
  }, // selected palette bar (accent background)
42
42
  group: chalk.dim.bold, // palette group headers
43
43
  // Command arguments
44
- arg: chalk.green, // ids / values (mode, model)
45
- file: chalk.yellow, // file paths
44
+ arg: chalk, // ids / values (mode, model)
45
+ file: chalk, // file paths
46
46
  // SIA / clarification — deliberately not the yellow the turn-shape chips use,
47
47
  // because it isn't one: Fast and HIPWR change how the answer is produced,
48
48
  // while this changes the question before it's asked.
49
- magic: chalk.magentaBright,
49
+ get magic() { return chalk.hex(accentHex()); },
50
50
  // Status
51
51
  ok: chalk.green,
52
52
  warn: chalk.yellow,
53
- info: chalk.cyan,
53
+ get info() { return chalk.hex(accentHex()); },
54
54
  err: chalk.red
55
55
  };
@@ -0,0 +1,11 @@
1
+ import { stripControl } from "./conversation.js";
2
+ // Ephemeral display cache only. The existing result/outbox owns durable evidence.
3
+ const last = new WeakMap();
4
+ export function rememberCommandDetails(ctx, scope, output) {
5
+ last.set(ctx, { scope, output: stripControl(output) });
6
+ }
7
+ export function commandDetails(ctx, scope) {
8
+ const entry = last.get(ctx);
9
+ return entry?.scope === scope ? ["Command output (existing bounded, redacted result)", ...entry.output.split("\n")] : ["No command output available for this session and repository."];
10
+ }
11
+ export function clearCommandDetails(ctx) { last.delete(ctx); }
@@ -12,8 +12,8 @@ function colorOf(name) {
12
12
  const m = name.match(/^\/(?:color|theme)\s+(\w+)$/i);
13
13
  return m && isThemeColor(m[1].toLowerCase()) ? m[1].toLowerCase() : null;
14
14
  }
15
- export function readCommand(caret, history, footer = "", placeholder = "") {
16
- if (!process.stdin.isTTY)
15
+ export function readCommand(caret, history, footer = "", placeholder = "", locked = () => false) {
16
+ if (!process.stdin.isTTY || process.env.TERM === "dumb")
17
17
  return readSimple(caret);
18
18
  return new Promise((resolve) => {
19
19
  const stdin = process.stdin;
@@ -98,9 +98,9 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
98
98
  const pad = " ".repeat(Math.max(0, total - promptCols));
99
99
  // The two divider rules carry the runtime accent (/color); the prompt
100
100
  // marker stays fixed brand green (branding, never recolored).
101
- const rule = MARGIN + c.brand("─".repeat(total));
102
- const promptLine = MARGIN + c.brandFixed("❯") + " " + body + (visTrailer ? c.dim(visTrailer) : "") + pad;
103
- const core = [rule, promptLine, rule, footer]; // fixed 4-row composer core
101
+ const rule = MARGIN + c.rule("─".repeat(total));
102
+ const promptLine = MARGIN + c.brand("›") + " " + body + (visTrailer ? c.dim(visTrailer) : "") + pad;
103
+ const core = [rule, promptLine, rule, typeof footer === "function" ? footer() : footer]; // fixed 4-row composer core
104
104
  // The command palette floats ABOVE the bar when open — except in the
105
105
  // value-entry context (`/color <value>`), where the inline arg hint / ghost
106
106
  // on the prompt line replaces the list. The caret sits on the prompt line
@@ -115,6 +115,16 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
115
115
  const caretCol = MARGIN.length + MARKER_COLS + (cursor - start) + 1;
116
116
  screenComposer(paletteLines, core, 1, caretCol);
117
117
  };
118
+ process.stdout.on("resize", render);
119
+ let lastFooter = typeof footer === "function" ? footer() : footer;
120
+ const footerTimer = setInterval(() => {
121
+ const next = typeof footer === "function" ? footer() : footer;
122
+ if (next !== lastFooter) {
123
+ lastFooter = next;
124
+ render();
125
+ }
126
+ }, 500);
127
+ footerTimer.unref();
118
128
  const finish = (res) => {
119
129
  paletteOpen = false;
120
130
  // Undo any live color preview — the /color command re-applies + persists
@@ -126,16 +136,18 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
126
136
  // Clear the composer to an empty prompt so the just-submitted text doesn't
127
137
  // linger in the bar while the response streams into the transcript above.
128
138
  const total = contentWidth();
129
- const rule = MARGIN + c.brand("─".repeat(total));
130
- const empty = MARGIN + c.brandFixed("❯") + " " + " ".repeat(Math.max(0, total - MARKER_COLS));
131
- screenComposer([], [rule, empty, rule, footer], 1, MARGIN.length + MARKER_COLS + 1);
139
+ const rule = MARGIN + c.rule("─".repeat(total));
140
+ const empty = MARGIN + c.brand("›") + " " + " ".repeat(Math.max(0, total - MARKER_COLS));
141
+ screenComposer([], [rule, empty, rule, typeof footer === "function" ? footer() : footer], 1, MARGIN.length + MARKER_COLS + 1);
142
+ clearInterval(footerTimer);
143
+ process.stdout.removeListener("resize", render);
132
144
  stdin.removeListener("keypress", onKey);
133
145
  // Raw mode is intentionally left ON between prompts (see the setup note);
134
146
  // the shell restores cooked mode when it exits.
135
147
  resolve(res);
136
148
  };
137
149
  const setInput = (next, open) => {
138
- input = next;
150
+ input = locked() && !next.startsWith("/") ? "" : next;
139
151
  cursor = input.length;
140
152
  paletteOpen = open ?? input.startsWith("/");
141
153
  if (paletteOpen) {
@@ -228,6 +240,8 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
228
240
  if (key.name === "end" && input.length === 0)
229
241
  return screenScrollToBottom();
230
242
  if (key.name === "return" || key.name === "enter") {
243
+ if (locked() && !input.startsWith("/"))
244
+ return render();
231
245
  // Value-entry (`/color <value>`): run what's typed, completing any ghost
232
246
  // first (`/color gr` → `/color green`; a bare `/color ` → the picker).
233
247
  if (paletteOpen && /^\/(?:color|theme)\s/i.test(input)) {
@@ -329,7 +343,10 @@ export function readCommand(caret, history, footer = "", placeholder = "") {
329
343
  }
330
344
  // Printable character.
331
345
  if (str && !key.ctrl && !key.meta && str >= " " && str !== "\x7f") {
332
- input = input.slice(0, cursor) + str + input.slice(cursor);
346
+ const next = input.slice(0, cursor) + str + input.slice(cursor);
347
+ if (locked() && !next.startsWith("/"))
348
+ return;
349
+ input = next;
333
350
  cursor += str.length;
334
351
  if (input.startsWith("/")) {
335
352
  paletteOpen = true;
@@ -21,6 +21,7 @@ export const GROUP_ORDER = [
21
21
  "Developer"
22
22
  ];
23
23
  export const COMMANDS = [
24
+ { name: "/details", desc: "Show the last bounded command output", group: "Context", rank: 10 },
24
25
  { name: "/chat", desc: "Start chatting with Carrier", group: "Chat", rank: 1 },
25
26
  { name: "/switch", desc: "Switch chat: Carrier ⇄ Standard", group: "Chat", rank: 2 },
26
27
  { name: "/websearch", desc: "Search the web — or a query to search now", group: "Chat", rank: 3, arg: "query" },
@@ -53,13 +54,18 @@ export const COMMANDS = [
53
54
  arg: "question"
54
55
  },
55
56
  { name: "/new", desc: "Start a new conversation", group: "Sessions", rank: 1, arg: "title" },
57
+ { name: "/clear", desc: "Start a new task — the current one stays in /sessions", group: "Sessions", rank: 1 },
58
+ { name: "/resume", desc: "Continue an earlier conversation (its permission mode, never its approvals)", group: "Sessions", rank: 2 },
56
59
  { name: "/sessions", desc: "List conversations, numbered", group: "Sessions", rank: 2 },
57
60
  { name: "/session", desc: "Continue a session — /session 2", group: "Sessions", rank: 3, arg: "n" },
58
61
  { name: "/history", desc: "Transcript — /history 2", group: "Sessions", rank: 4, arg: "n" },
59
62
  { name: "/context", desc: "What the next message is sent with — try /context project", group: "Context", rank: 1, arg: "project" },
60
63
  { name: "/memory", desc: "Snapshots and restructures — /memory 2", group: "Context", rank: 2, arg: "n" },
64
+ { name: "/compact", desc: "Summarise earlier messages; keep the task, plan, changes and tests", group: "Context", rank: 2 },
65
+ { name: "/permissions", desc: "Manual · Plan · Accept Edits · Auto", group: "Chat", rank: 1, arg: "manual|plan|accept-edits|auto" },
66
+ { name: "/plan", desc: "Plan mode — investigate and plan; no changes or commands", group: "Chat", rank: 1 },
61
67
  { name: "/model", desc: "List & switch provider model", group: "Models", rank: 1, arg: "model" },
62
- { name: "/mode", desc: "List & switch Carrier mode", group: "Models", rank: 2, arg: "mode" },
68
+ { name: "/mode", desc: "Carrier mode — or /mode manual|plan|accept-edits for permissions", group: "Models", rank: 2, arg: "mode" },
63
69
  { name: "/upload", desc: "Upload file(s) — many + * globs", group: "Files", rank: 1, arg: "path" },
64
70
  { name: "/attach", desc: "Attach an upload to your next message", group: "Files", rank: 2, arg: "file" },
65
71
  { name: "/detach", desc: "Clear attached files", group: "Files", rank: 3 },
@@ -70,7 +76,7 @@ export const COMMANDS = [
70
76
  { name: "/undo", desc: "Undo the latest change — /undo --repo <name> for another repository", group: "Files", rank: 7, arg: "operation" },
71
77
  { name: "/repo", desc: "Active repository — /repo use <name> to switch", group: "Context", rank: 3, arg: "use" },
72
78
  { name: "/repos", desc: "Repositories in this workspace", group: "Context", rank: 4 },
73
- { name: "/whoami", desc: "Current workspace & project", group: "Account", rank: 1 },
79
+ { name: "/whoami", desc: "Your signed-in account", group: "Account", rank: 1 },
74
80
  { name: "/usage", desc: "View API usage", group: "Account", rank: 2 },
75
81
  { name: "/settings", desc: "CLI settings — /settings commands on|off", group: "Account", rank: 3, arg: "commands" },
76
82
  { name: "/login", desc: "Sign in via your browser", group: "Account", rank: 3 },
@@ -90,6 +96,7 @@ export const COMMANDS = [
90
96
  /** Commands that take an argument — completed with a trailing space. */
91
97
  export const TAKES_ARG = new Set([
92
98
  "/mode",
99
+ "/permissions",
93
100
  "/model",
94
101
  "/websearch",
95
102
  "/fast",
@@ -1,7 +1,10 @@
1
+ import path from "node:path";
2
+ import { executionContract } from "../services/execution-platform.js";
1
3
  import { displayCommand } from "../services/command-policy.js";
2
4
  import { c } from "./colors.js";
3
5
  import { MARGIN, contentWidth } from "./composer-layout.js";
4
6
  import { clip, stripControl, wrapText } from "./conversation.js";
7
+ import { approvalCard, cardHeader } from "./agent-cards.js";
5
8
  /**
6
9
  * What a person sees before and after a local command.
7
10
  *
@@ -29,30 +32,29 @@ const INDENT = MARGIN + " ";
29
32
  const inner = () => Math.max(24, contentWidth() - 4);
30
33
  /** ` Label value` with continuation lines aligned under the value. */
31
34
  function field(label, value, paint = c.dim) {
32
- const pad = 8;
35
+ const pad = Math.max(12, label.length + 2);
33
36
  const head = label.padEnd(pad);
34
37
  return wrapText(safeText(value), inner() - pad).map((l, i) => INDENT + c.dim(i === 0 ? head : " ".repeat(pad)) + paint(l));
35
38
  }
36
- export function renderCommandReview(d, reason, repository) {
39
+ export function renderCommandReview(d, reason, repository, execution = executionContract(), activeRoot, operationId) {
37
40
  const tier = d.tier === "R2" ? c.warn(TIER_TEXT[d.tier]) : d.tier === "R1" ? c.value(TIER_TEXT[d.tier]) : c.dim(TIER_TEXT[d.tier]);
38
- const lines = [
39
- "",
40
- MARGIN + c.warn("◆") + " " + c.title("Carrier OS wants to run:"),
41
- ""
42
- ];
43
- // A command can now be aimed at a repository that is not the active one, so
44
- // WHICH repository is part of what is being approved. It sits above the
45
- // command, before the absolute working directory that confirms it, and reads
46
- // the same as the file-change card.
47
- if (repository) {
48
- lines.push(INDENT + c.dim("Repository ") + c.value(clip(safeText(repository), Math.max(12, inner() - 14))), "");
49
- }
41
+ const lines = [...cardHeader("COMMAND REVIEW", c.title)];
50
42
  for (const l of wrapText(safeText(displayCommand(d.program, d.args)), inner()))
51
- lines.push(INDENT + c.accent(l));
52
- for (const l of wrapText(safeText(d.cwdAbsolute), inner()))
53
- lines.push(INDENT + c.file(l));
54
- lines.push(INDENT + tier + c.dim(" · network: " + NETWORK_TEXT[d.network]));
43
+ lines.push(MARGIN + c.accent(l));
55
44
  lines.push("");
45
+ // A command can be aimed at a repository that is not the active one, so
46
+ // WHICH repository is part of what is being approved.
47
+ if (repository)
48
+ lines.push(...field("Repository", repository, c.value));
49
+ const relative = activeRoot ? path.relative(activeRoot, d.cwdAbsolute) : undefined;
50
+ const cwd = relative !== undefined && relative !== ".." && !relative.startsWith(".." + path.sep) && !path.isAbsolute(relative) ? relative || "." : d.cwdAbsolute;
51
+ lines.push(...field("Directory", cwd, c.file));
52
+ const network = execution.backend === "docker-engine-v1" ? "Disabled" : execution.backend === "windows-job" ? "Not restricted by executor" : "Unavailable";
53
+ lines.push(...field("Runtime", execution.backend ? `${execution.backend} · ${execution.backend === "docker-engine-v1" ? "isolated Linux runtime" : "native Windows"}` : "unavailable", c.value));
54
+ lines.push(...field("Network", network, execution.backend === "docker-engine-v1" ? c.ok : c.warn));
55
+ if (execution.backend === "windows-job")
56
+ lines.push(...field("Expected", NETWORK_TEXT[d.network]));
57
+ lines.push(INDENT + c.dim("Risk".padEnd(12)) + tier);
56
58
  if (d.script) {
57
59
  lines.push(...field("Script", d.script.text, c.value));
58
60
  if (d.script.pre)
@@ -61,18 +63,19 @@ export function renderCommandReview(d, reason, repository) {
61
63
  lines.push(...field("post", d.script.post, c.value));
62
64
  }
63
65
  if (reason)
64
- lines.push(...field("Why", reason));
66
+ lines.push(...field("Reason", reason));
65
67
  for (const note of d.notes) {
66
68
  if (/^Read-only|^Runs project code/.test(note))
67
69
  continue; // already said by the tier
68
70
  lines.push(INDENT + c.dim("· " + clip(note, inner() - 2)));
69
71
  }
70
- lines.push("");
72
+ lines.push(...approvalCard("command", "This command needs its own approval; approving file changes never approves a command.", operationId ? [operationId] : []), "");
71
73
  return lines;
72
74
  }
73
75
  /**
74
- * A one-line result: what ran, how it ended, how long it took — plus test
75
- * counts when the output plainly states them.
76
+ * The result: a status heading, the command, then counts and timing — the
77
+ * exit code is the truth about success; counts are read from the output only
78
+ * when a runner states them plainly.
76
79
  */
77
80
  export function renderCommandSummary(d, r, errorCode, message) {
78
81
  const what = d ? displayCommand(d.program, d.args) : "command";
@@ -82,19 +85,65 @@ export function renderCommandSummary(d, r, errorCode, message) {
82
85
  return [MARGIN + icon + " " + c.dim(clip(`${what} — ${safeText(message ?? errorCode ?? "not run")}`, inner()))];
83
86
  }
84
87
  const secs = `${(r.duration_ms / 1000).toFixed(1)}s`;
88
+ const counts = summariseOutput(r.output);
85
89
  const extra = [
86
- summariseOutput(r.output),
90
+ counts,
91
+ secs,
87
92
  r.truncated ? "output truncated" : "",
88
93
  r.redaction_count ? `${r.redaction_count} secret${r.redaction_count === 1 ? "" : "s"} redacted` : ""
89
94
  ].filter(Boolean);
90
- const tail = c.dim([secs, ...extra].join(" · "));
95
+ // "Running tests…", the command, each test the runner named, the counts one
96
+ // per line, then the status the exit code decides.
97
+ const report = parseTestReport(r.output);
98
+ const isTest = report.tests.length > 0 || !!counts;
99
+ const shown = report.tests.slice(0, 12);
100
+ const out = [
101
+ "",
102
+ MARGIN + c.title(isTest ? "Running tests…" : "Running command…"),
103
+ MARGIN + " " + c.dim("> ") + c.accent(clip(what, inner() - 2)),
104
+ ...shown.map((t) => MARGIN + " " + (t.passed ? c.ok("✓ ") : c.err("✗ ")) + (t.passed ? c.dim : c.value)(clip(t.name, inner() - 2))),
105
+ ...(report.tests.length > shown.length ? [MARGIN + " " + c.dim(`+${report.tests.length - shown.length} more`)] : []),
106
+ ...(counts ? counts.split(" · ").map((n) => MARGIN + " " + (/^0 failed$/.test(n) || /passed/.test(n) ? c.value(n) : c.err(n))) : [])
107
+ ];
108
+ const timing = MARGIN + " " + c.dim(extra.filter((e) => e !== counts).join(" · "));
91
109
  if (r.timed_out)
92
- return [MARGIN + c.err("✕") + " " + c.value(what) + c.dim(" timed out — process tree stopped · ") + tail];
110
+ return [...out, MARGIN + c.err("✕ TIMED OUT") + c.dim(" · process tree stopped"), timing];
93
111
  if (r.cancelled)
94
- return [MARGIN + c.warn("✗") + " " + c.value(what) + c.dim(" cancelled — process tree stopped · ") + tail];
112
+ return [...out, MARGIN + c.warn("⊘ CANCELLED") + c.dim(" · process tree stopped"), timing];
95
113
  if (r.exit_code === 0)
96
- return [MARGIN + c.ok("✓") + " " + c.value(what) + c.dim(" · ") + tail];
97
- return [MARGIN + c.err("✕") + " " + c.value(what) + c.dim(` exited ${r.exit_code} · `) + tail];
114
+ return [...out, MARGIN + c.ok("✓ PASSED"), timing];
115
+ return [...out, MARGIN + c.err("✕ FAILED") + c.dim(` · exit ${r.exit_code}`), timing];
116
+ }
117
+ export function parseTestReport(output) {
118
+ const text = safeText(output).replace(/\r\n/g, "\n");
119
+ const tests = [];
120
+ const seen = new Set();
121
+ const add = (name, passed) => {
122
+ const clean = name.replace(/\s+\([\d.]+\s*m?s\)\s*$/, "").replace(/\s+#\s.*$/, "").trim();
123
+ const key = `${passed}:${clean}`;
124
+ if (!clean || seen.has(key))
125
+ return;
126
+ seen.add(key);
127
+ tests.push({ name: clean, passed });
128
+ };
129
+ // Results end where a runner starts its failure recap; reading past it would
130
+ // list a failing test twice.
131
+ const body = text.split(/\n[✖✕]\s+failing tests:|\nFailures:|\n\s*\d+ failing\b/)[0];
132
+ for (const line of body.split("\n")) {
133
+ let m;
134
+ if ((m = /^\s{0,4}(✔|✓|✖|✕|×)\s+(.+)$/.exec(line)))
135
+ add(m[2], m[1] === "✔" || m[1] === "✓");
136
+ else if ((m = /^(not ok|ok)\s+\d+\s+-\s+(.+)$/.exec(line)))
137
+ add(m[2], m[1] === "ok");
138
+ }
139
+ const value = (re) => {
140
+ const m = re.exec(text);
141
+ return m ? m[1].trim().replace(/,$/, "").slice(0, 120) : undefined;
142
+ };
143
+ const failed = tests.find((t) => !t.passed);
144
+ const expected = value(/^\s*expected:\s*(.+)$/m) ?? value(/^\s*Expected[^:]*:\s*(.+)$/m);
145
+ const received = value(/^\s*actual:\s*(.+)$/m) ?? value(/^\s*Received[^:]*:\s*(.+)$/m);
146
+ return { tests, ...(failed || expected || received ? { failure: { name: failed?.name, expected, received } } : {}) };
98
147
  }
99
148
  /**
100
149
  * Test counts, when a runner states them plainly. Presentation only: the exit
@@ -1,3 +1,4 @@
1
+ import stringWidth from "string-width";
1
2
  /**
2
3
  * Composer layout. The composer + its divider lines span the FULL terminal
3
4
  * width (Claude-style), inset by a small margin with a one-column right gutter
@@ -19,7 +20,7 @@ function columns() {
19
20
  /** Full content width for the composer + dividers: terminal minus the left
20
21
  * margin and a one-column right gutter. */
21
22
  export function contentWidth() {
22
- return Math.max(24, columns() - MARGIN.length - 1);
23
+ return Math.max(8, columns() - MARGIN.length - 1);
23
24
  }
24
25
  /** Width to wrap running text to — full content width, capped for readability. */
25
26
  export function textWidth() {
@@ -28,10 +29,9 @@ export function textWidth() {
28
29
  // SGR colour runs plus OSC strings. An OSC payload (a hyperlink URL, a window
29
30
  // title) occupies no columns, so a matcher that only knows SGR over-counts any
30
31
  // line carrying one.
31
- const ANSI = /\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b\[[0-9;]*m/g;
32
32
  /** Visible column count of a styled string — escape sequences don't count. */
33
33
  export function visibleWidth(s) {
34
- return s.replace(ANSI, "").length;
34
+ return stringWidth(s);
35
35
  }
36
36
  /**
37
37
  * Clamp a styled line to `width` visible columns, keeping its colour codes.
@@ -46,23 +46,29 @@ export function visibleWidth(s) {
46
46
  export function clampAnsi(s, width = contentWidth()) {
47
47
  if (visibleWidth(s) <= width)
48
48
  return s;
49
- const max = Math.max(1, width - 1); // room for the ellipsis
50
- let out = "";
51
- let vis = 0;
52
- let i = 0;
53
- while (i < s.length && vis < max) {
54
- if (s[i] === "\x1b") {
55
- // Copy the escape verbatim; it costs no columns.
56
- const m = /^\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|^\x1b\[[0-9;]*m/.exec(s.slice(i));
57
- if (m) {
58
- out += m[0];
59
- i += m[0].length;
60
- continue;
61
- }
49
+ const first = wrapAnsi(s, Math.max(1, width - 1))[0];
50
+ return `${first}…${s.includes("\x1b[") ? "\x1b[0m" : ""}`;
51
+ }
52
+ /** Reflow transcript content without discarding reviewed bytes on resize. */
53
+ export function wrapAnsi(text, width) {
54
+ const limit = Math.max(1, width);
55
+ const tokens = text.split(/(\x1b\[[0-9;]*m)/g).flatMap(part => part.startsWith("\x1b[") ? [part] : [...new Intl.Segmenter().segment(part)].map(s => s.segment));
56
+ const lines = [];
57
+ let row = "", count = 0, style = "";
58
+ for (const token of tokens) {
59
+ if (token.startsWith("\x1b[")) {
60
+ row += token;
61
+ style = token === "\x1b[0m" ? "" : style + token;
62
+ continue;
63
+ }
64
+ if (count + visibleWidth(token) > limit && count > 0) {
65
+ lines.push(row + (style ? "\x1b[0m" : ""));
66
+ row = style;
67
+ count = 0;
62
68
  }
63
- out += s[i];
64
- vis++;
65
- i++;
69
+ row += token;
70
+ count += visibleWidth(token);
66
71
  }
67
- return `${out}…\x1b[0m`;
72
+ lines.push(row);
73
+ return lines;
68
74
  }