@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.
- package/README.md +34 -13
- package/dist/commands/chat.js +3 -3
- package/dist/commands/context.js +40 -0
- package/dist/commands/doctor.js +27 -12
- package/dist/commands/logout.js +1 -0
- package/dist/commands/permissions.js +77 -0
- package/dist/commands/scope.js +9 -6
- package/dist/commands/sessions.js +5 -0
- package/dist/commands/settings.js +8 -1
- package/dist/commands/update.js +79 -9
- package/dist/commands/usage.js +5 -5
- package/dist/commands/whoami.js +12 -9
- package/dist/ide/editor-context.js +115 -12
- package/dist/ide/ide-session.js +274 -13
- package/dist/ide/tool-host.js +2 -2
- package/dist/main.js +0 -0
- package/dist/services/api.js +178 -12
- package/dist/services/auth-origin.js +20 -0
- package/dist/services/chat-stream.js +26 -3
- package/dist/services/checkpoints.js +176 -14
- package/dist/services/client-tools.js +113 -21
- 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 +85 -12
- package/dist/services/command-policy.js +34 -4
- package/dist/services/config.js +67 -5
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +45 -17
- package/dist/services/device-auth.js +30 -5
- package/dist/services/execution-platform.js +30 -0
- package/dist/services/file-resolver.js +1 -1
- package/dist/services/folder-key.js +22 -0
- package/dist/services/git-tools.js +181 -0
- package/dist/services/helper-bin.js +56 -35
- package/dist/services/instruction-resolver.js +54 -0
- package/dist/services/job-helper.js +31 -10
- package/dist/services/local-files.js +148 -26
- package/dist/services/local-tools.js +540 -35
- package/dist/services/login-flow.js +43 -12
- package/dist/services/mutation-coordinator.js +186 -20
- package/dist/services/mutation-groups.js +309 -0
- package/dist/services/mutation-recovery.js +159 -0
- package/dist/services/mutations.js +264 -78
- package/dist/services/packaged-update.js +403 -0
- package/dist/services/packaged.js +15 -0
- package/dist/services/permission-mode.js +60 -0
- package/dist/services/process-runner.js +7 -1
- package/dist/services/project-context.js +4 -4
- package/dist/services/result-reconciliation.js +49 -0
- package/dist/services/secure-store.js +21 -1
- package/dist/services/session-resolver.js +5 -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 +37 -12
- package/dist/services/workspace-registry.js +4 -3
- package/dist/services/workspace.js +8 -1
- package/dist/shell/shell-chat.js +299 -32
- package/dist/shell/shell-commands.js +46 -4
- package/dist/shell/shell-prompt.js +21 -11
- package/dist/shell/shell-renderer.js +1 -1
- package/dist/shell/shell.js +69 -7
- package/dist/shell/task-context-view.js +40 -0
- package/dist/ui/agent-cards.js +111 -0
- package/dist/ui/agent-presentation.js +131 -0
- package/dist/ui/approval.js +46 -16
- package/dist/ui/banner.js +31 -87
- package/dist/ui/change-review.js +293 -46
- package/dist/ui/chat-renderer.js +6 -6
- package/dist/ui/colors.js +9 -9
- package/dist/ui/command-details.js +11 -0
- package/dist/ui/command-palette.js +27 -10
- package/dist/ui/command-registry.js +9 -2
- package/dist/ui/command-review.js +77 -28
- package/dist/ui/composer-layout.js +26 -20
- package/dist/ui/conversation.js +77 -25
- package/dist/ui/live.js +1 -1
- package/dist/ui/screen.js +19 -11
- package/dist/ui/select.js +6 -0
- package/dist/ui/task-context-card.js +99 -0
- package/dist/ui/trust.js +7 -12
- package/dist/ui/ui.js +23 -0
- package/package.json +8 -5
package/dist/ui/approval.js
CHANGED
|
@@ -15,14 +15,21 @@ function countdown(msLeft) {
|
|
|
15
15
|
* the policy underneath.
|
|
16
16
|
*/
|
|
17
17
|
export function approvalFrame(question, msLeft) {
|
|
18
|
-
const hint = c.dim("Enter or ") +
|
|
18
|
+
const hint = c.dim("Type y + Enter to approve · empty Enter or ") +
|
|
19
19
|
c.key("n") +
|
|
20
20
|
c.dim(" declines · ") +
|
|
21
21
|
c.key("Ctrl+C") +
|
|
22
22
|
c.dim(" stops the turn · declines on its own in ") +
|
|
23
23
|
c.dim(countdown(msLeft));
|
|
24
|
-
const short = c.dim("Enter/") + c.key("n") + c.dim(" declines · ") + c.key("Ctrl+C") + c.dim(" stops · ") + c.dim(countdown(msLeft));
|
|
24
|
+
const short = c.dim("y + Enter approves · Enter/") + c.key("n") + c.dim(" declines · ") + c.key("Ctrl+C") + c.dim(" stops · ") + c.dim(countdown(msLeft));
|
|
25
25
|
const room = contentWidth() - 6;
|
|
26
|
+
if (contentWidth() < 70)
|
|
27
|
+
return [
|
|
28
|
+
MARGIN + c.title(question),
|
|
29
|
+
MARGIN + c.dim("y + Enter approves"),
|
|
30
|
+
MARGIN + c.dim("Enter/n declines"),
|
|
31
|
+
MARGIN + c.dim(`Ctrl+C stops · ${countdown(msLeft)}`)
|
|
32
|
+
];
|
|
26
33
|
return [
|
|
27
34
|
MARGIN + " " + c.warn("?") + " " + c.title(question) + " " + c.dim("(y/N)"),
|
|
28
35
|
MARGIN + " " + (visibleWidth(hint) <= room ? hint : short)
|
|
@@ -32,37 +39,59 @@ export function askApproval(opts) {
|
|
|
32
39
|
return new Promise((resolve) => {
|
|
33
40
|
const deadline = Date.now() + opts.timeoutMs;
|
|
34
41
|
let done = false;
|
|
42
|
+
let candidate = false;
|
|
43
|
+
let confirming = false;
|
|
35
44
|
const paint = () => screenTransient(approvalFrame(opts.question, deadline - Date.now()));
|
|
36
45
|
const finish = (value) => {
|
|
37
46
|
if (done)
|
|
38
47
|
return;
|
|
39
48
|
done = true;
|
|
40
49
|
clearInterval(timer);
|
|
50
|
+
process.stdout.removeListener("resize", paint);
|
|
41
51
|
opts.signal?.removeEventListener?.("abort", onAbort);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
setImmediate(() => {
|
|
53
|
+
release();
|
|
54
|
+
screenTransient([]);
|
|
55
|
+
resolve(value);
|
|
56
|
+
});
|
|
45
57
|
};
|
|
46
58
|
function onAbort() {
|
|
47
59
|
finish("cancel");
|
|
48
60
|
}
|
|
49
61
|
const onKey = (str, key) => {
|
|
50
|
-
if (!key && !str)
|
|
62
|
+
if (done || (!key && !str))
|
|
51
63
|
return;
|
|
64
|
+
if (Date.now() >= deadline)
|
|
65
|
+
return finish("timeout");
|
|
66
|
+
if (opts.signal?.aborted)
|
|
67
|
+
return finish("cancel");
|
|
52
68
|
if (key?.ctrl && (key.name === "c" || key.name === "d"))
|
|
53
69
|
return finish("cancel");
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (key?.name === "end")
|
|
59
|
-
return screenScrollToBottom();
|
|
60
|
-
if (str === "y" || str === "Y")
|
|
61
|
-
return finish("approve");
|
|
62
|
-
if (str === "n" || str === "N" || key?.name === "escape")
|
|
70
|
+
// Never interpret a prefix of text/paste as consent. Drain this input
|
|
71
|
+
// burst before resolving so trailing characters cannot approve another
|
|
72
|
+
// prompt. No input text is retained or rendered.
|
|
73
|
+
if (confirming)
|
|
63
74
|
return finish("reject");
|
|
64
|
-
if (key?.
|
|
75
|
+
if (key?.ctrl || key?.meta)
|
|
65
76
|
return finish("reject");
|
|
77
|
+
if (!candidate && ["up", "down", "left", "right", "home"].includes(key?.name ?? ""))
|
|
78
|
+
return;
|
|
79
|
+
if (!candidate && key?.name === "pageup")
|
|
80
|
+
return screenScrollPage(1);
|
|
81
|
+
if (!candidate && key?.name === "pagedown")
|
|
82
|
+
return screenScrollPage(-1);
|
|
83
|
+
if (!candidate && key?.name === "end")
|
|
84
|
+
return screenScrollToBottom();
|
|
85
|
+
if ((str === "y" || str === "Y") && !candidate) {
|
|
86
|
+
candidate = true;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if ((key?.name === "return" || key?.name === "enter") && candidate) {
|
|
90
|
+
confirming = true;
|
|
91
|
+
setImmediate(() => finish(Date.now() >= deadline ? "timeout" : opts.signal?.aborted ? "cancel" : "approve"));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
finish("reject");
|
|
66
95
|
};
|
|
67
96
|
const release = captureKeys(onKey);
|
|
68
97
|
const timer = setInterval(() => {
|
|
@@ -75,6 +104,7 @@ export function askApproval(opts) {
|
|
|
75
104
|
if (opts.signal?.aborted)
|
|
76
105
|
return finish("cancel");
|
|
77
106
|
opts.signal?.addEventListener?.("abort", onAbort, { once: true });
|
|
107
|
+
process.stdout.on("resize", paint);
|
|
78
108
|
screenScrollToBottom();
|
|
79
109
|
paint();
|
|
80
110
|
});
|
package/dist/ui/banner.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { line } from "../services/output.js";
|
|
3
|
-
import { branchLabel,
|
|
3
|
+
import { branchLabel, getWorkspace } from "../services/workspace.js";
|
|
4
4
|
import { modeLabelShort, modelLabelShort } from "../shell/shell-chat.js";
|
|
5
5
|
import { c } from "./colors.js";
|
|
6
|
+
import { clip } from "./conversation.js";
|
|
7
|
+
import { contentWidth, MARGIN } from "./composer-layout.js";
|
|
6
8
|
import { WORDMARK } from "./logo.js";
|
|
7
9
|
import { BRAND_HEX } from "./theme.js";
|
|
8
|
-
const MARGIN = " ";
|
|
9
|
-
const LABEL_WIDTH = 13;
|
|
10
|
-
/** Visible width of a block of lines. */
|
|
11
|
-
function blockWidth(block) {
|
|
12
|
-
return Math.max(...block.split("\n").map((l) => [...l].length));
|
|
13
|
-
}
|
|
14
|
-
/** True when the terminal is too narrow for the block wordmark. */
|
|
15
|
-
function isNarrow() {
|
|
16
|
-
return (process.stdout.columns ?? 80) < 2 + blockWidth(WORDMARK) + 2;
|
|
17
|
-
}
|
|
18
|
-
// ── Theme-color gradient across the wordmark (subtle; follows the accent) ──────
|
|
19
10
|
function hexToRgb(h) {
|
|
20
11
|
const n = parseInt(h.slice(1), 16);
|
|
21
12
|
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
@@ -26,87 +17,40 @@ function lerpHex(a, b, t) {
|
|
|
26
17
|
const mix = (x, y) => Math.round(x + (y - x) * t);
|
|
27
18
|
return "#" + [mix(ar, br), mix(ag, bg), mix(ab, bb)].map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
28
19
|
}
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* branding, so it stays green and does NOT follow the runtime /color accent. */
|
|
32
|
-
function gradientWordmark(lines) {
|
|
33
|
-
const from = BRAND_HEX;
|
|
34
|
-
const to = lerpHex(from, "#ffffff", 0.5); // lighten toward white on the right
|
|
35
|
-
const maxW = Math.max(1, ...lines.map((l) => [...l].length));
|
|
36
|
-
return lines.map((line) => [...line].map((ch, i) => (ch === " " ? ch : chalk.hex(lerpHex(from, to, i / maxW))(ch))).join(""));
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* The brand lockup lines (already colored): the CARRIER block wordmark with a
|
|
40
|
-
* subtle theme-color gradient. Shared by the startup banner and first-run
|
|
41
|
-
* welcome.
|
|
42
|
-
*/
|
|
20
|
+
/** The CARRIER OS block wordmark with a brand-green → lighter gradient, or a
|
|
21
|
+
* one-line mark when the terminal is too narrow for it. */
|
|
43
22
|
export function renderBrandmark() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return MARGIN + c.label(label.padEnd(LABEL_WIDTH)) + c.value(value);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Where you are, in three lines: the project, its Git state, and the path.
|
|
54
|
-
*
|
|
55
|
-
* This is the first thing the CLI has ever known about the local machine, and
|
|
56
|
-
* the banner is where it belongs — it answers "what am I pointed at?" before
|
|
57
|
-
* the first prompt, rather than making someone run a command to find out.
|
|
58
|
-
*
|
|
59
|
-
* Failure is silent by design. A machine without Git, or a folder Git refuses
|
|
60
|
-
* to read, still gets a Workspace and a Path; only the Git line changes. The
|
|
61
|
-
* caller already wraps this, but the shell must open regardless.
|
|
62
|
-
*/
|
|
63
|
-
function workspaceLines() {
|
|
64
|
-
const ws = getWorkspace();
|
|
65
|
-
const repo = ws.repository;
|
|
66
|
-
const out = [kvLine("Workspace", ws.project.name)];
|
|
67
|
-
if (repo.state === "detected") {
|
|
68
|
-
const branch = branchLabel(repo) ?? "unknown";
|
|
69
|
-
const status = statusLabel(repo);
|
|
70
|
-
// "Clean" adds nothing at a glance — the absence of a count already says
|
|
71
|
-
// it. Only a dirty tree, or an unknown one, is worth the extra words.
|
|
72
|
-
const suffix = status && status !== "Clean" ? ` ${c.dim("·")} ${status}` : "";
|
|
73
|
-
out.push(kvLine("Git", branch) + suffix);
|
|
74
|
-
}
|
|
75
|
-
else if (repo.state === "unavailable") {
|
|
76
|
-
out.push(kvLine("Git", "Unavailable"));
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
out.push(kvLine("Git", "Not detected"));
|
|
80
|
-
}
|
|
81
|
-
// Budget: margin + label column + a little slack, so a deep path shortens
|
|
82
|
-
// instead of wrapping the banner onto a second line.
|
|
83
|
-
const width = Math.max(24, (process.stdout.columns ?? 80) - MARGIN.length - LABEL_WIDTH - 2);
|
|
84
|
-
out.push(kvLine("Path", fitPath(ws.cwd, width)));
|
|
85
|
-
out.push("");
|
|
86
|
-
return out;
|
|
23
|
+
const rows = WORDMARK.split("\n");
|
|
24
|
+
const width = Math.max(1, ...rows.map((l) => [...l].length));
|
|
25
|
+
if ((process.stdout.columns ?? 80) < MARGIN.length + width + 2)
|
|
26
|
+
return [MARGIN + c.title("CarrierOS")];
|
|
27
|
+
const to = lerpHex(BRAND_HEX, "#ffffff", 0.5);
|
|
28
|
+
return rows.map((row) => MARGIN + [...row].map((ch, i) => (ch === " " ? ch : chalk.hex(lerpHex(BRAND_HEX, to, i / width))(ch))).join(""));
|
|
87
29
|
}
|
|
88
30
|
export function renderWelcomeBanner(ctx, opts = {}) {
|
|
89
31
|
try {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (opts.notices?.length)
|
|
99
|
-
out.push("");
|
|
100
|
-
out.push(MARGIN + c.hint("Type ") + c.key("/help") + c.hint(" for available commands."));
|
|
101
|
-
// Emit through `line()` so, in the interactive shell, the banner lands in the
|
|
102
|
-
// transcript region above the pinned composer (not written over it).
|
|
103
|
-
for (const l of out)
|
|
32
|
+
const ws = getWorkspace();
|
|
33
|
+
const branch = branchLabel(ws.repository);
|
|
34
|
+
// Where the agent will work, stated plainly before the first prompt: the
|
|
35
|
+
// signed-in state (a stored credential; the server checks it on use), the
|
|
36
|
+
// repository this folder resolves to, and its branch.
|
|
37
|
+
const row = (label, value) => MARGIN + c.dim(label.padEnd(12)) + c.value(clip(value, Math.max(8, contentWidth() - 12 - MARGIN.length)));
|
|
38
|
+
line("");
|
|
39
|
+
for (const l of renderBrandmark())
|
|
104
40
|
line(l);
|
|
41
|
+
line("");
|
|
42
|
+
line(MARGIN + c.ok("Authenticated ✓"));
|
|
43
|
+
line(row("Repository", ws.project.name));
|
|
44
|
+
if (branch)
|
|
45
|
+
line(row("Branch", branch));
|
|
46
|
+
line(row("Model", modelLabelShort(ctx)));
|
|
47
|
+
line(row("Mode", modeLabelShort(ctx)));
|
|
48
|
+
for (const notice of opts.notices ?? [])
|
|
49
|
+
line(MARGIN + clip(notice, contentWidth()));
|
|
50
|
+
line(MARGIN + c.dim("Describe a bug or a change in plain words · /help for commands"));
|
|
51
|
+
line("");
|
|
105
52
|
}
|
|
106
53
|
catch {
|
|
107
|
-
|
|
108
|
-
line();
|
|
109
|
-
line(` ${c.wordmark("Carrier OS")} ${c.subtitle("CLI")}`);
|
|
110
|
-
line();
|
|
54
|
+
line(MARGIN + c.title("CarrierOS"));
|
|
111
55
|
}
|
|
112
56
|
}
|
package/dist/ui/change-review.js
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { c } from "./colors.js";
|
|
2
|
-
import { MARGIN, contentWidth } from "./composer-layout.js";
|
|
2
|
+
import { MARGIN, contentWidth, visibleWidth } from "./composer-layout.js";
|
|
3
3
|
import { clip, stripControl, wrapText } from "./conversation.js";
|
|
4
|
+
import { approvalCard, cardHeader, statusTrack } from "./agent-cards.js";
|
|
4
5
|
/**
|
|
5
6
|
* How a proposed file change is shown before anyone approves it.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Source-control style: a summary of every file in the group, then each file
|
|
9
|
+
* with its operation, status and reason, then its hunks with old and new line
|
|
10
|
+
* numbers. Committed to the transcript rather than drawn in the prompt, so it
|
|
11
|
+
* stays on screen as the record of what was approved and a long one can be
|
|
12
|
+
* scrolled back to (PgUp/PgDn). Every changed line is shown in full — long
|
|
13
|
+
* lines wrap under the gutter, never clip — so the decision is made on the
|
|
14
|
+
* whole change. Signs (`+`/`-`) and gutters carry the meaning without color,
|
|
15
|
+
* so a terminal without color, or a copied transcript, reads the same.
|
|
16
|
+
*
|
|
17
|
+
* Everything here is display. The text comes from the plan the mutation layer
|
|
18
|
+
* computed from the current bytes on disk; the limits that decide whether a
|
|
19
|
+
* change is reviewable at all (size, sensitive files, containment) live there.
|
|
11
20
|
*/
|
|
12
21
|
const ACTION = {
|
|
13
22
|
create_file: "create",
|
|
@@ -16,7 +25,92 @@ const ACTION = {
|
|
|
16
25
|
delete_file: "delete",
|
|
17
26
|
revert_change: "revert"
|
|
18
27
|
};
|
|
19
|
-
|
|
28
|
+
/** Source-control status letter for the summary list. */
|
|
29
|
+
const STATUS = {
|
|
30
|
+
create_file: "A",
|
|
31
|
+
write_file: "M",
|
|
32
|
+
edit_file: "M",
|
|
33
|
+
delete_file: "D",
|
|
34
|
+
revert_change: "R"
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The reviewed diff as numbered lines, parsed from the plan's unified text.
|
|
38
|
+
*
|
|
39
|
+
* Numbers come from the hunk headers the diff engine wrote, so they are the
|
|
40
|
+
* real line numbers of the current file (old) and the proposed file (new).
|
|
41
|
+
*/
|
|
42
|
+
export function numberedLines(unified) {
|
|
43
|
+
const out = [];
|
|
44
|
+
let oldLine = 0;
|
|
45
|
+
let newLine = 0;
|
|
46
|
+
for (const raw of unified.split("\n")) {
|
|
47
|
+
if (raw.startsWith("+++") || raw.startsWith("---"))
|
|
48
|
+
continue;
|
|
49
|
+
const h = raw.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
|
50
|
+
if (h) {
|
|
51
|
+
// A zero-length side is written as "start-1,0"; the next line on that side is start.
|
|
52
|
+
oldLine = Number(h[2] === "0" ? Number(h[1]) + 1 : h[1]);
|
|
53
|
+
newLine = Number(h[4] === "0" ? Number(h[3]) + 1 : h[3]);
|
|
54
|
+
out.push({ kind: "hunk", text: raw });
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (!raw && out.length === 0)
|
|
58
|
+
continue;
|
|
59
|
+
const op = raw[0];
|
|
60
|
+
const text = raw.slice(1);
|
|
61
|
+
if (op === "-")
|
|
62
|
+
out.push({ kind: "-", oldLine: oldLine++, text });
|
|
63
|
+
else if (op === "+")
|
|
64
|
+
out.push({ kind: "+", newLine: newLine++, text });
|
|
65
|
+
else if (op === " ")
|
|
66
|
+
out.push({ kind: " ", oldLine: oldLine++, newLine: newLine++, text });
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
/** Split display text into chunks of at most `width` columns, by code point. */
|
|
71
|
+
function chunks(text, width) {
|
|
72
|
+
const w = Math.max(8, width);
|
|
73
|
+
if (visibleWidth(text) <= w)
|
|
74
|
+
return [text];
|
|
75
|
+
const out = [];
|
|
76
|
+
let cur = "";
|
|
77
|
+
for (const ch of text) {
|
|
78
|
+
if (visibleWidth(cur + ch) > w) {
|
|
79
|
+
out.push(cur);
|
|
80
|
+
cur = "";
|
|
81
|
+
}
|
|
82
|
+
cur += ch;
|
|
83
|
+
}
|
|
84
|
+
if (cur || !out.length)
|
|
85
|
+
out.push(cur);
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/** Hunk lines with a two-column gutter: sign, old number, new number, rule, code. */
|
|
89
|
+
function hunkLines(plan) {
|
|
90
|
+
const lines = numberedLines(plan.unified);
|
|
91
|
+
const widest = lines.reduce((n, l) => Math.max(n, l.oldLine ?? 0, l.newLine ?? 0), 0);
|
|
92
|
+
const w = Math.max(2, String(widest).length);
|
|
93
|
+
const room = contentWidth() - INDENT.length - (w * 2 + 6) + 1;
|
|
94
|
+
const out = [];
|
|
95
|
+
for (const l of lines) {
|
|
96
|
+
if (l.kind === "hunk") {
|
|
97
|
+
out.push(INDENT + c.accent(clip(safe(l.text), contentWidth() - INDENT.length + 1)));
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const oldNo = l.oldLine === undefined ? "".padStart(w) : String(l.oldLine).padStart(w);
|
|
101
|
+
const newNo = l.newLine === undefined ? "".padStart(w) : String(l.newLine).padStart(w);
|
|
102
|
+
const sign = l.kind === " " ? " " : l.kind;
|
|
103
|
+
const paint = l.kind === "+" ? c.ok : l.kind === "-" ? c.err : c.dim;
|
|
104
|
+
// Tabs and control bytes would misalign the gutter; show them visibly.
|
|
105
|
+
const text = safe(l.text).replace(/\t/g, " ");
|
|
106
|
+
const parts = chunks(text, room);
|
|
107
|
+
parts.forEach((part, i) => {
|
|
108
|
+
const gutter = i === 0 ? `${sign} ${oldNo} ${newNo} │ ` : ` ${"".padStart(w)} ${"".padStart(w)} ┆ `;
|
|
109
|
+
out.push(INDENT + paint(gutter + part));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
20
114
|
export function riskOf(plan) {
|
|
21
115
|
if (plan.name === "delete_file")
|
|
22
116
|
return "high";
|
|
@@ -27,61 +121,214 @@ export function riskOf(plan) {
|
|
|
27
121
|
const safe = stripControl;
|
|
28
122
|
const INDENT = MARGIN + " ";
|
|
29
123
|
const inner = () => Math.max(24, contentWidth() - 4);
|
|
30
|
-
|
|
124
|
+
/** Explanatory text, wrapped to the terminal at the given indent. */
|
|
125
|
+
const notes = (indent, text) => wrapText(text, Math.max(16, contentWidth() - indent.length - 1)).map((l) => indent + c.dim(l));
|
|
126
|
+
function planLines(plan, index, total, activeRoot) {
|
|
31
127
|
const risk = riskOf(plan);
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
128
|
+
const riskLabel = risk.toUpperCase();
|
|
129
|
+
const riskText = risk === "high" ? c.err(riskLabel) : risk === "medium" ? c.warn(riskLabel) : c.dim(riskLabel);
|
|
130
|
+
const counter = total > 1 ? `${index + 1}/${total} ` : "";
|
|
131
|
+
const hunks = plan.diff.hunks.length;
|
|
132
|
+
const out = [""];
|
|
133
|
+
// WHICH repository, ABOVE the path — a change can target a repository that is
|
|
134
|
+
// not the active one, so the name is part of what is being approved and must
|
|
135
|
+
// be read before the path it qualifies.
|
|
136
|
+
if (plan.repositoryName)
|
|
137
|
+
out.push(MARGIN + c.dim("Repository ") + c.value(safe(plan.repositoryName)));
|
|
138
|
+
// File boundary: the path (and its position in the group), never clipped —
|
|
139
|
+
// it is what is being approved.
|
|
140
|
+
const head = counter + safe(plan.rel);
|
|
141
|
+
for (const part of chunks(head, contentWidth() - MARGIN.length - 1))
|
|
142
|
+
out.push(MARGIN + c.file(part));
|
|
143
|
+
// The full location is part of what is approved: wrapped, never clipped.
|
|
144
|
+
if (plan.repositoryRoot && plan.repositoryRoot !== activeRoot) {
|
|
145
|
+
chunks(safe(plan.repositoryRoot), contentWidth() - INDENT.length - 10).forEach((part, i) => out.push(INDENT + c.dim(i === 0 ? "Location " : " ") + part));
|
|
46
146
|
}
|
|
47
147
|
if (plan.reverts)
|
|
48
148
|
out.push(INDENT + c.dim(`undoes ${plan.reverts}`));
|
|
49
|
-
for (const [i, l] of wrapText(safe(plan.reason), inner() - 8).entries()) {
|
|
50
|
-
out.push(INDENT + c.dim(i === 0 ? "Why " : " ") + c.dim(l));
|
|
51
|
-
}
|
|
52
149
|
out.push("");
|
|
53
150
|
if (plan.name === "delete_file") {
|
|
54
151
|
out.push(INDENT + c.err(`The whole file (${plan.diff.removed} lines) will be removed.`));
|
|
55
152
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
else if (l.startsWith("+++") || l.startsWith("---"))
|
|
61
|
-
continue; // the path is in the header
|
|
62
|
-
else if (l.startsWith("+"))
|
|
63
|
-
out.push(INDENT + c.ok(l));
|
|
64
|
-
else if (l.startsWith("-"))
|
|
65
|
-
out.push(INDENT + c.err(l));
|
|
66
|
-
else
|
|
67
|
-
out.push(INDENT + c.dim(l));
|
|
153
|
+
out.push(...hunkLines(plan));
|
|
154
|
+
if (plan.lineEndings) {
|
|
155
|
+
const { before, after } = plan.lineEndings;
|
|
156
|
+
out.push(INDENT + c.warn(`${plan.diff.hunks.length ? "Also changes" : "Changes only"} the line endings: ${before} → ${after}.`));
|
|
68
157
|
}
|
|
69
|
-
if (plan.diff.hunks.length === 0)
|
|
158
|
+
else if (plan.diff.hunks.length === 0)
|
|
70
159
|
out.push(INDENT + c.dim("(no line changes)"));
|
|
71
160
|
out.push("");
|
|
161
|
+
// Reason, the operation ID (the one the receipt, journal, audit events and
|
|
162
|
+
// Admin activity already use) and the risk: what the person is deciding on.
|
|
163
|
+
const field = (label, value, paint = c.value) => wrapText(value, Math.max(12, inner() - 14)).map((l, i) => INDENT + c.dim((i === 0 ? label : "").padEnd(14)) + paint(l));
|
|
164
|
+
out.push(...field("Reason", safe(plan.reason), c.dim));
|
|
165
|
+
out.push(...field("Operation ID", safe(plan.operationId)));
|
|
166
|
+
out.push(INDENT + c.dim("Risk".padEnd(14)) + riskText);
|
|
167
|
+
out.push(...field("Change", `${ACTION[plan.name] ?? "change"} · +${plan.diff.added} −${plan.diff.removed} · ${hunks} ${hunks === 1 ? "hunk" : "hunks"}`, c.dim));
|
|
72
168
|
return out;
|
|
73
169
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
170
|
+
/** The changed-files list: one row per file in the reviewed group, all expanded below. */
|
|
171
|
+
function fileList(plans) {
|
|
172
|
+
const added = plans.reduce((n, p) => n + p.diff.added, 0);
|
|
173
|
+
const removed = plans.reduce((n, p) => n + p.diff.removed, 0);
|
|
174
|
+
const pathWidth = Math.max(8, Math.min(48, contentWidth() - 24, plans.reduce((n, p) => Math.max(n, visibleWidth(safe(p.rel))), 0)));
|
|
175
|
+
return [
|
|
176
|
+
MARGIN + c.value(`${plans.length} file${plans.length === 1 ? "" : "s"} changed`) + c.dim(" · ") + c.ok(`+${added}`) + " " + c.err(`−${removed}`),
|
|
177
|
+
...(plans.length > 1
|
|
178
|
+
? plans.map((p) => INDENT + c.dim("▾ ") + c.warn(STATUS[p.name] ?? "M") + " " + c.file(clip(safe(p.rel), pathWidth).padEnd(pathWidth)) + c.dim(` +${p.diff.added} −${p.diff.removed}`))
|
|
179
|
+
: [])
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
export function renderGroup(plans, correction = false, remaining = 0, activeRoot) {
|
|
183
|
+
const files = plans.length;
|
|
184
|
+
const detail = correction
|
|
185
|
+
? `New diff from fresh reads after the failed validation — the earlier approval does not cover it. Nothing has been written yet (${files} file${files === 1 ? "" : "s"}).`
|
|
186
|
+
: `Nothing has been written yet (${files} file${files === 1 ? "" : "s"}). Tests run only after their own approval.`;
|
|
187
|
+
return [
|
|
188
|
+
...cardHeader(correction ? "CORRECTIVE CHANGE" : "PROPOSED CHANGE", c.title),
|
|
189
|
+
...(plans.length > 1 ? fileList(plans) : []),
|
|
190
|
+
...plans.flatMap((p, i) => planLines(p, i, plans.length, activeRoot)),
|
|
191
|
+
...(remaining ? ["", ...notes(MARGIN, `${remaining} other planned file${remaining === 1 ? "" : "s"} still require review.`)] : []),
|
|
192
|
+
...approvalCard(correction ? "correction" : "change", detail, []),
|
|
193
|
+
...notes(MARGIN, "PgUp/PgDn scrolls the diff."),
|
|
194
|
+
""
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
/** The card shown when an approved diff no longer matches the file on disk. */
|
|
198
|
+
export function renderNoLongerValid(rels) {
|
|
199
|
+
return [
|
|
200
|
+
...cardHeader("⚠ CHANGE INVALIDATED", c.warn),
|
|
201
|
+
...rels.flatMap((rel) => wrapText(`${safe(rel)} changed after this proposal.`, Math.max(16, contentWidth() - MARGIN.length - 1)).map((l) => MARGIN + c.value(l))),
|
|
202
|
+
...notes(MARGIN, "The approved diff is no longer based on the current file. No files were modified by it."),
|
|
203
|
+
...notes(MARGIN, "A fresh proposal and a new approval are required."),
|
|
204
|
+
""
|
|
205
|
+
];
|
|
206
|
+
}
|
|
207
|
+
/** The card shown when the person declines a proposed change. */
|
|
208
|
+
export function renderChangeRejected(plans) {
|
|
77
209
|
return [
|
|
78
|
-
"",
|
|
79
|
-
MARGIN + c.
|
|
80
|
-
|
|
81
|
-
|
|
210
|
+
...cardHeader("CHANGE REJECTED", c.warn),
|
|
211
|
+
MARGIN + c.value("No files were modified."),
|
|
212
|
+
...plans.map((p) => INDENT + c.file(safe(p.rel)) + c.dim(` · ${safe(p.operationId)}`)),
|
|
213
|
+
""
|
|
82
214
|
];
|
|
83
215
|
}
|
|
84
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* After a planned validation fails: what failed, and what happens next. Built
|
|
218
|
+
* from the workflow's own validation projection — the command identity and
|
|
219
|
+
* exit status it recorded — plus the counts the command result card read from
|
|
220
|
+
* the actual output. Never from model text.
|
|
221
|
+
*/
|
|
222
|
+
export function renderValidationFailed(snapshot, counts = "", failure) {
|
|
223
|
+
const validation = Array.isArray(snapshot.validation) ? snapshot.validation : [];
|
|
224
|
+
const tests = Array.isArray(snapshot.tests) ? snapshot.tests : [];
|
|
225
|
+
const failed = validation.filter((v) => v.status === "FAILED");
|
|
226
|
+
const failedCount = /(\d+) failed/.exec(counts)?.[1];
|
|
227
|
+
const out = [...cardHeader("✗ VALIDATION FAILED", c.err)];
|
|
228
|
+
if (failedCount)
|
|
229
|
+
out.push(MARGIN + c.err(`✗ ${failedCount} test${failedCount === "1" ? "" : "s"} failed`));
|
|
230
|
+
else if (counts)
|
|
231
|
+
out.push(MARGIN + c.dim(safe(counts)));
|
|
232
|
+
if (failure?.name)
|
|
233
|
+
out.push(...wrapText(safe(failure.name), inner()).map((l) => MARGIN + c.value(l)));
|
|
234
|
+
if (failure?.expected)
|
|
235
|
+
out.push(MARGIN + c.dim("Expected: ") + c.ok(clip(safe(failure.expected), Math.max(8, inner() - 12))));
|
|
236
|
+
if (failure?.received)
|
|
237
|
+
out.push(MARGIN + c.dim("Received: ") + c.err(clip(safe(failure.received), Math.max(8, inner() - 12))));
|
|
238
|
+
for (const v of failed) {
|
|
239
|
+
const args = Array.isArray(v.args) ? v.args.filter((a) => typeof a === "string") : [];
|
|
240
|
+
const exit = tests.find((t) => t.id === v.operation_id)?.exit;
|
|
241
|
+
out.push(MARGIN + c.dim(clip(safe([String(v.program ?? ""), ...args].join(" ")), inner() - 16) + ` · exit ${exit ?? "unknown"}`));
|
|
242
|
+
}
|
|
243
|
+
out.push(...notes(MARGIN, "A correction, if any, is a new diff with its own approval."), "");
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The coordinator's applied-change confirmations, laid out as an "applying"
|
|
248
|
+
* block. Display only: the coordinator's own text is parsed, never changed, and
|
|
249
|
+
* anything that is not an apply confirmation is shown as it was sent.
|
|
250
|
+
*/
|
|
251
|
+
const APPLIED_LINE = /^✓\s+(\S+)\s+(.+?)\s+\(\+(\d+)\s+−(\d+)\)\s+·\s+Applied\s+·\s+(\S+)$/;
|
|
85
252
|
export function renderChangeSummary(lines) {
|
|
86
|
-
|
|
253
|
+
const applied = lines.map((l) => APPLIED_LINE.exec(stripControl(l).trim())).filter((m) => !!m);
|
|
254
|
+
const other = lines.filter((l) => !APPLIED_LINE.test(stripControl(l).trim()));
|
|
255
|
+
const out = [];
|
|
256
|
+
if (applied.length) {
|
|
257
|
+
out.push("", MARGIN + c.title(applied.length === 1 ? "Applying change…" : `Applying ${applied.length} changes…`));
|
|
258
|
+
for (const [, verb, rel, added, removed] of applied) {
|
|
259
|
+
const what = verb === "Deleted" ? "File deleted" : verb === "Created" ? "File created" : "File updated";
|
|
260
|
+
const counts = ` +${added} −${removed}`;
|
|
261
|
+
const oneLine = `${MARGIN} ✓ ${what} · ${rel}${counts}`;
|
|
262
|
+
if (visibleWidth(oneLine) <= contentWidth() - 1) {
|
|
263
|
+
out.push(MARGIN + " " + c.ok("✓ ") + c.value(what) + c.dim(" · ") + c.file(rel) + c.dim(counts));
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
// A long path wraps on its own lines rather than running off the edge.
|
|
267
|
+
out.push(MARGIN + " " + c.ok("✓ ") + c.value(what) + c.dim(counts));
|
|
268
|
+
for (const part of chunks(rel, contentWidth() - MARGIN.length - 5))
|
|
269
|
+
out.push(MARGIN + " " + c.file(part));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
out.push(MARGIN + " " + c.ok("✓ ") + c.value(applied.length === 1 ? "Mutation completed" : "Mutations completed"));
|
|
273
|
+
for (const m of applied)
|
|
274
|
+
out.push(MARGIN + " " + c.dim("Operation ID: ") + c.value(m[5]));
|
|
275
|
+
}
|
|
276
|
+
for (const l of other)
|
|
277
|
+
out.push(MARGIN + (l.includes("✓") ? c.ok(l.trim()) : c.warn(l.trim())));
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
280
|
+
/** Bounded display projection of existing coordinator events, never an authority. */
|
|
281
|
+
export class ActiveChangeView {
|
|
282
|
+
snapshot;
|
|
283
|
+
paint;
|
|
284
|
+
entries = new Map();
|
|
285
|
+
lastActive;
|
|
286
|
+
constructor(snapshot, paint) {
|
|
287
|
+
this.snapshot = snapshot;
|
|
288
|
+
this.paint = paint;
|
|
289
|
+
}
|
|
290
|
+
review(plans) {
|
|
291
|
+
for (const plan of plans)
|
|
292
|
+
this.entries.set(plan.operationId, { plan: { ...plan }, status: "awaiting approval" });
|
|
293
|
+
while (this.entries.size > 8)
|
|
294
|
+
this.entries.delete(this.entries.keys().next().value);
|
|
295
|
+
this.refresh();
|
|
296
|
+
}
|
|
297
|
+
decision(plans, answer) {
|
|
298
|
+
for (const plan of plans) {
|
|
299
|
+
const entry = this.entries.get(plan.operationId);
|
|
300
|
+
if (entry)
|
|
301
|
+
entry.status = answer === "approve" ? "approved; awaiting verified result" : answer === "reject" ? "rejected" : answer;
|
|
302
|
+
}
|
|
303
|
+
this.refresh();
|
|
304
|
+
}
|
|
305
|
+
result(payload) {
|
|
306
|
+
const entry = this.entries.get(payload.tool_call_id);
|
|
307
|
+
if (entry)
|
|
308
|
+
entry.status = payload.ok ? "applied" : payload.error?.code === "MUTATION_REJECTED" ? "rejected" : payload.error?.code === "STALE_FILE" ? "invalidated" : payload.error?.code ?? "unresolved";
|
|
309
|
+
this.refresh();
|
|
310
|
+
}
|
|
311
|
+
commandStatus(value) { void value; this.refresh(); }
|
|
312
|
+
refresh() {
|
|
313
|
+
const state = this.snapshot();
|
|
314
|
+
// The status track appears once there is a coding plan; ordinary
|
|
315
|
+
// questions never get one. It is a projection of CodingWorkflow state.
|
|
316
|
+
if (!state.plan && !this.entries.size)
|
|
317
|
+
return;
|
|
318
|
+
const current = String(state.state ?? "");
|
|
319
|
+
if (!["FAILED", "CANCELLED", "UNRESOLVED"].includes(current))
|
|
320
|
+
this.lastActive = current;
|
|
321
|
+
const lines = [statusTrack(state, this.lastActive)];
|
|
322
|
+
const entries = [...this.entries.values()];
|
|
323
|
+
// Verification is the workflow's: shown only once a change is applied.
|
|
324
|
+
const validation = Array.isArray(state.validation) ? state.validation : [];
|
|
325
|
+
const verification = !validation.length ? "" : validation.every(v => v.status === "PASSED") ? "verification passed" : validation.some(v => v.status === "FAILED") ? "verification failed" : "verification pending";
|
|
326
|
+
for (const { plan, status } of entries.slice(-2)) {
|
|
327
|
+
lines.push(MARGIN + c.file(safe(plan.rel)) + c.dim(` · ${safe(status)}${status === "applied" && verification ? ` · ${verification}` : ""}`));
|
|
328
|
+
}
|
|
329
|
+
if (entries.length > 2)
|
|
330
|
+
lines.push(MARGIN + c.dim(`+${entries.length - 2} earlier changes · PgUp for reviews`));
|
|
331
|
+
this.paint(lines.map(l => clip(l, contentWidth())));
|
|
332
|
+
}
|
|
333
|
+
clear() { this.entries.clear(); this.lastActive = undefined; this.paint([]); }
|
|
87
334
|
}
|