@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,187 @@
1
+ import path from "node:path";
2
+ import { executionContract } from "../services/execution-platform.js";
3
+ import { displayCommand } from "../services/command-policy.js";
4
+ import { c } from "./colors.js";
5
+ import { MARGIN, contentWidth } from "./composer-layout.js";
6
+ import { clip, stripControl, wrapText } from "./conversation.js";
7
+ import { approvalCard, cardHeader } from "./agent-cards.js";
8
+ /**
9
+ * What a person sees before and after a local command.
10
+ *
11
+ * The card is deliberately compact — a continuation of the conversation, not a
12
+ * form — but it still carries EVERY fact the decision needs: the exact command,
13
+ * where it will run, its risk tier, whether it may use the network, the real
14
+ * script text behind an npm script, the model's reason, and any policy notes.
15
+ * Nothing is summarised away; only the labelling is lighter.
16
+ *
17
+ * It is committed to the transcript, so what was approved stays on screen.
18
+ */
19
+ const TIER_TEXT = {
20
+ R0: "R0 · read-only",
21
+ R1: "R1 · runs project code",
22
+ R2: "R2 · changes files"
23
+ };
24
+ const NETWORK_TEXT = {
25
+ "none-expected": "no network expected",
26
+ "project-code-may-use-network": "not restricted",
27
+ "uses-network": "uses the network"
28
+ };
29
+ export const safeText = stripControl;
30
+ const INDENT = MARGIN + " ";
31
+ /** Width available inside the card. */
32
+ const inner = () => Math.max(24, contentWidth() - 4);
33
+ /** ` Label value` with continuation lines aligned under the value. */
34
+ function field(label, value, paint = c.dim) {
35
+ const pad = Math.max(12, label.length + 2);
36
+ const head = label.padEnd(pad);
37
+ return wrapText(safeText(value), inner() - pad).map((l, i) => INDENT + c.dim(i === 0 ? head : " ".repeat(pad)) + paint(l));
38
+ }
39
+ export function renderCommandReview(d, reason, repository, execution = executionContract(), activeRoot, operationId) {
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]);
41
+ const lines = [...cardHeader("COMMAND REVIEW", c.title)];
42
+ for (const l of wrapText(safeText(displayCommand(d.program, d.args)), inner()))
43
+ lines.push(MARGIN + c.accent(l));
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);
58
+ if (d.script) {
59
+ lines.push(...field("Script", d.script.text, c.value));
60
+ if (d.script.pre)
61
+ lines.push(...field("pre", d.script.pre, c.value));
62
+ if (d.script.post)
63
+ lines.push(...field("post", d.script.post, c.value));
64
+ }
65
+ if (reason)
66
+ lines.push(...field("Reason", reason));
67
+ for (const note of d.notes) {
68
+ if (/^Read-only|^Runs project code/.test(note))
69
+ continue; // already said by the tier
70
+ lines.push(INDENT + c.dim("· " + clip(note, inner() - 2)));
71
+ }
72
+ lines.push(...approvalCard("command", "This command needs its own approval; approving file changes never approves a command.", operationId ? [operationId] : []), "");
73
+ return lines;
74
+ }
75
+ /**
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.
79
+ */
80
+ export function renderCommandSummary(d, r, errorCode, message) {
81
+ const what = d ? displayCommand(d.program, d.args) : "command";
82
+ if (!r) {
83
+ const declined = errorCode === "COMMAND_REJECTED" || errorCode === "APPROVAL_TIMEOUT" || errorCode === "COMMAND_CANCELLED";
84
+ const icon = declined ? c.warn("✗") : c.err("✕");
85
+ return [MARGIN + icon + " " + c.dim(clip(`${what} — ${safeText(message ?? errorCode ?? "not run")}`, inner()))];
86
+ }
87
+ const secs = `${(r.duration_ms / 1000).toFixed(1)}s`;
88
+ const counts = summariseOutput(r.output);
89
+ const extra = [
90
+ counts,
91
+ secs,
92
+ r.truncated ? "output truncated" : "",
93
+ r.redaction_count ? `${r.redaction_count} secret${r.redaction_count === 1 ? "" : "s"} redacted` : ""
94
+ ].filter(Boolean);
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(" · "));
109
+ if (r.timed_out)
110
+ return [...out, MARGIN + c.err("✕ TIMED OUT") + c.dim(" · process tree stopped"), timing];
111
+ if (r.cancelled)
112
+ return [...out, MARGIN + c.warn("⊘ CANCELLED") + c.dim(" · process tree stopped"), timing];
113
+ if (r.exit_code === 0)
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 } } : {}) };
147
+ }
148
+ /**
149
+ * Test counts, when a runner states them plainly. Presentation only: the exit
150
+ * code remains the truth about success, and an unrecognised format simply adds
151
+ * nothing to the line.
152
+ */
153
+ export function summariseOutput(output) {
154
+ const text = safeText(output);
155
+ // node --test — "# pass 97" (tap reporter) or "ℹ pass 97" (spec reporter)
156
+ const nodePass = text.match(/^[#ℹ] pass (\d+)\s*$/m);
157
+ const nodeFail = text.match(/^[#ℹ] fail (\d+)\s*$/m);
158
+ if (nodePass && nodeFail) {
159
+ const skipped = text.match(/^[#ℹ] skipped (\d+)\s*$/m);
160
+ return [
161
+ `${nodePass[1]} passed`,
162
+ `${nodeFail[1]} failed`,
163
+ skipped && skipped[1] !== "0" ? `${skipped[1]} skipped` : ""
164
+ ]
165
+ .filter(Boolean)
166
+ .join(" · ");
167
+ }
168
+ // jest / vitest: "Tests: 11 failed, 3612 passed, 3623 total"
169
+ const jest = text.match(/^Tests:\s+(.+?)\s*$/m);
170
+ if (jest) {
171
+ const failed = jest[1].match(/(\d+) failed/);
172
+ const passed = jest[1].match(/(\d+) passed/);
173
+ const skipped = jest[1].match(/(\d+) (?:skipped|todo)/);
174
+ if (passed || failed) {
175
+ return [passed ? `${passed[1]} passed` : "", failed ? `${failed[1]} failed` : "", skipped ? `${skipped[1]} skipped` : ""]
176
+ .filter(Boolean)
177
+ .join(" · ");
178
+ }
179
+ }
180
+ // mocha
181
+ const passing = text.match(/^\s*(\d+) passing/m);
182
+ if (passing) {
183
+ const failing = text.match(/^\s*(\d+) failing/m);
184
+ return [`${passing[1]} passed`, failing ? `${failing[1]} failed` : ""].filter(Boolean).join(" · ");
185
+ }
186
+ return "";
187
+ }
@@ -0,0 +1,74 @@
1
+ import stringWidth from "string-width";
2
+ /**
3
+ * Composer layout. The composer + its divider lines span the FULL terminal
4
+ * width (Claude-style), inset by a small margin with a one-column right gutter
5
+ * so a line never overflows and wraps. It's computed fresh each render, so a
6
+ * resize simply redraws at the new width — cleanly, never "messed up".
7
+ *
8
+ * Long answer text still wraps to a readable maximum (READABLE_MAX) so replies
9
+ * don't run edge-to-edge on very wide terminals.
10
+ */
11
+ /** Left margin the whole column sits at. */
12
+ export const MARGIN = " ";
13
+ /** Cap for wrapping running text (dividers/composer are not capped). */
14
+ const READABLE_MAX = 96;
15
+ /** Terminal columns, defensively defaulted. */
16
+ function columns() {
17
+ const cols = process.stdout.columns;
18
+ return cols && cols > 0 ? cols : 80;
19
+ }
20
+ /** Full content width for the composer + dividers: terminal minus the left
21
+ * margin and a one-column right gutter. */
22
+ export function contentWidth() {
23
+ return Math.max(8, columns() - MARGIN.length - 1);
24
+ }
25
+ /** Width to wrap running text to — full content width, capped for readability. */
26
+ export function textWidth() {
27
+ return Math.max(20, Math.min(contentWidth(), READABLE_MAX));
28
+ }
29
+ // SGR colour runs plus OSC strings. An OSC payload (a hyperlink URL, a window
30
+ // title) occupies no columns, so a matcher that only knows SGR over-counts any
31
+ // line carrying one.
32
+ /** Visible column count of a styled string — escape sequences don't count. */
33
+ export function visibleWidth(s) {
34
+ return stringWidth(s);
35
+ }
36
+ /**
37
+ * Clamp a styled line to `width` visible columns, keeping its colour codes.
38
+ *
39
+ * The screen engine writes one transcript line per terminal row and does no
40
+ * wrap accounting, so ANY line wider than the terminal steals a second physical
41
+ * row and shifts everything below it — which is how model output containing a
42
+ * 250-character URL ends up overwriting the composer. This is the last line of
43
+ * defence: it runs over everything the markdown renderer emits, so a path that
44
+ * forgets to wrap degrades to a clipped line instead of a corrupted screen.
45
+ */
46
+ export function clampAnsi(s, width = contentWidth()) {
47
+ if (visibleWidth(s) <= width)
48
+ return s;
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;
68
+ }
69
+ row += token;
70
+ count += visibleWidth(token);
71
+ }
72
+ lines.push(row);
73
+ return lines;
74
+ }