@vecteur/cli 0.9.1 → 0.11.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.
- package/README.md +224 -15
- package/bin/vecteur.js +107 -10
- package/package.json +5 -1
- package/src/blocks.js +201 -6
- package/src/client.js +280 -29
- package/src/commands.js +56 -15
- package/src/contract.js +35 -7
- package/src/credentials.js +8 -0
- package/src/errors.js +4 -1
- package/src/exchange.js +85 -0
- package/src/executor.js +171 -0
- package/src/folders.js +28 -2
- package/src/format.js +332 -28
- package/src/input.js +22 -3
- package/src/localfiles.js +788 -0
- package/src/mcp.js +143 -9
- package/src/produce.js +49 -0
- package/src/session.js +697 -104
- package/src/terminal.js +189 -54
- package/src/tui/view.js +342 -124
package/src/tui/view.js
CHANGED
|
@@ -1,83 +1,192 @@
|
|
|
1
1
|
import stringWidth from "string-width";
|
|
2
2
|
import wrapAnsi from "wrap-ansi";
|
|
3
3
|
import { parseMarkdown } from "../markdown.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { blockContent } from "../blocks.js";
|
|
5
|
+
import { terminalText, plainLine, taskLines } from "../format.js";
|
|
6
|
+
|
|
7
|
+
// Unknown palette: the terminal owns its readable default pair. Only repeated metadata is faint.
|
|
8
|
+
export const DEFAULT_THEME = Object.freeze({ primary: "", accent: "1", attention: "1", success: "1", error: "1",
|
|
9
|
+
secondary: "", quiet: "2", rule: "", band: "", strong: "1", em: "3", link: "4" });
|
|
10
|
+
const themeOf = color => color === true ? DEFAULT_THEME : color || null;
|
|
11
|
+
const RESET = { 1: "22", 2: "22", 3: "23", 4: "24", 7: "27", 38: "39", 48: "49" };
|
|
12
|
+
// Targeted resets, never SGR 0: a role inside the input band must not clear the band.
|
|
13
|
+
const style = (value, code, theme) => {
|
|
14
|
+
if (!theme || !code || !value) return value;
|
|
15
|
+
const close = []; const parts = code.split(";");
|
|
16
|
+
for (let i = 0; i < parts.length; i++) {
|
|
17
|
+
const n = Number(parts[i]);
|
|
18
|
+
if (n === 38 || n === 48) { close.push(RESET[n]); i += parts[i + 1] === "5" ? 2 : 4; }
|
|
19
|
+
else close.push(RESET[n] ?? ((n >= 30 && n <= 37) || (n >= 90 && n <= 97) ? "39" : "0"));
|
|
20
|
+
}
|
|
21
|
+
return `\x1b[${code}m${value}\x1b[${[...new Set(close)].join(";")}m`;
|
|
22
|
+
};
|
|
23
|
+
const paint = (value, role = "primary", theme) => style(value, theme?.[role], theme);
|
|
24
|
+
|
|
25
|
+
// Terminal palette → roles. The reference values are blends of the terminal's own foreground
|
|
26
|
+
// toward its background; text roles are pulled back toward the foreground until they reach 4.5:1.
|
|
27
|
+
const channel = v => { v /= 255; return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; };
|
|
28
|
+
const luminance = ([r, g, b]) => 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
|
|
29
|
+
export const contrast = (a, b) => { const [x, y] = [luminance(a), luminance(b)].sort((p, q) => q - p); return (x + 0.05) / (y + 0.05); };
|
|
30
|
+
const mix = (from, to, t) => from.map((v, i) => Math.round(v + (to[i] - v) * t));
|
|
31
|
+
const cube = [0, 95, 135, 175, 215, 255];
|
|
32
|
+
function xterm256([r, g, b]) {
|
|
33
|
+
const near = v => cube.reduce((best, c, i) => Math.abs(c - v) < Math.abs(cube[best] - v) ? i : best, 0);
|
|
34
|
+
const [i, j, k] = [near(r), near(g), near(b)], rgb = [cube[i], cube[j], cube[k]];
|
|
35
|
+
const level = Math.max(0, Math.min(23, Math.round(((r + g + b) / 3 - 8) / 10))), grey = 8 + level * 10;
|
|
36
|
+
const distance = c => (c[0] - r) ** 2 + (c[1] - g) ** 2 + (c[2] - b) ** 2;
|
|
37
|
+
return distance([grey, grey, grey]) < distance(rgb) ? 232 + level : 16 + 36 * i + 6 * j + k;
|
|
38
|
+
}
|
|
39
|
+
// The colour a 256-colour terminal actually shows for an index.
|
|
40
|
+
const shown = index => index >= 232 ? Array(3).fill(8 + (index - 232) * 10)
|
|
41
|
+
: [Math.floor((index - 16) / 36), Math.floor((index - 16) / 6) % 6, (index - 16) % 6].map(i => cube[i]);
|
|
42
|
+
/** Fail loudly when no rendered colour satisfies the actual backgrounds. */
|
|
43
|
+
export function readable(from, grounds, { fg, render = rgb => rgb, excluded = [] } = {}) {
|
|
44
|
+
const allowed = rgb => grounds.every(ground => contrast(rgb, ground) >= 4.5)
|
|
45
|
+
&& !excluded.some(other => other.every((channel, index) => channel === rgb[index]));
|
|
46
|
+
for (const toward of [fg ?? from, [0, 0, 0], [255, 255, 255]]) {
|
|
47
|
+
for (let step = 0; step <= 100; step++) {
|
|
48
|
+
const value = render(mix(from, toward, step / 100));
|
|
49
|
+
if (allowed(value)) return value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Near-threshold palettes can exhaust a blend's quantized colours. Search rendered candidates too.
|
|
53
|
+
const levels = [0, 32, 64, 96, 128, 160, 192, 224, 255];
|
|
54
|
+
const candidates = levels.flatMap(r => levels.flatMap(g => levels.map(b => render([r, g, b]))));
|
|
55
|
+
candidates.sort((a, b) => a.reduce((sum, v, i) => sum + (v - from[i]) ** 2, 0)
|
|
56
|
+
- b.reduce((sum, v, i) => sum + (v - from[i]) ** 2, 0));
|
|
57
|
+
const found = candidates.find(allowed);
|
|
58
|
+
if (found) return found;
|
|
59
|
+
throw new RangeError("No readable rendered colour at 4.5:1 for these backgrounds");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function paletteTheme({ fg, bg, red, green }, truecolor = false) {
|
|
63
|
+
const render = rgb => truecolor ? rgb : shown(xterm256(rgb));
|
|
64
|
+
const code = (rgb, layer = 38) => truecolor ? `${layer};2;${rgb.join(";")}` : `${layer};5;${xterm256(rgb)}`;
|
|
65
|
+
const band = render(mix(fg, bg, 0.88));
|
|
66
|
+
const grounds = [bg, band], used = [];
|
|
67
|
+
const pick = (base, distinct = false) => {
|
|
68
|
+
const value = readable(base, grounds, { fg, render, excluded: distinct ? used : [] });
|
|
69
|
+
if (distinct) used.push(value);
|
|
70
|
+
return code(value);
|
|
71
|
+
};
|
|
72
|
+
const dark = luminance(bg) < 0.4;
|
|
73
|
+
const primary = pick(fg);
|
|
74
|
+
return Object.freeze({
|
|
75
|
+
primary, strong: `1;${primary}`, em: `3;${primary}`, link: `4;${primary}`,
|
|
76
|
+
accent: pick(dark ? [105, 215, 239] : [0, 120, 150], true),
|
|
77
|
+
success: pick(green ?? (dark ? [100, 220, 130] : [0, 115, 45]), true),
|
|
78
|
+
error: pick(red ?? (dark ? [255, 135, 150] : [175, 30, 55]), true),
|
|
79
|
+
secondary: pick(mix(fg, bg, 0.25), true),
|
|
80
|
+
attention: pick(dark ? [233, 173, 12] : [154, 103, 0]),
|
|
81
|
+
quiet: pick(mix(fg, bg, 0.42)), rule: pick(mix(fg, bg, 0.62)), band: code(band, 48),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
8
85
|
const SPINNER = ["·", "✢", "✳", "✶", "✻", "✽", "✻", "✶", "✳", "✢"];
|
|
86
|
+
const PROSE = 88; // readable measure on wide terminals; tables and code may use the full width
|
|
87
|
+
const NEW_PROJECT = "New Project on first send";
|
|
9
88
|
const printableAscii = /^[\x20-\x7e]*$/;
|
|
10
89
|
const measure = value => printableAscii.test(value) ? value.length : stringWidth(value);
|
|
90
|
+
// Each wrapped row closes whatever style is still open and the next row reopens it: a role never
|
|
91
|
+
// rides a line feed into a row that is later dropped or drawn by someone else (wrap-ansi only
|
|
92
|
+
// re-closes the 16-colour codes, not 256/truecolor ones).
|
|
93
|
+
const CLOSE = { 1: "22", 2: "22", 3: "23", 4: "24", 7: "27" };
|
|
94
|
+
function seal(lines) {
|
|
95
|
+
let open = [];
|
|
96
|
+
return lines.map(line => {
|
|
97
|
+
const head = open.length ? `\x1b[${open.join(";")}m` : "";
|
|
98
|
+
for (const [, list] of line.matchAll(/\x1b\[([0-9;]*)m/g)) {
|
|
99
|
+
const parts = list.split(";");
|
|
100
|
+
for (let i = 0; i < parts.length; i++) {
|
|
101
|
+
const n = Number(parts[i] || 0);
|
|
102
|
+
if (n === 38 || n === 48) { const width = parts[i + 1] === "5" ? 3 : 5; open = open.filter(g => !g.startsWith(`${n};`)); open.push(parts.slice(i, i + width).join(";")); i += width - 1; }
|
|
103
|
+
else if (n === 0) open = [];
|
|
104
|
+
else if (n === 39 || n === 49) open = open.filter(g => !g.startsWith(n === 39 ? "38;" : "48;") && !(n === 39 ? /^(3[0-7]|9[0-7])$/ : /^(4[0-7]|10[0-7])$/).test(g));
|
|
105
|
+
else if (["22", "23", "24", "27"].includes(String(n))) open = open.filter(g => CLOSE[g] !== String(n));
|
|
106
|
+
else open.push(String(n));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const tail = open.length ? `\x1b[${[...new Set(open.map(g => CLOSE[g] ?? (g.startsWith("48") || /^(4[0-7]|10[0-7])$/.test(g) ? "49" : "39")))].join(";")}m` : "";
|
|
110
|
+
return head + line + tail;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Cached wraps own only immutable text rows; each caller receives a separate array.
|
|
11
114
|
const wrapped = new Map();
|
|
12
115
|
const wrap = (value, width, wordWrap = true) => {
|
|
13
116
|
width = Math.max(1, width);
|
|
14
117
|
const key = value.length <= 512 ? `${width}:${wordWrap}:${value}` : null;
|
|
15
|
-
if (key && wrapped.has(key)) return wrapped.get(key);
|
|
118
|
+
if (key && wrapped.has(key)) return [...wrapped.get(key)];
|
|
16
119
|
const lines = !value.includes("\n") && measure(value) <= width ? [value]
|
|
17
|
-
: wrapAnsi(value, width, { hard: true, trim: false, wordWrap }).split("\n");
|
|
120
|
+
: seal(wrapAnsi(value, width, { hard: true, trim: false, wordWrap }).split("\n"));
|
|
18
121
|
if (key) {
|
|
19
122
|
if (wrapped.size === 128) wrapped.delete(wrapped.keys().next().value);
|
|
20
|
-
wrapped.set(key, lines);
|
|
123
|
+
wrapped.set(key, Object.freeze([...lines]));
|
|
21
124
|
}
|
|
22
125
|
return lines;
|
|
23
126
|
};
|
|
24
127
|
// Prose wraps at word boundaries and drops the break's leading space; the composer keeps every space.
|
|
25
|
-
const prose = (value, width) => wrapAnsi(value, Math.max(1, width), { hard: true, trim: true }).split("\n");
|
|
128
|
+
const prose = (value, width) => seal(wrapAnsi(value, Math.max(1, width), { hard: true, trim: true }).split("\n"));
|
|
129
|
+
// Key hints fold between their " · " segments, never inside one ("? shortcuts" stays whole).
|
|
130
|
+
const fold = (text, width) => text.split("\n").flatMap(part => part.split(" · ").reduce((rows, segment) => {
|
|
131
|
+
if (rows.length && measure(rows.at(-1)) + 3 + measure(segment) <= width) rows[rows.length - 1] += " · " + segment;
|
|
132
|
+
else rows.push(segment);
|
|
133
|
+
return rows;
|
|
134
|
+
}, [])).flatMap(row => wrap(row, width));
|
|
26
135
|
const pad = (value, width) => value + " ".repeat(Math.max(0, width - measure(value)));
|
|
27
136
|
|
|
28
|
-
function inline(tokens,
|
|
137
|
+
function inline(tokens, theme) {
|
|
29
138
|
return tokens.map(token => {
|
|
30
139
|
const href = token.href && /^https?:\/\//i.test(token.href) ? ` <${token.href}>` : "";
|
|
31
140
|
const value = token.text + href;
|
|
32
|
-
return token.kind === "strong" ?
|
|
33
|
-
: token.kind === "em" ?
|
|
34
|
-
: token.kind === "code" ?
|
|
35
|
-
: token.kind === "link" ?
|
|
141
|
+
return token.kind === "strong" ? paint(value, "strong", theme)
|
|
142
|
+
: token.kind === "em" ? paint(value, "em", theme)
|
|
143
|
+
: token.kind === "code" ? paint(value, "accent", theme)
|
|
144
|
+
: token.kind === "link" ? paint(value, "link", theme) : paint(value, "primary", theme);
|
|
36
145
|
}).join("");
|
|
37
146
|
}
|
|
38
147
|
|
|
39
148
|
const numeric = /^[-+−~≈<>≤≥±]?\s?\d[\d.,]*(?:\s?[^\s\d]\S*)?$/;
|
|
40
|
-
function table(block, width,
|
|
41
|
-
const grid = [block.header, ...block.rows].map(row => row.map(cell => inline(cell,
|
|
149
|
+
function table(block, width, theme) {
|
|
150
|
+
const grid = [block.header, ...block.rows].map(row => row.map(cell => inline(cell, null)));
|
|
42
151
|
const columns = Math.max(...grid.map(row => row.length));
|
|
43
152
|
const widths = Array.from({ length: columns }, (_, i) => Math.max(1, ...grid.map(row => measure(row[i] ?? ""))));
|
|
44
153
|
if (widths.reduce((a, b) => a + b, 0) + 3 * (columns - 1) > width) {
|
|
45
154
|
// Too wide for the terminal: one record per row, never a clipped column.
|
|
46
155
|
const lines = [];
|
|
47
156
|
block.rows.forEach((row, index) => {
|
|
48
|
-
lines.push(
|
|
49
|
-
row.forEach((cell, column) => lines.push(...wrap(`${
|
|
157
|
+
lines.push(paint(`Record ${index + 1}`, "strong", theme));
|
|
158
|
+
row.forEach((cell, column) => lines.push(...wrap(`${paint(grid[0]?.[column] || `Column ${column + 1}`, "secondary", theme)} ${inline(cell, theme)}`, width)));
|
|
50
159
|
});
|
|
51
160
|
return lines;
|
|
52
161
|
}
|
|
53
|
-
const right = widths.map((_, i) => block.rows.length > 0 && block.rows.every(row => numeric.test(inline(row[i] ?? [],
|
|
162
|
+
const right = widths.map((_, i) => block.rows.length > 0 && block.rows.every(row => numeric.test(inline(row[i] ?? [], null).trim() || "0")));
|
|
54
163
|
const cell = (value, i) => right[i] ? " ".repeat(Math.max(0, widths[i] - measure(value))) + value : pad(value, widths[i]);
|
|
55
|
-
const bar =
|
|
56
|
-
return [
|
|
57
|
-
|
|
58
|
-
...grid.slice(1).map(row => widths.map((_, i) => cell(row[i] ?? "", i)).join(bar))];
|
|
164
|
+
const bar = paint(" │ ", "rule", theme);
|
|
165
|
+
return [paint(grid[0].map((value, i) => pad(value, widths[i])).join(" │ "), "strong", theme),
|
|
166
|
+
paint(widths.map(w => "─".repeat(w)).join("─┼─"), "rule", theme),
|
|
167
|
+
...grid.slice(1).map(row => widths.map((_, i) => paint(cell(row[i] ?? "", i), "primary", theme)).join(bar))];
|
|
59
168
|
}
|
|
60
169
|
|
|
61
170
|
/** Shared web grammar; only trusted renderer styling can emit terminal controls. */
|
|
62
171
|
export function markdownView(source, width, color = true) {
|
|
63
|
-
const lines = [];
|
|
172
|
+
const theme = themeOf(color), lines = [], measureWidth = Math.min(width, PROSE);
|
|
64
173
|
for (const block of parseMarkdown(terminalText(source))) {
|
|
65
|
-
if (block.kind === "table") lines.push(...table(block, width,
|
|
174
|
+
if (block.kind === "table") lines.push(...table(block, width, theme));
|
|
66
175
|
else if (block.kind === "codeblock") {
|
|
67
|
-
if (block.language) lines.push(
|
|
68
|
-
lines.push(...wrap(block.text, width - 2, false).map(line =>
|
|
176
|
+
if (block.language) lines.push(paint(block.language, "quiet", theme));
|
|
177
|
+
lines.push(...wrap(block.text, width - 2, false).map(line => paint("│ ", "rule", theme) + paint(line, "primary", theme)));
|
|
69
178
|
} else if (block.kind === "hr") {
|
|
70
|
-
lines.push(
|
|
179
|
+
lines.push(paint("─".repeat(Math.min(width, 48)), "rule", theme));
|
|
71
180
|
} else if (block.kind === "list") {
|
|
72
181
|
block.items.forEach((item, index) => {
|
|
73
182
|
const prefix = block.ordered ? `${index + 1}. ` : "• ";
|
|
74
|
-
prose(inline(item,
|
|
183
|
+
prose(inline(item, theme), measureWidth - prefix.length).forEach((line, i) => lines.push((i ? " ".repeat(prefix.length) : paint(prefix, "quiet", theme)) + line));
|
|
75
184
|
});
|
|
76
185
|
} else {
|
|
77
|
-
let value = inline(block.inline,
|
|
78
|
-
if (block.kind === "heading") value =
|
|
79
|
-
if (block.kind === "quote") lines.push(...prose(value,
|
|
80
|
-
else lines.push(...prose(value,
|
|
186
|
+
let value = inline(block.inline, theme);
|
|
187
|
+
if (block.kind === "heading") value = paint(value, "strong", theme);
|
|
188
|
+
if (block.kind === "quote") lines.push(...prose(value, measureWidth - 2).map(line => paint("│ ", "rule", theme) + line));
|
|
189
|
+
else lines.push(...prose(value, measureWidth));
|
|
81
190
|
}
|
|
82
191
|
lines.push("");
|
|
83
192
|
}
|
|
@@ -88,7 +197,7 @@ export function markdownView(source, width, color = true) {
|
|
|
88
197
|
// One terminal owns this cache. Cursor movement never rewraps unrelated paragraphs.
|
|
89
198
|
let composerText;
|
|
90
199
|
const composerLayouts = new Map();
|
|
91
|
-
function composerViewport(composer, cursor, width, height) {
|
|
200
|
+
function composerViewport(composer, cursor, width, height, theme) {
|
|
92
201
|
if (composerText !== composer) { composerLayouts.clear(); composerText = composer; }
|
|
93
202
|
let composerLayout = composerLayouts.get(width);
|
|
94
203
|
if (!composerLayout) {
|
|
@@ -105,7 +214,9 @@ function composerViewport(composer, cursor, width, height) {
|
|
|
105
214
|
const paragraph = paragraphs.findLast(row => row.offset <= cursor) ?? paragraphs[0];
|
|
106
215
|
const local = cursor - paragraph.offset;
|
|
107
216
|
const before = terminalText(paragraph.text.slice(0, local));
|
|
108
|
-
|
|
217
|
+
// The caret is the one accent mark inside the input: wrapped on its plain glyph, painted after.
|
|
218
|
+
const active = wrap(before + "▌" + terminalText(paragraph.text.slice(local)), width, false)
|
|
219
|
+
.map(line => line.replace("▌", paint("▌", "accent", theme)));
|
|
109
220
|
const cursorRow = paragraph.row + wrap(before + "▌", width, false).length - 1;
|
|
110
221
|
const start = Math.max(0, cursorRow - height + 1);
|
|
111
222
|
const next = paragraphs[paragraphs.indexOf(paragraph) + 1]?.row ?? lines.length;
|
|
@@ -115,27 +226,14 @@ function composerViewport(composer, cursor, width, height) {
|
|
|
115
226
|
scrolling: lines.length > height };
|
|
116
227
|
}
|
|
117
228
|
|
|
118
|
-
/**
|
|
119
|
-
function
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return style(left + text + "─".repeat(Math.max(0, width - 2 - measure(text))) + right, DIM, color);
|
|
229
|
+
/** The composer: a filled input band between two rules; a label may sit in either rule. */
|
|
230
|
+
function composerBand(rows, width, theme, { top = "", bottom = "" } = {}) {
|
|
231
|
+
const rule = label => {
|
|
232
|
+
const text = label ? `── ${trimEnd(label, width - 4)} ` : "";
|
|
233
|
+
return paint(text + "─".repeat(Math.max(0, width - measure(text))), "rule", theme);
|
|
124
234
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** The once-printed welcome: one calm box, a single accent glyph, no ASCII logo. */
|
|
130
|
-
export function welcome(version, origin, columns = 80, color = true, channel, folder) {
|
|
131
|
-
const width = Math.max(20, columns - 1), inner = width - 4;
|
|
132
|
-
const label = `${version}${channel === "preview" ? " · Preview" : ""}`;
|
|
133
|
-
const where = [folder, origin === "https://vecteur.space" ? "" : origin].filter(Boolean).map(terminalText).join(" · ");
|
|
134
|
-
const head = `${style("▼", ACCENT, color)} ${style("Vecteur", "1", color)} ${style(label, DIM, color)}`;
|
|
135
|
-
const lines = measure(`▼ Vecteur ${label} · Laplace · Vecteur cloud`) <= inner
|
|
136
|
-
? [`${head} ${style("· Laplace · Vecteur cloud", DIM, color)}`] : [head];
|
|
137
|
-
if (where) lines.push(style(trimEnd(` ${where}`, inner), DIM, color));
|
|
138
|
-
return box(lines, width, color).join("\n") + "\n";
|
|
235
|
+
const band = theme?.band;
|
|
236
|
+
return [rule(top), ...rows.map(row => band ? style(pad(row, width), band, theme) : row), rule(bottom)];
|
|
139
237
|
}
|
|
140
238
|
|
|
141
239
|
// Display-cell truncation with an ellipsis; never more work than the visible width needs.
|
|
@@ -155,36 +253,82 @@ function trimStart(value, max) {
|
|
|
155
253
|
return "…" + chars.join("");
|
|
156
254
|
}
|
|
157
255
|
|
|
158
|
-
|
|
159
|
-
|
|
256
|
+
const execution = view => view.location && view.location !== "Vecteur cloud" ? view.location : "Cloud";
|
|
257
|
+
const routeOf = view => `${view.lead ? `${view.lead} · ` : ""}${view.model} · ${execution(view)}`;
|
|
258
|
+
const customOrigin = view => view.origin && view.origin !== "https://vecteur.space" ? view.origin : "";
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Identity: `▼ Vecteur <version>` and the folder, the route group on the right (beneath when
|
|
262
|
+
* narrow). Live while the transcript is empty, then committed once to scrollback.
|
|
263
|
+
*/
|
|
264
|
+
export function richHeader(view, columns = 80, color = true) {
|
|
265
|
+
const theme = themeOf(color), width = Math.max(20, columns - 1);
|
|
266
|
+
const label = `${view.version ?? ""}${view.channel === "preview" ? " · Preview" : ""}`;
|
|
267
|
+
const brand = `${paint("▼", "accent", theme)} ${paint("Vecteur", "strong", theme)} ${paint(label, "quiet", theme)}`;
|
|
268
|
+
const brandWidth = measure(`▼ Vecteur ${label}`);
|
|
269
|
+
// Only a signed-in, online session earns the filled dot; it claims nothing about a server.
|
|
270
|
+
const live = !!view.account && !view.offline;
|
|
271
|
+
const route = trimEnd(routeOf(view), width - 4);
|
|
272
|
+
const routeText = `${paint(live ? "●" : "○", live ? "accent" : "quiet", theme)} ${paint(route, "secondary", theme)}`;
|
|
273
|
+
const routeWidth = measure(route) + 2;
|
|
274
|
+
const lines = ["", brandWidth + 4 + routeWidth <= width
|
|
275
|
+
? brand + " ".repeat(width - brandWidth - routeWidth) + routeText : brand];
|
|
276
|
+
// A non-production origin is never hidden for visual simplicity.
|
|
277
|
+
const origin = customOrigin(view), directory = view.directory ? terminalText(view.directory) : "";
|
|
278
|
+
if (directory && origin && measure(directory) + 3 + measure(origin) <= width - 2) {
|
|
279
|
+
lines.push(` ${paint(directory, "quiet", theme)}${paint(" · ", "quiet", theme)}${paint(terminalText(origin), "accent", theme)}`);
|
|
280
|
+
} else {
|
|
281
|
+
if (directory) lines.push(" " + paint(trimStart(directory, width - 2), "quiet", theme));
|
|
282
|
+
if (origin) lines.push(" " + paint(trimEnd(origin, width - 2), "accent", theme));
|
|
283
|
+
}
|
|
284
|
+
if (lines[1] === brand) lines.push(" " + routeText);
|
|
285
|
+
return lines;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// First-use suggestions are plain text, never a menu; existing commands stay authoritative.
|
|
289
|
+
const ONBOARDING = ["Review a mission brief and find the missing inputs",
|
|
290
|
+
"Compare orbit options for an Earth-observation mission", "Turn requirements into an analysis plan"];
|
|
291
|
+
|
|
292
|
+
/** The live region: `top` (identity, first-use note) above a flexible gap, `bottom` anchored. */
|
|
293
|
+
export function richLayout(view, composer, cursor, options = {}) {
|
|
294
|
+
const { columns = 80, rows = 24, color = true, tick = null } = options;
|
|
295
|
+
const theme = themeOf(color);
|
|
160
296
|
const width = Math.max(20, columns - 1), budget = Math.max(1, rows - 3);
|
|
161
297
|
const active = !!view.run?.subject && !view.run.terminal;
|
|
298
|
+
const pending = view.run?.blocks?.find(block => !block.committed && block.calls);
|
|
299
|
+
const pendingContent = pending ? blockContent(pending) : null;
|
|
300
|
+
// Compact layouts reserve their activity row for the open call, including its state.
|
|
301
|
+
const callSummary = pendingContent ? `${pendingContent.tool} ${trimEnd(plainLine(pendingContent.title),
|
|
302
|
+
Math.max(1, width - measure(`${pendingContent.tool} · ${pendingContent.status}`)))} · ${pendingContent.status}` : null;
|
|
162
303
|
const readOnly = view.project?.role === "VIEWER", signedOut = view.offline || !view.account;
|
|
163
304
|
const glyph = tick === null ? "●" : SPINNER[tick % SPINNER.length];
|
|
164
305
|
const runHint = readOnly ? "Read-only · /help · Ctrl+D detach"
|
|
165
306
|
: signedOut ? `${view.offline ? "/resume" : "/login"} · /help · Ctrl+D detach`
|
|
166
307
|
: `${view.run?.question ? "/answer" : "/steer · /answer-now"} · /help${width < 60 ? "\n" : " · "}Esc twice cancel · Ctrl+D detach`;
|
|
308
|
+
const idleHint = `${readOnly ? "Read-only · /project" : signedOut ? "Enter sign in" : view.busy ? "Please wait" : "Enter send"} · / commands · ? shortcuts`;
|
|
167
309
|
if (rows < 12) {
|
|
168
310
|
const focus = view.focus ?? view.prompt;
|
|
169
311
|
const choices = view.choices ?? focus?.options ?? view.palette ?? [];
|
|
170
312
|
const selected = Math.min(view.selected ?? view.paletteSelected ?? 0, Math.max(0, choices.length - 1));
|
|
171
313
|
const choice = choices[selected];
|
|
172
314
|
const content = focus?.title ?? (view.login ? `Sign in · Code ${view.login.user_code}` : view.issue?.text
|
|
173
|
-
?? (active ? `${view.run.elapsed ?? "Elapsed unavailable"} · ${view.status}` : view.status));
|
|
315
|
+
?? view.egress ?? (active ? callSummary ?? `${view.run.elapsed ?? "Elapsed unavailable"} · ${view.status}` : view.status));
|
|
174
316
|
const status = wrap(terminalText(content), width).slice(0, 1);
|
|
317
|
+
if (active && callSummary && content !== callSummary) status.push(callSummary);
|
|
175
318
|
if (choice) status.push(wrap(terminalText(`› ${selected + 1}/${choices.length} ${choice.label ?? '/' + choice.name}`), width)[0]);
|
|
176
319
|
else if (view.login) status.push(['› Open browser', '› Copy link', '› Work offline'][view.loginAction ?? 0]);
|
|
177
|
-
const draft = composerViewport(composer, cursor, width - 2, 1).lines[0];
|
|
320
|
+
const draft = composerViewport(composer, cursor, width - 2, 1, theme).lines[0];
|
|
178
321
|
const hint = focus || choices.length ? '↑↓ Enter choose · Esc back' : view.login ? 'Tab actions · Enter open · Esc offline'
|
|
179
|
-
: active ? runHint :
|
|
180
|
-
return [...status, `${
|
|
322
|
+
: active ? runHint : idleHint;
|
|
323
|
+
return { top: [], bottom: [...status.map(row => paint(row, "primary", theme)), `${paint("›", "accent", theme)} ${paint(draft, "primary", theme)}`,
|
|
324
|
+
...fold(hint, width).slice(0, 2).map(row => paint(row, "secondary", theme))].slice(0, budget) };
|
|
181
325
|
}
|
|
182
|
-
if (rows < 8) return wrap(`${view.status} · Ctrl+D exit`, width).slice(0, budget).join("\n");
|
|
183
|
-
const project = view.projectLabel ?? view.project?.name ?? "New Project on first send";
|
|
184
326
|
// The steady footer names the Workspace, never a personal address; /status shows the account.
|
|
185
327
|
const workspaces = view.account?.workspaces ?? [];
|
|
186
328
|
const account = view.account ? (workspaces.find(row => row.id === view.project?.workspace_id) ?? workspaces[0])?.name ?? "Signed in"
|
|
187
329
|
: view.offline ? "Offline" : "Not signed in";
|
|
330
|
+
const projectLabel = view.projectLabel ?? view.project?.name ?? NEW_PROJECT;
|
|
331
|
+
const identity = `${account} · ${projectLabel === NEW_PROJECT ? "New project" : projectLabel}`;
|
|
188
332
|
const compact = width < 60 || rows < 18;
|
|
189
333
|
const prompt = view.focus ?? view.prompt;
|
|
190
334
|
const compactFocus = rows < 24 && (view.focus || view.prompt || view.login || view.palette?.length || view.issue);
|
|
@@ -194,44 +338,52 @@ export function richFrame(view, composer, cursor, { columns = 80, rows = 24, col
|
|
|
194
338
|
const hint = prompt ? prompt.multiple ? "Space toggle · ↑↓ move · Enter confirm · Esc back" : "↑↓ choose · Enter confirm · Esc back · Ctrl+D exit"
|
|
195
339
|
: view.login ? "Tab actions · Enter on empty activates · Esc offline"
|
|
196
340
|
: view.palette?.length ? "↑↓ choose · Tab complete · Enter open · Esc close"
|
|
197
|
-
: active ? runHint
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const identity = trimEnd(`${project === "New Project on first send" ? "New Project" : project} · ${account}`, width);
|
|
204
|
-
const where = trimStart(view.folder ?? ".", Math.max(6, width - measure(identity) - measure(context) - 7));
|
|
205
|
-
const left = where === "." ? identity : `${identity} · ${where}`;
|
|
206
|
-
if (!compact && measure(left) + measure(context) + 4 <= width) {
|
|
207
|
-
footer.push(" " + style(left + " ".repeat(width - 2 - measure(left) - measure(context)) + context, DIM, color));
|
|
341
|
+
: active ? runHint : idleHint;
|
|
342
|
+
// While the identity header is live it owns the route and origin; afterwards the footer does.
|
|
343
|
+
const context = view.header ? identity : compact ? routeOf(view) : `${identity} · ${routeOf(view)}`;
|
|
344
|
+
const footer = [];
|
|
345
|
+
if (!compact && !hint.includes("\n") && measure(context) + 3 + measure(hint) <= width) {
|
|
346
|
+
footer.push(paint(context, "secondary", theme) + " ".repeat(width - measure(context) - measure(hint)) + paint(hint, "quiet", theme));
|
|
208
347
|
} else {
|
|
209
|
-
footer.push(
|
|
210
|
-
|
|
348
|
+
footer.push(...fold(hint, width).slice(0, 2).map(row => paint(row, "quiet", theme)));
|
|
349
|
+
footer.push(paint(trimEnd(context, width), "secondary", theme));
|
|
211
350
|
}
|
|
212
|
-
if (view.
|
|
351
|
+
if (!view.header && customOrigin(view)) footer.push(paint(trimEnd(customOrigin(view), width), "accent", theme));
|
|
213
352
|
|
|
214
353
|
// A breathing line between the scrollback and the live area when the window has room for it.
|
|
215
354
|
const lines = rows >= 18 && !compactFocus ? [""] : [];
|
|
216
355
|
const room = () => budget - footer.length - 3 - lines.length;
|
|
217
|
-
const line = (value,
|
|
356
|
+
const line = (value, role, limit = 2) => {
|
|
218
357
|
const text = terminalText(value);
|
|
219
|
-
lines.push(...wrap(
|
|
358
|
+
lines.push(...wrap(text, width).slice(0, Math.max(0, Math.min(limit, room()))).map(row => paint(row, role, theme)));
|
|
220
359
|
};
|
|
360
|
+
if (active && compactFocus && compactRun && pending) line(callSummary, "attention", 1);
|
|
221
361
|
// Activity: the one animated glyph, the current step and the server-anchored clock.
|
|
222
362
|
if (active && !compactFocus) {
|
|
223
363
|
const clock = view.run.elapsed ?? "Elapsed unavailable";
|
|
224
|
-
const doing = compactRun ? view.status : (view.run.progress || "Working").replace(/^Starting: (.+)$/, "$1") + "…";
|
|
225
|
-
const head = `${
|
|
226
|
-
if (measure(`${glyph} ${terminalText(doing)} · ${terminalText(clock)}`) <= width) lines.push(`${head} ${
|
|
227
|
-
else if (compactRun) lines.push(wrap(head, width)[0], ` ${tail}`);
|
|
228
|
-
else lines.push(wrap(`${
|
|
229
|
-
if (!compactRun && view.status && view.status !== "Running") line(view.status
|
|
364
|
+
const doing = compactRun ? callSummary ?? view.status : (view.run.progress || "Working").replace(/^Starting: (.+)$/, "$1").replace(/[.…]+$/, "") + "…";
|
|
365
|
+
const head = `${paint(glyph, "accent", theme)} ${paint(terminalText(doing), "primary", theme)}`, tail = paint(terminalText(clock), "quiet", theme);
|
|
366
|
+
if (measure(`${glyph} ${terminalText(doing)} · ${terminalText(clock)}`) <= width) lines.push(`${head} ${paint("·", "quiet", theme)} ${tail}`);
|
|
367
|
+
else if (compactRun) lines.push(callSummary ? paint(terminalText(doing), "attention", theme) : wrap(head, width)[0], ` ${tail}`);
|
|
368
|
+
else lines.push(wrap(`${paint(glyph, "accent", theme)} ${tail} · ${paint(terminalText(doing), "primary", theme)}`, width)[0]);
|
|
369
|
+
if (!compactRun && view.status && view.status !== "Running") line(` ${view.status}`, "secondary", 1);
|
|
370
|
+
}
|
|
371
|
+
if (active && !compactFocus && !compactRun) {
|
|
372
|
+
const pending = view.run.blocks?.find(block => !block.committed && block.calls);
|
|
373
|
+
if (pending) {
|
|
374
|
+
const content = blockContent(pending);
|
|
375
|
+
line(` ${content.tool} ${content.title} · ${content.status}`, "attention", 1);
|
|
376
|
+
if (pending.kind === "sources") line(` ${content.rows.join(" · ")}`, "secondary", 1);
|
|
377
|
+
}
|
|
378
|
+
for (const block of view.run.blocks?.filter(block => block.kind === "control") ?? []) {
|
|
379
|
+
const c = blockContent(block);
|
|
380
|
+
line(` ${c.title} · ${c.rows.join(" · ")}`, "secondary", 1);
|
|
381
|
+
}
|
|
230
382
|
}
|
|
231
383
|
if (!compactFocus && !compactRun && view.run?.question) line(readOnly ? "Waiting for an editor to answer"
|
|
232
|
-
: signedOut ? "Question pending — reconnect to answer" : "Your answer is needed · /answer",
|
|
384
|
+
: signedOut ? "Question pending — reconnect to answer" : "Your answer is needed · /answer", "attention", 1);
|
|
233
385
|
if (prompt) {
|
|
234
|
-
line(prompt.title, "
|
|
386
|
+
line(prompt.title, "strong", compactFocus ? 1 : 3);
|
|
235
387
|
if (!prompt.typed) {
|
|
236
388
|
const choices = view.choices ?? prompt.options, selected = Math.min(view.selected ?? 0, Math.max(0, choices.length - 1));
|
|
237
389
|
const more = choices.length > 1 && !compactFocus ? 1 : 0;
|
|
@@ -240,14 +392,14 @@ export function richFrame(view, composer, cursor, { columns = 80, rows = 24, col
|
|
|
240
392
|
choices.slice(offset, offset + count).forEach((item, i) => {
|
|
241
393
|
const index = prompt.options.indexOf(item) + 1, current = i + offset === selected;
|
|
242
394
|
const checked = prompt.multiple ? `${composer.split(/[, ]+/).includes(String(index)) ? "[x]" : "[ ]"} ` : "";
|
|
243
|
-
lines.push(wrap(`${current ?
|
|
395
|
+
lines.push(wrap(`${current ? paint("›", "accent", theme) : " "} ${index}. ${checked}${current ? paint(terminalText(item.label), "accent", theme) : paint(terminalText(item.label), "primary", theme)}`, width)[0]);
|
|
244
396
|
});
|
|
245
|
-
if (!choices.length) line("No matching choices; clear the filter",
|
|
246
|
-
if (choices.length > count && more) line(`${selected + 1}/${choices.length} · ↑↓ more choices`,
|
|
397
|
+
if (!choices.length) line("No matching choices; clear the filter", "attention", 1);
|
|
398
|
+
if (choices.length > count && more) line(`${selected + 1}/${choices.length} · ↑↓ more choices`, "quiet", 1);
|
|
247
399
|
}
|
|
248
400
|
} else if (view.login) {
|
|
249
|
-
line(`Approve code ${view.login.user_code} in your browser`, "
|
|
250
|
-
if (!compactFocus) line(view.login.verification_uri_complete,
|
|
401
|
+
line(`Approve code ${view.login.user_code} in your browser`, "strong", 1);
|
|
402
|
+
if (!compactFocus) line(view.login.verification_uri_complete, "accent", 2);
|
|
251
403
|
const actions = ["Open browser", "Copy link", "Work offline"];
|
|
252
404
|
line(compactFocus ? `› ${actions[view.loginAction ?? 0]} (${(view.loginAction ?? 0) + 1}/3)`
|
|
253
405
|
: actions.map((text, i) => `${i === view.loginAction ? "› " : ""}${text}`).join(" · "), undefined, compactFocus ? 1 : 2);
|
|
@@ -258,62 +410,128 @@ export function richFrame(view, composer, cursor, { columns = 80, rows = 24, col
|
|
|
258
410
|
const name = Math.min(16, Math.max(...view.palette.map(row => row.name.length + 1)));
|
|
259
411
|
view.palette.slice(offset, offset + count).forEach((row, i) => {
|
|
260
412
|
const current = i + offset === selected, label = pad(`/${row.name}`, name);
|
|
261
|
-
lines.push(wrap(`${current ?
|
|
413
|
+
lines.push(wrap(`${current ? paint("›", "accent", theme) : " "} ${current ? paint(label, "accent", theme) : paint(label, "primary", theme)} ${paint(terminalText(row.disabled || row.description), "secondary", theme)}`, width)[0]);
|
|
262
414
|
});
|
|
263
415
|
}
|
|
264
416
|
const compactAttachments = rows < 24 && view.attachments?.length;
|
|
265
|
-
if (view.attachments?.length && !compactAttachments) line(`${view.attachments.length} file(s) selected · uploaded only on send`,
|
|
266
|
-
if (view.issue && !prompt) line(view.issue.text + (view.issue.count > 1 ? ` (${view.issue.count} attempts)` : ""),
|
|
267
|
-
|
|
417
|
+
if (view.attachments?.length && !compactAttachments) line(view.egress ?? `${view.attachments.length} file(s) selected · uploaded only on send`, "secondary", 1);
|
|
418
|
+
if (view.issue && !prompt) line(view.issue.text + (view.issue.count > 1 ? ` (${view.issue.count} attempts)` : ""), "attention", Math.max(1, Math.min(3, room())));
|
|
419
|
+
// First use: signed in, idle, an unbound folder, an empty transcript and an empty draft.
|
|
420
|
+
const firstUse = view.header && view.firstUse && !active && !composer && !prompt
|
|
421
|
+
&& !view.login && !view.issue && !view.palette?.length && !view.attachments?.length;
|
|
422
|
+
const idle = !active && !view.issue && !prompt && !view.login && !view.palette?.length;
|
|
423
|
+
// "Ready" is what the idle hint already says; every other state keeps its line.
|
|
424
|
+
if (idle && !firstUse && view.status !== "Ready") line(view.status, "secondary", 1);
|
|
268
425
|
const maxDraft = Math.max(1, Math.min(6, budget - lines.length - footer.length - 2));
|
|
269
|
-
const draft = composerViewport(composer, cursor, width -
|
|
270
|
-
const selection = compactAttachments ? `${view.attachments.length} file(s) · upload on send` : "";
|
|
426
|
+
const draft = composerViewport(composer, cursor, width - 4, maxDraft, theme);
|
|
427
|
+
const selection = compactAttachments ? view.egress ?? `${view.attachments.length} file(s) · upload on send` : "";
|
|
271
428
|
const placeholder = prompt ? (prompt.typed ? "Type your answer…" : "Filter or type a choice number…")
|
|
272
429
|
: readOnly ? "Read-only Project — draft here…" : view.offline ? "Draft offline…"
|
|
273
430
|
: !view.account ? "Sign in to send — draft here…"
|
|
274
431
|
: active ? "Draft your next question…" : "Ask Laplace…";
|
|
275
|
-
lines.push(...
|
|
276
|
-
|
|
432
|
+
lines.push(...composerBand(draft.lines.map((value, index) => ` ${index ? " " : paint("›", "accent", theme)} ${composer ? paint(value, "primary", theme)
|
|
433
|
+
: paint("▌", "accent", theme) + paint(placeholder, "secondary", theme)}`), width, theme,
|
|
434
|
+
{ top: selection, bottom: draft.scrolling ? draft.position : "" }));
|
|
277
435
|
lines.push(...footer);
|
|
278
|
-
|
|
436
|
+
const bottom = lines.slice(-budget);
|
|
437
|
+
|
|
438
|
+
// Above the gap: identity while the transcript is empty, then the first-use note if it fits.
|
|
439
|
+
const space = rows - 1 - bottom.length;
|
|
440
|
+
const top = [];
|
|
441
|
+
if (view.header) {
|
|
442
|
+
const header = richHeader(view, columns, theme);
|
|
443
|
+
// No room for the identity: the footer owns the route and origin, as after the commit.
|
|
444
|
+
if (header.length > space) return richLayout({ ...view, header: false }, composer, cursor, options);
|
|
445
|
+
top.push(...header);
|
|
446
|
+
}
|
|
447
|
+
if (firstUse) {
|
|
448
|
+
const note = "New folder · A project will be created on your first message. /link existing";
|
|
449
|
+
const intro = [paint("What are we working on?", "strong", theme), paint("Ask Laplace about your mission, or start from a file.", "secondary", theme)];
|
|
450
|
+
const suggestions = ONBOARDING.map(text => `${paint("›", "accent", theme)} ${paint(text, "secondary", theme)}`);
|
|
451
|
+
const quiet = wrap(note, width).map(row => paint(row, "quiet", theme));
|
|
452
|
+
const body = [[...intro, "", ...suggestions, "", ...quiet], [...intro, "", ...quiet], quiet]
|
|
453
|
+
.map(rows => rows.map(row => measure(row) > width ? wrap(row, width)[0] : row))
|
|
454
|
+
.find(rows => top.length + 1 + rows.length + 1 <= space);
|
|
455
|
+
if (body) top.push("", ...body);
|
|
456
|
+
}
|
|
457
|
+
return { top, bottom };
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** Bottom-anchored live area as one string: identity, gap, activity, focus, composer, footer. */
|
|
461
|
+
export function richFrame(view, composer, cursor, options = {}) {
|
|
462
|
+
const { top, bottom } = richLayout(view, composer, cursor, options);
|
|
463
|
+
return [...top, ...bottom].join("\n");
|
|
279
464
|
}
|
|
280
465
|
|
|
281
466
|
const indent = (text, first, rest = " ") => text.split("\n").map((line, i) => (i ? (line ? rest : "") : first) + line).join("\n");
|
|
282
467
|
|
|
283
468
|
/** One scrollback block per message: the ask, the answer with its record, or a quiet notice. */
|
|
284
|
-
export function richMessage(message, columns, color, { stepsShown = false } = {}) {
|
|
285
|
-
const width = Math.max(20, columns - 1);
|
|
469
|
+
export function richMessage(message, columns, color, { stepsShown = false, shownKeys = new Set() } = {}) {
|
|
470
|
+
const theme = themeOf(color), width = Math.max(20, columns - 1);
|
|
286
471
|
if (message.kind === "user") {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (message.kind === "cost") {
|
|
291
|
-
const display = message.value?.display ?? {};
|
|
292
|
-
const parts = [["Used", display.used], ["Limit", display.limit], ["Remaining", display.remaining]].filter(([, v]) => v !== null && v !== undefined);
|
|
293
|
-
return style(trimEnd(` Usage this UTC month · ${parts.length ? parts.map(([k, v]) => `${k} ${v}`).join(" · ") : "no exact amount available"} · /usage`, width), DIM, color);
|
|
472
|
+
const rows = wrap(terminalText(message.text), width - 2).map((row, index) =>
|
|
473
|
+
`${index ? " " : paint("›", "accent", theme)} ${paint(row, "strong", theme)}`);
|
|
474
|
+
return "\n" + rows.map(row => theme?.band ? style(pad(row, width), theme.band, theme) : row).join("\n") + "\n";
|
|
294
475
|
}
|
|
476
|
+
if (message.kind === "block") return richBlock(message.block, columns, theme);
|
|
477
|
+
if (message.kind === "turn-footer") return paint(terminalText(message.text), "quiet", theme);
|
|
295
478
|
if (message.kind !== "answer") return wrap(terminalText(message.text), width - 2).map(line => " " + line).join("\n");
|
|
296
479
|
const run = message.sections;
|
|
297
|
-
if (!run) return "\n" + indent(markdownView(message.text, width - 2,
|
|
480
|
+
if (!run) return "\n" + indent(markdownView(message.text, width - 2, theme), paint("●", "accent", theme) + " ") + "\n";
|
|
298
481
|
const out = [];
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
482
|
+
// A horizon stop says so, and what can be done, before the work (the plain renderer's `humanRun` prints the same lines).
|
|
483
|
+
if (run.stop?.length) out.push(...run.stop.flatMap(line => (line ? prose(terminalText(line), width - 4).map(part => " " + paint(part, "attention", theme)) : [""])), "");
|
|
484
|
+
for (const block of run.blocks ?? []) {
|
|
485
|
+
if (!shownKeys.has(block.key) && ["tool", "sources", "clarification"].includes(block.kind))
|
|
486
|
+
out.push(richBlock(block, columns, theme), "");
|
|
487
|
+
}
|
|
488
|
+
out.push(run.answer !== undefined ? indent(markdownView(run.answer, width - 2, theme), paint("●", "accent", theme) + " ")
|
|
489
|
+
: paint("●", "attention", theme) + " No answer was published for this Run.");
|
|
490
|
+
// The host's publication warnings, beside a non-empty answer, as the plain renderer and the browser show them (`format.js` publicationChecks).
|
|
491
|
+
if (run.answer !== undefined && run.answer !== "" && run.checks?.length)
|
|
492
|
+
out.push("", ...run.checks.flatMap(check => prose(terminalText(check), width - 4).map(part => " " + paint(part, "attention", theme))));
|
|
493
|
+
const section = (title, rows) => { if (rows.length) out.push("", " " + paint(title, "strong", theme), ...rows); };
|
|
302
494
|
const one = text => text.split("\n").map(part => part.trim()).filter(Boolean).join(" · ");
|
|
303
|
-
|
|
495
|
+
const shownSteps = new Set((run.blocks ?? []).filter(block => block.kind === "step" && shownKeys.has(block.key)).map(block => block.stepId));
|
|
496
|
+
const tasks = shownSteps.size && run.events ? taskLines(run.events.filter(event => event.kind !== "step_finished" || !shownSteps.has(event.payload?.step_id)), { facts: true }) : run.tasks;
|
|
497
|
+
section("Steps", tasks.slice(stepsShown).flatMap(task => prose(terminalText(one(task.replace(/^\s*[▸·]\s*/, ""))), width - 4).map(row => ` ⎿ ${paint(row, "secondary", theme)}`)));
|
|
304
498
|
// Evidence rows are never truncated: quantity, unit and origin wrap with a hanging indent.
|
|
305
|
-
const full = (row,
|
|
499
|
+
const full = (row, role = "secondary") => prose(terminalText(row.trim()), width - 4).map((part, i) => (i ? " " : " ") + paint(part, role, theme));
|
|
306
500
|
section("Inputs and origins", run.origins.flatMap(row => full(row)));
|
|
307
501
|
section("Assumptions", run.assumptions.flatMap(row => full(row)));
|
|
308
502
|
section("Transfer tables", run.tables.flatMap(rows => rows.flatMap(row => full(row))));
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
.map((part, i) => ` ${i ? " " : style("↓", ACCENT, color)} ${part}`))
|
|
316
|
-
.concat(more > 0 ? [style(` … ${more} more · /files`, DIM, color)] : []));
|
|
317
|
-
out.push("", ...full(run.tail.map(terminalText).join(" · "), run.state === "ok" ? DIM : ATTENTION));
|
|
503
|
+
section("Files", run.artifacts.flatMap(({ artifact, number, sameBytesAs }, i) =>
|
|
504
|
+
prose(`${terminalText(artifact.path ?? artifact.filename)} · ${terminalText(artifact.kind)} · /download ${number ?? i + 1}${sameBytesAs ? ` · same bytes as ${sameBytesAs}` : ""}`, width - 4)
|
|
505
|
+
.map((part, index) => ` ${index ? " " : paint("↓", "accent", theme)} ${paint(part, "secondary", theme)}`)));
|
|
506
|
+
out.push("", ...full(run.tail.map(terminalText).join(" · "), run.state === "ok" ? "quiet" : "attention"));
|
|
507
|
+
section("Controls", (run.blocks ?? []).filter(block => block.kind === "control" && !shownKeys.has(block.key))
|
|
508
|
+
.map(block => richBlock(block, columns, theme)));
|
|
318
509
|
return "\n" + out.join("\n") + "\n";
|
|
319
510
|
}
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
/** The same human grammar in live scrollback and reload, with bounded excerpt previews. */
|
|
514
|
+
export function richBlock(block, columns = 80, color = true, { full = false } = {}) {
|
|
515
|
+
const theme = themeOf(color), width = Math.max(20, columns - 1);
|
|
516
|
+
const c = blockContent(block, { full });
|
|
517
|
+
const role = block.kind === "step"
|
|
518
|
+
? ["computed", "read"].includes(c.status) ? "success" : ["failed", "refused"].includes(c.status) ? "error" : "attention"
|
|
519
|
+
: c.status === "ok" ? "success" : ["running", "requested", "queued", "claimed"].includes(c.status) ? "attention" : "error";
|
|
520
|
+
const header = `${paint("●", role, theme)} ${paint(terminalText(c.tool ?? c.title), "strong", theme)}${c.tool ? ` ${paint(terminalText(c.title), "primary", theme)}` : ""}`;
|
|
521
|
+
const out = wrap(header, width);
|
|
522
|
+
for (const row of c.rows) out.push(...wrap(terminalText(row).trim(), width - 5).map((line, i) =>
|
|
523
|
+
`${i ? " " : " ⎿ "}${paint(line, "secondary", theme)}`));
|
|
524
|
+
const preview = c.preview ?? [];
|
|
525
|
+
// Preserve the selected logical lines in scrollback, even at narrow widths.
|
|
526
|
+
// Bound each line independently so a long notice cannot displace the cause.
|
|
527
|
+
const selected = c.previewTail ? preview.slice(-3) : preview.slice(0, 3);
|
|
528
|
+
const wrapped = selected.map(row => wrap(row, width - 5));
|
|
529
|
+
const display = wrapped.flatMap(rows => rows.slice(0, 3));
|
|
530
|
+
if (display.length) {
|
|
531
|
+
out.push(...display.map(row => " " + paint(row, "secondary", theme)));
|
|
532
|
+
const truncated = preview.length > 3 || wrapped.some(rows => rows.length > 3);
|
|
533
|
+
const label = truncated ? "… output excerpt truncated · ctrl+o for the full block" : "output excerpt · ctrl+o for the full block";
|
|
534
|
+
out.push(...wrap(label, width - 5).map(row => " " + paint(row, "secondary", theme)));
|
|
535
|
+
}
|
|
536
|
+
return out.join("\n");
|
|
537
|
+
}
|