@mumbrane/arrakis 0.7.0 → 0.8.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 +1 -1
- package/package.json +1 -1
- package/src/cli.js +25 -17
- package/src/markdown.js +48 -29
- package/src/theme.js +153 -0
- package/src/tui.js +177 -93
- package/src/ui.js +58 -64
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ In a session:
|
|
|
69
69
|
| `/compact` | Summarize history to free up context |
|
|
70
70
|
| `/model [name]` | Pick a model from your provider |
|
|
71
71
|
| `/provider` | Switch provider or update your API key |
|
|
72
|
-
| `/clear` |
|
|
72
|
+
| `/clear` | Clear the screen and start a fresh session (the old one stays saved) |
|
|
73
73
|
| `/yolo` | Toggle running tool calls without asking |
|
|
74
74
|
| `/exit` | Quit (or Ctrl-D) |
|
|
75
75
|
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -277,9 +277,9 @@ async function interactive({ agent, ui, prompts, config, cwd, firstPrompt, mcpSe
|
|
|
277
277
|
} else p.acceptEdits = true;
|
|
278
278
|
};
|
|
279
279
|
ui.modeLabel = () =>
|
|
280
|
-
p.planMode ? `${c.
|
|
281
|
-
: p.acceptEdits ? `${c.
|
|
282
|
-
: p.mode === 'yolo' ? `${c.
|
|
280
|
+
p.planMode ? `${c.orchid('◈ plan mode')} ${c.faint('· read-only · ⇧⇥ to cycle')}`
|
|
281
|
+
: p.acceptEdits ? `${c.mint('» accepting edits')} ${c.faint('· ⇧⇥ to cycle')}`
|
|
282
|
+
: p.mode === 'yolo' ? `${c.rose('‼ yolo')} ${c.faint('· everything runs without asking')}`
|
|
283
283
|
: '';
|
|
284
284
|
p.onDeny = () => agent.interrupt();
|
|
285
285
|
} else if (ui.fancy) ui.suspend();
|
|
@@ -304,7 +304,7 @@ async function interactive({ agent, ui, prompts, config, cwd, firstPrompt, mcpSe
|
|
|
304
304
|
const used = Math.round((estimateTokens(agent.session.messages) / config.contextWindow) * 100);
|
|
305
305
|
const branch = gitBranch(cwd);
|
|
306
306
|
const cost = agent.usage.requests && agent.usage.priced && priceFor(config.model) ? formatCost(agent.usage.cost) : '';
|
|
307
|
-
if (ui instanceof FancyUI) return [config.model, branch ? `⎇ ${branch}` : '', `${used}%
|
|
307
|
+
if (ui instanceof FancyUI) return [config.model, branch ? `⎇ ${branch}` : '', `${used}% ctx`, cost].filter(Boolean).join(' · ');
|
|
308
308
|
const parts = [config.model, `${used}% context`];
|
|
309
309
|
if (branch) parts.push(`⎇ ${branch}`);
|
|
310
310
|
if (agent.permissions.planMode) parts.push('plan mode');
|
|
@@ -313,17 +313,19 @@ async function interactive({ agent, ui, prompts, config, cwd, firstPrompt, mcpSe
|
|
|
313
313
|
return parts.join(' · ');
|
|
314
314
|
};
|
|
315
315
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
316
|
+
state.showBanner = () =>
|
|
317
|
+
ui.banner({
|
|
318
|
+
version: VERSION,
|
|
319
|
+
model: config.model,
|
|
320
|
+
provider: config.providerName || config.baseUrl,
|
|
321
|
+
cwd,
|
|
322
|
+
instructions: loadProjectInstructions(cwd).filter((i) => i.text.trim()).map((i) => i.file),
|
|
323
|
+
resumed: agent.session.messages.length ? `resumed ${agent.session.id} (${agent.session.messages.length} messages)` : '',
|
|
324
|
+
mcp: mcpServers,
|
|
325
|
+
hooks,
|
|
326
|
+
update,
|
|
327
|
+
});
|
|
328
|
+
state.showBanner();
|
|
327
329
|
|
|
328
330
|
const send = async (text) => {
|
|
329
331
|
const { content, attached, errors } = buildMessage(text, cwd, state.pastedImages.splice(0));
|
|
@@ -541,12 +543,18 @@ async function slashCommand(text, { agent, ui, prompts, config, cwd, state }) {
|
|
|
541
543
|
case 'exit':
|
|
542
544
|
case 'quit':
|
|
543
545
|
return 'exit';
|
|
544
|
-
case 'clear':
|
|
546
|
+
case 'clear': {
|
|
547
|
+
const previous = agent.session.messages.length ? agent.session.id : null;
|
|
545
548
|
agent.session = Session.create({ cwd, model: config.model });
|
|
546
549
|
agent.checkpoints = new Checkpoints(agent.session.file);
|
|
547
550
|
agent.systemPrompt = null;
|
|
548
|
-
|
|
551
|
+
agent.todos = [];
|
|
552
|
+
agent.notes = [];
|
|
553
|
+
ui.clearScreen();
|
|
554
|
+
state.showBanner?.();
|
|
555
|
+
if (previous) ui.info(` Fresh start. The previous conversation is saved: /resume or arrakis -r ${previous}`);
|
|
549
556
|
break;
|
|
557
|
+
}
|
|
550
558
|
case 'compact': {
|
|
551
559
|
const ac = new AbortController();
|
|
552
560
|
agent.abort = ac;
|
package/src/markdown.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Streaming Markdown renderer for the terminal
|
|
2
|
-
// complete line is rendered as soon as its newline
|
|
3
|
-
// until they end so their columns can be aligned.
|
|
1
|
+
// Streaming Markdown renderer for the terminal, in the Dusk style. Text
|
|
2
|
+
// arrives in chunks; each complete line is rendered as soon as its newline
|
|
3
|
+
// arrives. Tables are held until they end so their columns can be aligned.
|
|
4
4
|
|
|
5
5
|
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
6
6
|
export const visibleLength = (s) => s.replace(ANSI, '').length;
|
|
@@ -13,13 +13,14 @@ const KEYWORDS = new Set(
|
|
|
13
13
|
);
|
|
14
14
|
|
|
15
15
|
export function highlight(line, c) {
|
|
16
|
-
const token = /(\/\/.*$|#(?![!{\[]).*$|--\s.*$)|("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`)|(\b\d+(?:\.\d+)?\b)|([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
17
|
-
return line.replace(token, (m, comment, str, num, word) => {
|
|
18
|
-
if (comment) return c.
|
|
19
|
-
if (str) return c.
|
|
20
|
-
if (num) return c.
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
16
|
+
const token = /(\/\/.*$|#(?![!{\[]).*$|--\s.*$)|("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`)|(\b\d+(?:\.\d+)?\b)|([A-Za-z_][A-Za-z0-9_]*)(?=\s*\()|([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
17
|
+
return line.replace(token, (m, comment, str, num, call, word) => {
|
|
18
|
+
if (comment) return c.faint(c.italic(comment));
|
|
19
|
+
if (str) return c.mint(str);
|
|
20
|
+
if (num) return c.amber(num);
|
|
21
|
+
if (call) return KEYWORDS.has(call) ? c.orchid(call) : c.sky(call);
|
|
22
|
+
if (word && KEYWORDS.has(word)) return c.orchid(word);
|
|
23
|
+
return c.lilac(m);
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -28,13 +29,13 @@ export function renderInline(s, c) {
|
|
|
28
29
|
return s
|
|
29
30
|
.split(/(`[^`]+`)/)
|
|
30
31
|
.map((part) => {
|
|
31
|
-
if (/^`[^`]+`$/.test(part)) return c.
|
|
32
|
+
if (/^`[^`]+`$/.test(part)) return c.panelBg(c.sky(` ${part.slice(1, -1)} `));
|
|
32
33
|
return part
|
|
33
|
-
.replace(/\*\*([^*]+)\*\*|__([^_]+)__/g, (_, a, b) => c.bold(a ?? b))
|
|
34
|
+
.replace(/\*\*([^*]+)\*\*|__([^_]+)__/g, (_, a, b) => c.bold(c.lilac(a ?? b)))
|
|
34
35
|
.replace(/(^|[\s(])\*([^*\s][^*]*)\*(?=$|[\s).,:;!?])/g, (_, pre, a) => pre + c.italic(a))
|
|
35
36
|
.replace(/(^|[\s(])_([^_\s][^_]*)_(?=$|[\s).,:;!?])/g, (_, pre, a) => pre + c.italic(a))
|
|
36
|
-
.replace(/~~([^~]+)~~/g, (_, a) => c.
|
|
37
|
-
.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_, text, url) => (text === url ? c.underline(url) : `${c.underline(text)} ${c.
|
|
37
|
+
.replace(/~~([^~]+)~~/g, (_, a) => c.strike(c.mist(a)))
|
|
38
|
+
.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_, text, url) => (text === url ? c.underline(c.sky(url)) : `${c.underline(c.sky(text))} ${c.faint(url)}`));
|
|
38
39
|
})
|
|
39
40
|
.join('');
|
|
40
41
|
}
|
|
@@ -46,6 +47,7 @@ export class MarkdownStream {
|
|
|
46
47
|
this.buf = '';
|
|
47
48
|
this.inCode = false;
|
|
48
49
|
this.fence = '';
|
|
50
|
+
this.lang = '';
|
|
49
51
|
this.table = [];
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -68,12 +70,21 @@ export class MarkdownStream {
|
|
|
68
70
|
}
|
|
69
71
|
out += this.flushTable();
|
|
70
72
|
if (this.inCode) {
|
|
71
|
-
out += this.
|
|
73
|
+
out += this.panel('') + '\n';
|
|
72
74
|
this.inCode = false;
|
|
73
75
|
}
|
|
74
76
|
return out;
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
// One row of a code panel: plum background across the panel width.
|
|
80
|
+
panel(content) {
|
|
81
|
+
const c = this.c;
|
|
82
|
+
const w = Math.max(20, Math.min(this.width - 2, 110));
|
|
83
|
+
const vis = visibleLength(content);
|
|
84
|
+
const body = vis > w - 2 ? content : content + ' '.repeat(w - 2 - vis);
|
|
85
|
+
return c.panelBg(` ${body} `);
|
|
86
|
+
}
|
|
87
|
+
|
|
77
88
|
line(raw) {
|
|
78
89
|
const c = this.c;
|
|
79
90
|
const fence = raw.match(/^\s*(```+|~~~+)\s*([\w+#.-]*)/);
|
|
@@ -82,12 +93,15 @@ export class MarkdownStream {
|
|
|
82
93
|
if (!this.inCode) {
|
|
83
94
|
this.inCode = true;
|
|
84
95
|
this.fence = fence[1];
|
|
85
|
-
|
|
96
|
+
this.lang = fence[2] || '';
|
|
97
|
+
// Top edge of the panel carries the language as a small tag.
|
|
98
|
+
const tag = this.lang ? c.violet(this.lang) : c.faint('code');
|
|
99
|
+
return out + this.panel(tag) + '\n';
|
|
86
100
|
}
|
|
87
101
|
this.inCode = false;
|
|
88
|
-
return out +
|
|
102
|
+
return out + this.panel('') + '\n';
|
|
89
103
|
}
|
|
90
|
-
if (this.inCode) return
|
|
104
|
+
if (this.inCode) return this.panel(highlight(raw.replace(/\t/g, ' '), c)) + '\n';
|
|
91
105
|
|
|
92
106
|
if (/^\s*\|.*\|\s*$/.test(raw)) {
|
|
93
107
|
this.table.push(raw);
|
|
@@ -97,17 +111,22 @@ export class MarkdownStream {
|
|
|
97
111
|
|
|
98
112
|
let m;
|
|
99
113
|
if ((m = raw.match(/^(#{1,6})\s+(.*)$/))) {
|
|
100
|
-
const text =
|
|
101
|
-
|
|
114
|
+
const text = m[2].replace(/\s+#+\s*$/, '');
|
|
115
|
+
if (m[1].length === 1) return out + c.bold(c.gradient(text)) + '\n';
|
|
116
|
+
if (m[1].length === 2) return out + c.bold(c.violet(text)) + '\n';
|
|
117
|
+
return out + c.bold(c.lilac(renderInline(text, c))) + '\n';
|
|
102
118
|
}
|
|
103
|
-
if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(raw)) return out + c.
|
|
104
|
-
if ((m = raw.match(/^\s*>\s?(.*)$/))) return out + `${c.
|
|
119
|
+
if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(raw)) return out + c.faint('─'.repeat(Math.min(this.width, 56))) + '\n';
|
|
120
|
+
if ((m = raw.match(/^\s*>\s?(.*)$/))) return out + `${c.iris('┃')} ${c.italic(c.lilac(renderInline(m[1], c)))}\n`;
|
|
105
121
|
if ((m = raw.match(/^(\s*)[-*+]\s+\[( |x|X)\]\s+(.*)$/))) {
|
|
106
122
|
const done = m[2].toLowerCase() === 'x';
|
|
107
|
-
return out + `${m[1]}${done ? c.
|
|
123
|
+
return out + `${m[1]}${done ? c.mint('●') : c.mist('○')} ${done ? c.mist(c.strike(renderInline(m[3], c))) : renderInline(m[3], c)}\n`;
|
|
124
|
+
}
|
|
125
|
+
if ((m = raw.match(/^(\s*)[-*+]\s+(.*)$/))) {
|
|
126
|
+
const nested = m[1].length >= 2;
|
|
127
|
+
return out + `${m[1]}${nested ? c.iris('◦') : c.violet('•')} ${renderInline(m[2], c)}\n`;
|
|
108
128
|
}
|
|
109
|
-
if ((m = raw.match(/^(\s*)[
|
|
110
|
-
if ((m = raw.match(/^(\s*)(\d+)[.)]\s+(.*)$/))) return out + `${m[1]}${c.accent(m[2] + '.')} ${renderInline(m[3], c)}\n`;
|
|
129
|
+
if ((m = raw.match(/^(\s*)(\d+)[.)]\s+(.*)$/))) return out + `${m[1]}${c.violet(m[2] + '.')} ${renderInline(m[3], c)}\n`;
|
|
111
130
|
return out + renderInline(raw, c) + '\n';
|
|
112
131
|
}
|
|
113
132
|
|
|
@@ -122,13 +141,13 @@ export class MarkdownStream {
|
|
|
122
141
|
const cols = Math.max(...rows.map((r) => r.length));
|
|
123
142
|
const widths = Array.from({ length: cols }, (_, i) => Math.max(3, ...rows.map((r) => visibleLength(r[i] ?? ''))));
|
|
124
143
|
const pad = (s, w) => s + ' '.repeat(Math.max(0, w - visibleLength(s)));
|
|
125
|
-
const rule = (l, mid, r) => c.
|
|
126
|
-
const lines = [rule('
|
|
144
|
+
const rule = (l, mid, r) => c.faint(l + widths.map((w) => '─'.repeat(w + 2)).join(mid) + r);
|
|
145
|
+
const lines = [rule('╭', '┬', '╮')];
|
|
127
146
|
rows.forEach((r, i) => {
|
|
128
|
-
lines.push(c.
|
|
147
|
+
lines.push(c.faint('│') + widths.map((w, j) => ` ${i === 0 ? c.bold(c.violet(pad(r[j] ?? '', w))) : pad(r[j] ?? '', w)} `).join(c.faint('│')) + c.faint('│'));
|
|
129
148
|
if (i === 0 && rows.length > 1) lines.push(rule('├', '┼', '┤'));
|
|
130
149
|
});
|
|
131
|
-
lines.push(rule('
|
|
150
|
+
lines.push(rule('╰', '┴', '╯'));
|
|
132
151
|
return lines.join('\n') + '\n';
|
|
133
152
|
}
|
|
134
153
|
}
|
package/src/theme.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// "Dusk": arrakis's design language.
|
|
2
|
+
//
|
|
3
|
+
// A twilight palette: lavender as the primary, deep iris and orchid as
|
|
4
|
+
// accents, lilac for soft text, plum panels behind code. Mint, amber and rose
|
|
5
|
+
// carry meaning (success, caution, error) and are used sparingly.
|
|
6
|
+
//
|
|
7
|
+
// Colors render in 24-bit where the terminal supports it and fall back to the
|
|
8
|
+
// nearest 256-color value elsewhere (e.g. macOS Terminal.app). NO_COLOR turns
|
|
9
|
+
// everything off.
|
|
10
|
+
|
|
11
|
+
export const PALETTE = {
|
|
12
|
+
violet: [167, 139, 250], // primary
|
|
13
|
+
iris: [124, 92, 246], // deep accent
|
|
14
|
+
orchid: [226, 125, 245], // hot accent
|
|
15
|
+
lilac: [221, 214, 254], // soft text
|
|
16
|
+
mist: [140, 132, 166], // muted text
|
|
17
|
+
dusk: [84, 76, 110], // faint lines
|
|
18
|
+
mint: [110, 231, 183],
|
|
19
|
+
amber: [246, 196, 92],
|
|
20
|
+
rose: [251, 113, 150],
|
|
21
|
+
sky: [134, 200, 252],
|
|
22
|
+
ink: [20, 17, 31], // text on light chips
|
|
23
|
+
panel: [32, 27, 48], // code panels
|
|
24
|
+
raise: [46, 38, 70], // selected rows, user messages
|
|
25
|
+
addBg: [22, 52, 44],
|
|
26
|
+
delBg: [62, 26, 44],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const env = process.env;
|
|
30
|
+
export const TRUECOLOR =
|
|
31
|
+
/truecolor|24bit/i.test(env.COLORTERM ?? '') ||
|
|
32
|
+
/iTerm|WezTerm|vscode|ghostty|Hyper|Tabby|WarpTerminal|rio/i.test(env.TERM_PROGRAM ?? '') ||
|
|
33
|
+
Boolean(env.WT_SESSION || env.KITTY_WINDOW_ID || env.ALACRITTY_LOG);
|
|
34
|
+
|
|
35
|
+
function to256([r, g, b]) {
|
|
36
|
+
// Grays get the 24-step gray ramp, colors the 6x6x6 cube.
|
|
37
|
+
if (Math.abs(r - g) < 10 && Math.abs(g - b) < 10) {
|
|
38
|
+
if (r < 8) return 16;
|
|
39
|
+
if (r > 248) return 231;
|
|
40
|
+
return 232 + Math.round(((r - 8) / 247) * 23);
|
|
41
|
+
}
|
|
42
|
+
const q = (v) => (v < 48 ? 0 : v < 115 ? 1 : Math.round((v - 35) / 40));
|
|
43
|
+
return 16 + 36 * q(r) + 6 * q(g) + q(b);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const fgCode = (rgb) => (TRUECOLOR ? `38;2;${rgb[0]};${rgb[1]};${rgb[2]}` : `38;5;${to256(rgb)}`);
|
|
47
|
+
const bgCode = (rgb) => (TRUECOLOR ? `48;2;${rgb[0]};${rgb[1]};${rgb[2]}` : `48;5;${to256(rgb)}`);
|
|
48
|
+
|
|
49
|
+
// Each style closes with its own reset code, so styles nest (e.g. colored
|
|
50
|
+
// text inside a background panel keeps the panel).
|
|
51
|
+
const wrap = (open, close, on) => (s) => (on ? `\x1b[${open}m${s}\x1b[${close}m` : String(s));
|
|
52
|
+
|
|
53
|
+
const mix = (a, b, t) => a.map((v, i) => Math.round(v + (b[i] - v) * t));
|
|
54
|
+
|
|
55
|
+
export function makeTheme(on) {
|
|
56
|
+
const fg = (rgb) => wrap(fgCode(rgb), '39', on);
|
|
57
|
+
const bg = (rgb) => wrap(bgCode(rgb), '49', on);
|
|
58
|
+
const P = PALETTE;
|
|
59
|
+
const t = {
|
|
60
|
+
on,
|
|
61
|
+
bold: wrap('1', '22', on),
|
|
62
|
+
dim: wrap('2', '22', on),
|
|
63
|
+
italic: wrap('3', '23', on),
|
|
64
|
+
underline: wrap('4', '24', on),
|
|
65
|
+
strike: wrap('9', '29', on),
|
|
66
|
+
inverse: wrap('7', '27', on),
|
|
67
|
+
fg,
|
|
68
|
+
bg,
|
|
69
|
+
violet: fg(P.violet),
|
|
70
|
+
iris: fg(P.iris),
|
|
71
|
+
orchid: fg(P.orchid),
|
|
72
|
+
lilac: fg(P.lilac),
|
|
73
|
+
mist: fg(P.mist),
|
|
74
|
+
faint: fg(P.dusk),
|
|
75
|
+
mint: fg(P.mint),
|
|
76
|
+
amber: fg(P.amber),
|
|
77
|
+
rose: fg(P.rose),
|
|
78
|
+
sky: fg(P.sky),
|
|
79
|
+
ink: fg(P.ink),
|
|
80
|
+
panelBg: bg(P.panel),
|
|
81
|
+
raiseBg: bg(P.raise),
|
|
82
|
+
addBg: bg(P.addBg),
|
|
83
|
+
delBg: bg(P.delBg),
|
|
84
|
+
violetBg: bg(P.violet),
|
|
85
|
+
|
|
86
|
+
// Color each character along a gradient of stops. `phase` (0-1) shifts it.
|
|
87
|
+
gradient(text, stops = [P.iris, P.violet, P.orchid], phase = 0) {
|
|
88
|
+
if (!on) return String(text);
|
|
89
|
+
const chars = [...String(text)];
|
|
90
|
+
const n = Math.max(1, chars.length - 1);
|
|
91
|
+
return (
|
|
92
|
+
chars
|
|
93
|
+
.map((ch, i) => {
|
|
94
|
+
if (ch === ' ') return ch;
|
|
95
|
+
let x = (i / n + phase) % 1;
|
|
96
|
+
if (phase) x = x < 0.5 ? x * 2 : 2 - x * 2; // ping-pong so it loops smoothly
|
|
97
|
+
const seg = x * (stops.length - 1);
|
|
98
|
+
const k = Math.min(stops.length - 2, Math.floor(seg));
|
|
99
|
+
return `\x1b[${fgCode(mix(stops[k], stops[k + 1], seg - k))}m${ch}`;
|
|
100
|
+
})
|
|
101
|
+
.join('') + '\x1b[39m'
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// A bright band sweeping across muted text (for the working indicator).
|
|
106
|
+
shimmer(text, frame) {
|
|
107
|
+
if (!on) return String(text);
|
|
108
|
+
const chars = [...String(text)];
|
|
109
|
+
const pos = (frame % (chars.length + 8)) - 4;
|
|
110
|
+
return (
|
|
111
|
+
chars
|
|
112
|
+
.map((ch, i) => {
|
|
113
|
+
const d = Math.abs(i - pos);
|
|
114
|
+
const c = d < 1 ? P.lilac : d < 2.5 ? mix(P.lilac, P.violet, 0.5) : d < 4 ? P.violet : mix(P.violet, P.mist, 0.55);
|
|
115
|
+
return `\x1b[${fgCode(c)}m${ch}`;
|
|
116
|
+
})
|
|
117
|
+
.join('') + '\x1b[39m'
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
// Names the rest of the code already uses, mapped onto the palette.
|
|
122
|
+
Object.assign(t, {
|
|
123
|
+
accent: t.violet,
|
|
124
|
+
sand: t.lilac,
|
|
125
|
+
gray: t.mist,
|
|
126
|
+
green: t.mint,
|
|
127
|
+
red: t.rose,
|
|
128
|
+
yellow: t.amber,
|
|
129
|
+
magenta: t.orchid,
|
|
130
|
+
cyan: t.sky,
|
|
131
|
+
blue: t.violet,
|
|
132
|
+
userBg: t.raiseBg,
|
|
133
|
+
});
|
|
134
|
+
return t;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Glyphs of the design language, in one place.
|
|
138
|
+
export const GLYPH = {
|
|
139
|
+
reply: '◆',
|
|
140
|
+
tool: '◇',
|
|
141
|
+
result: '╰',
|
|
142
|
+
user: '▌',
|
|
143
|
+
thinking: '✧',
|
|
144
|
+
prompt: '❯',
|
|
145
|
+
ok: '✓',
|
|
146
|
+
fail: '✕',
|
|
147
|
+
info: '·',
|
|
148
|
+
todo: { pending: '○', in_progress: '◉', completed: '●' },
|
|
149
|
+
spinner: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// "ARRAKIS" in a two-row block font.
|
|
153
|
+
export const LOGO = ['▄▀█ █▀█ █▀█ ▄▀█ █▄▀ █ █▀', '█▀█ █▀▄ █▀▄ █▀█ █ █ █ ▄█'];
|
package/src/tui.js
CHANGED
|
@@ -11,8 +11,9 @@ import path from 'node:path';
|
|
|
11
11
|
import { spawnSync } from 'node:child_process';
|
|
12
12
|
import { UI, truncate } from './ui.js';
|
|
13
13
|
import { MarkdownStream, visibleLength } from './markdown.js';
|
|
14
|
+
import { GLYPH, LOGO, PALETTE } from './theme.js';
|
|
14
15
|
|
|
15
|
-
const SPIN =
|
|
16
|
+
const SPIN = GLYPH.spinner;
|
|
16
17
|
const VERBS = ['Thinking', 'Reading the sands', 'Harvesting spice', 'Folding space', 'Charting the dunes', 'Working', 'Considering', 'Tracing', 'Mapping'];
|
|
17
18
|
const fmtTokens = (n) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n));
|
|
18
19
|
|
|
@@ -184,10 +185,23 @@ export class FancyUI extends UI {
|
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
|
|
188
|
+
// Your message: a raised violet panel across the full width, so it stands
|
|
189
|
+
// apart from both the terminal and arrakis's replies.
|
|
187
190
|
echoUser(text) {
|
|
188
191
|
const c = this.c;
|
|
189
|
-
const
|
|
190
|
-
|
|
192
|
+
const cols = Math.max(30, (this.out.columns || 100) - 1);
|
|
193
|
+
const width = cols - 3;
|
|
194
|
+
const rows = [];
|
|
195
|
+
for (const line of text.split('\n')) {
|
|
196
|
+
if (!line) rows.push('');
|
|
197
|
+
for (let i = 0; i < line.length; i += width) rows.push(line.slice(i, i + width));
|
|
198
|
+
}
|
|
199
|
+
const panel = (s, first) => {
|
|
200
|
+
const body = first ? c.bold(c.lilac(s)) : c.lilac(s);
|
|
201
|
+
return c.raiseBg(`${c.violet(GLYPH.user)} ${body}${' '.repeat(Math.max(0, cols - 2 - s.length))}`);
|
|
202
|
+
};
|
|
203
|
+
const lead = this.lastBlank ? '' : '\n';
|
|
204
|
+
this.printAbove(lead + rows.map((r) => panel(r, true)).join('\n') + '\n\n');
|
|
191
205
|
}
|
|
192
206
|
|
|
193
207
|
insert(s) {
|
|
@@ -319,8 +333,8 @@ export class FancyUI extends UI {
|
|
|
319
333
|
const nl = this.buffer.indexOf('\n', this.cursor);
|
|
320
334
|
this.buffer = this.buffer.slice(0, this.cursor) + (nl < 0 ? '' : this.buffer.slice(nl));
|
|
321
335
|
} else if (key.ctrl && name === 'l') {
|
|
322
|
-
this.
|
|
323
|
-
this.
|
|
336
|
+
this.clearScreen();
|
|
337
|
+
return this.render();
|
|
324
338
|
} else if (str === '?' && !this.buffer) {
|
|
325
339
|
this.showHelp = !this.showHelp;
|
|
326
340
|
return this.render();
|
|
@@ -472,10 +486,11 @@ export class FancyUI extends UI {
|
|
|
472
486
|
const what = { edit_file: 'edits', write_file: 'file writes', bash: 'commands', web_fetch: 'web fetches' }[toolName] ?? `"${toolName}"`;
|
|
473
487
|
this.menu = {
|
|
474
488
|
preview,
|
|
489
|
+
toolName,
|
|
475
490
|
options: [
|
|
476
491
|
{ label: 'Yes', value: 'yes' },
|
|
477
|
-
{ label: `
|
|
478
|
-
{ label: 'No,
|
|
492
|
+
{ label: `Always allow ${what}`, value: 'always' },
|
|
493
|
+
{ label: 'No, I\'ll explain', value: 'no' },
|
|
479
494
|
],
|
|
480
495
|
selected: 0,
|
|
481
496
|
resolve,
|
|
@@ -487,8 +502,8 @@ export class FancyUI extends UI {
|
|
|
487
502
|
menuKey(str, key) {
|
|
488
503
|
const m = this.menu;
|
|
489
504
|
const n = m.options.length;
|
|
490
|
-
if (key.name === 'up') m.selected = (m.selected + n - 1) % n;
|
|
491
|
-
else if (key.name === 'down' || (key.name === 'tab' && !key.shift)) m.selected = (m.selected + 1) % n;
|
|
505
|
+
if (key.name === 'up' || key.name === 'left') m.selected = (m.selected + n - 1) % n;
|
|
506
|
+
else if (key.name === 'down' || key.name === 'right' || (key.name === 'tab' && !key.shift)) m.selected = (m.selected + 1) % n;
|
|
492
507
|
else if (key.name === 'return' || key.name === 'enter') return this.finishMenu(m.selected);
|
|
493
508
|
else if (key.name === 'escape' || (key.ctrl && key.name === 'c')) return this.finishMenu(n - 1);
|
|
494
509
|
else if (/^[1-9]$/.test(str ?? '') && Number(str) <= n) return this.finishMenu(Number(str) - 1);
|
|
@@ -502,7 +517,8 @@ export class FancyUI extends UI {
|
|
|
502
517
|
if (!m) return;
|
|
503
518
|
this.menu = null;
|
|
504
519
|
const choice = m.options[index];
|
|
505
|
-
if (choice.value === 'no') this.printAbove(` ${this.c.
|
|
520
|
+
if (choice.value === 'no') this.printAbove(` ${this.c.faint(GLYPH.result)} ${this.c.rose('declined')} ${this.c.mist('· tell arrakis what to do instead')}\n`);
|
|
521
|
+
else if (choice.value === 'always') this.printAbove(` ${this.c.faint(GLYPH.result)} ${this.c.mint('allowed for the rest of this session')}\n`);
|
|
506
522
|
this.resumeSpinnerTimer();
|
|
507
523
|
this.render();
|
|
508
524
|
m.resolve(choice.value);
|
|
@@ -526,6 +542,24 @@ export class FancyUI extends UI {
|
|
|
526
542
|
this.drawRegion();
|
|
527
543
|
}
|
|
528
544
|
|
|
545
|
+
// Clear the screen and scrollback, and forget what was printed, so a resize
|
|
546
|
+
// doesn't bring it back. The input area is redrawn by the next render.
|
|
547
|
+
clearScreen() {
|
|
548
|
+
this.thinkBuf = '';
|
|
549
|
+
this.md = null;
|
|
550
|
+
this.mode = null;
|
|
551
|
+
this.partial = '';
|
|
552
|
+
this.transcript = [];
|
|
553
|
+
this.transcriptSize = 0;
|
|
554
|
+
this.out.write('\x1b[2J\x1b[3J\x1b[H');
|
|
555
|
+
this.regionRows = 0;
|
|
556
|
+
this.regionCursorRow = 0;
|
|
557
|
+
this.regionCursorCol = 0;
|
|
558
|
+
this.regionWidths = [];
|
|
559
|
+
this.lastBlank = true;
|
|
560
|
+
this.atLineStart = true;
|
|
561
|
+
}
|
|
562
|
+
|
|
529
563
|
handleResize() {
|
|
530
564
|
const cols = this.out.columns;
|
|
531
565
|
if (cols === this.lastCols || !this.active) return this.render();
|
|
@@ -579,11 +613,15 @@ export class FancyUI extends UI {
|
|
|
579
613
|
if (!rendered) return;
|
|
580
614
|
const lines = rendered.split('\n');
|
|
581
615
|
lines.pop();
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
616
|
+
const width = Math.max(20, (this.out.columns || 100) - 3);
|
|
617
|
+
const out = [];
|
|
618
|
+
for (const l of lines) {
|
|
619
|
+
for (const [i, part] of wrapAnsi(l, width).entries()) {
|
|
620
|
+
const prefix = this.firstLine ? `${this.c.violet(GLYPH.reply)} ` : ' ';
|
|
621
|
+
this.firstLine = false;
|
|
622
|
+
out.push(prefix + (i ? part.replace(/^/, '') : part));
|
|
623
|
+
}
|
|
624
|
+
}
|
|
587
625
|
this.write(this.out, out.join('\n') + '\n');
|
|
588
626
|
}
|
|
589
627
|
|
|
@@ -608,8 +646,8 @@ export class FancyUI extends UI {
|
|
|
608
646
|
for (let i = 0; i < para.length; i += width) rows.push(para.slice(i, i + width));
|
|
609
647
|
}
|
|
610
648
|
const shown = rows.slice(0, 10);
|
|
611
|
-
const out = shown.map((r, i) => `${i === 0 ? c.
|
|
612
|
-
if (rows.length > shown.length) out.push(` ${c.
|
|
649
|
+
const out = shown.map((r, i) => `${i === 0 ? `${c.orchid(GLYPH.thinking)} ` : ' '}${c.mist(c.italic(r))}`);
|
|
650
|
+
if (rows.length > shown.length) out.push(` ${c.faint(`+${rows.length - shown.length} more lines of thinking`)}`);
|
|
613
651
|
this.printAbove((this.lastBlank ? '' : '\n') + out.join('\n') + '\n\n');
|
|
614
652
|
}
|
|
615
653
|
|
|
@@ -725,100 +763,109 @@ export class FancyUI extends UI {
|
|
|
725
763
|
const c = this.c;
|
|
726
764
|
const cols = Math.max(30, (this.out.columns || 100) - 1);
|
|
727
765
|
const lines = [];
|
|
728
|
-
if (this.spinner) {
|
|
766
|
+
if (this.spinner && !this.menu) {
|
|
729
767
|
const s = this.spinner;
|
|
730
768
|
const secs = Math.floor((Date.now() - s.started) / 1000);
|
|
731
769
|
const meta = [`${secs}s`];
|
|
732
|
-
if (this.tokens >= 1) meta.push(`↓ ${fmtTokens(Math.round(this.tokens))}
|
|
770
|
+
if (this.tokens >= 1) meta.push(`↓ ${fmtTokens(Math.round(this.tokens))}`);
|
|
733
771
|
meta.push('esc to interrupt');
|
|
734
|
-
|
|
735
|
-
if (s.detail)
|
|
736
|
-
lines.push(
|
|
772
|
+
lines.push(truncate(`${c.orchid(SPIN[s.frame % SPIN.length])} ${c.shimmer(s.label + '…', s.frame)} ${c.faint(meta.join(' · '))}`, cols - 1));
|
|
773
|
+
if (s.detail) lines.push(truncate(` ${c.faint(GLYPH.result)} ${c.mist(s.detail)}`, cols - 1));
|
|
774
|
+
lines.push('');
|
|
737
775
|
}
|
|
738
776
|
|
|
739
777
|
if (this.menu) return this.menuLayout(lines, cols);
|
|
740
778
|
|
|
741
|
-
for (const q of this.queued) lines.push(truncate(c.
|
|
779
|
+
for (const q of this.queued) lines.push(truncate(`${c.iris(GLYPH.user)} ${c.mist('queued')} ${c.faint('·')} ${c.lilac(q.replace(/\n/g, ' '))}`, cols - 1));
|
|
742
780
|
if (this.queued.length) lines.push('');
|
|
743
781
|
if (this.pending?.label) lines.push(truncate(this.pending.label.trimEnd(), cols - 1));
|
|
744
782
|
|
|
745
|
-
//
|
|
746
|
-
const
|
|
747
|
-
|
|
783
|
+
// The input rail: a gradient line (it drifts while arrakis works), then the prompt.
|
|
784
|
+
const phase = this.busy && this.spinner ? (this.spinner.frame * 0.015) % 1 : 0;
|
|
785
|
+
lines.push(this.busy ? c.gradient('─'.repeat(cols), [PALETTE.iris, PALETTE.violet, PALETTE.dusk, PALETTE.iris], phase) : c.gradient('─'.repeat(cols)));
|
|
786
|
+
const width = Math.max(10, cols - 3);
|
|
748
787
|
const shown = this.pending?.secret ? '•'.repeat(this.buffer.length) : this.buffer;
|
|
749
788
|
const rows = wrap(shown, width);
|
|
750
|
-
const
|
|
751
|
-
const border = this.busy && !this.pending ? c.gray : (s) => c.gray(s);
|
|
752
|
-
lines.push(border(`╭${'─'.repeat(cols - 2)}╮`));
|
|
789
|
+
const top = lines.length;
|
|
753
790
|
let cursorRow = null;
|
|
754
791
|
let cursorCol = 0;
|
|
755
|
-
const placeholder = !this.buffer && !this.pending?.label ? (this.busy ? 'Type
|
|
792
|
+
const placeholder = !this.buffer && !this.pending?.label ? (this.busy ? 'Type ahead; your message will be sent next' : 'Ask, plan or build something. / commands @ files') : '';
|
|
756
793
|
rows.forEach((r, i) => {
|
|
757
|
-
const prefix = i === 0 ? c.
|
|
758
|
-
const body = placeholder && i === 0 ? c.
|
|
759
|
-
|
|
760
|
-
lines.push(`${border('│')} ${prefix}${body}${' '.repeat(pad)} ${border('│')}`);
|
|
794
|
+
const prefix = i === 0 ? `${this.busy ? c.iris(GLYPH.prompt) : c.orchid(GLYPH.prompt)} ` : ' ';
|
|
795
|
+
const body = placeholder && i === 0 ? c.faint(c.italic(truncate(placeholder, width))) : c.lilac(r.text);
|
|
796
|
+
lines.push(`${prefix}${body}`);
|
|
761
797
|
if (this.cursor >= r.start && this.cursor <= r.end && cursorRow === null) {
|
|
762
798
|
if (this.cursor === r.end && r.full && i < rows.length - 1) return;
|
|
763
799
|
cursorRow = lines.length - 1;
|
|
764
|
-
cursorCol =
|
|
800
|
+
cursorCol = 2 + (this.cursor - r.start);
|
|
765
801
|
}
|
|
766
802
|
});
|
|
767
803
|
if (cursorRow === null) {
|
|
768
|
-
cursorRow =
|
|
769
|
-
cursorCol =
|
|
804
|
+
cursorRow = top + rows.length - 1;
|
|
805
|
+
cursorCol = 2 + (rows.at(-1)?.text.length ?? 0);
|
|
770
806
|
}
|
|
771
|
-
lines.push(border(`╰${'─'.repeat(cols - 2)}╯`));
|
|
772
807
|
|
|
773
|
-
// Below the
|
|
808
|
+
// Below the input: suggestions, shortcuts, or the hint line.
|
|
774
809
|
if (this.suggest) {
|
|
810
|
+
const labelW = Math.min(28, Math.max(...this.suggest.items.map((x) => x.label.length)) + 2);
|
|
775
811
|
for (const [i, item] of this.suggest.items.slice(0, 8).entries()) {
|
|
776
812
|
const sel = i === this.suggest.selected;
|
|
777
|
-
const label =
|
|
778
|
-
const
|
|
779
|
-
|
|
813
|
+
const label = item.label.padEnd(labelW);
|
|
814
|
+
const row = ` ${sel ? c.bold(c.violet(label)) : c.lilac(label)}${item.hint ? (sel ? c.lilac(item.hint) : c.mist(item.hint)) : ''}`;
|
|
815
|
+
const fit = truncate(row, cols - 1);
|
|
816
|
+
lines.push(sel ? c.raiseBg(fit + ' '.repeat(Math.max(0, cols - 1 - visibleLength(fit)))) : fit);
|
|
780
817
|
}
|
|
781
818
|
} else if (this.showHelp) {
|
|
819
|
+
const k = (key, desc) => `${c.violet(key)} ${c.mist(desc)}`;
|
|
782
820
|
const help = [
|
|
783
|
-
['/
|
|
784
|
-
['
|
|
785
|
-
['
|
|
821
|
+
[k('/', 'commands'), k('@', 'attach files'), k('\\⏎', 'new line')],
|
|
822
|
+
[k('⇧⇥', 'cycle modes'), k('esc', 'interrupt'), k('↑↓', 'history')],
|
|
823
|
+
[k('tab', 'complete'), k('esc esc', 'clear input'), k('ctrl+c', 'clear / exit')],
|
|
786
824
|
];
|
|
787
|
-
for (const row of help) lines.push(
|
|
825
|
+
for (const row of help) lines.push(' ' + row.map((x) => x + ' '.repeat(Math.max(2, 24 - visibleLength(x)))).join(''));
|
|
788
826
|
} else {
|
|
789
|
-
const left = this.exitArmed ? c.
|
|
790
|
-
const right = c.
|
|
791
|
-
const gap = Math.max(2, cols -
|
|
827
|
+
const left = this.exitArmed ? c.amber('press ctrl+c again to exit') : this.modeLabel() || c.faint('? shortcuts');
|
|
828
|
+
const right = c.mist(this.statusLine());
|
|
829
|
+
const gap = Math.max(2, cols - 3 - visibleLength(left) - visibleLength(right));
|
|
792
830
|
lines.push(truncate(` ${left}${' '.repeat(gap)}${right}`, cols - 1));
|
|
793
831
|
}
|
|
794
832
|
return { lines, cursorRow, cursorCol };
|
|
795
833
|
}
|
|
796
834
|
|
|
835
|
+
// A permission request: a card with an orchid edge, the preview, and choices.
|
|
797
836
|
menuLayout(lines, cols) {
|
|
798
837
|
const c = this.c;
|
|
799
838
|
const m = this.menu;
|
|
800
|
-
const
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
|
|
839
|
+
const bar = c.orchid(GLYPH.user);
|
|
840
|
+
const inner = cols - 3;
|
|
841
|
+
const row = (s = '') => `${bar} ${truncate(s, inner)}`;
|
|
842
|
+
const label = { edit_file: 'Edit', write_file: 'Write', bash: 'Bash', web_fetch: 'Fetch' }[m.toolName] ?? (m.toolName ?? '').replace(/^mcp__/, '').replace(/__/, ':');
|
|
843
|
+
let title = m.preview?.title ?? 'wants to run';
|
|
844
|
+
if (title.toLowerCase().startsWith(label.toLowerCase() + ' ')) title = title.slice(label.length + 1);
|
|
845
|
+
lines.push(row(`${c.violet(GLYPH.tool)} ${c.bold(c.lilac(label))} ${c.mist(title)}`));
|
|
804
846
|
const body = m.preview?.lines ?? [];
|
|
805
847
|
if (body.length) {
|
|
806
|
-
lines.push(
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
const
|
|
810
|
-
|
|
848
|
+
lines.push(bar);
|
|
849
|
+
const w = Math.max(20, inner - 8);
|
|
850
|
+
for (const { sign, text, n } of body.slice(0, 16)) {
|
|
851
|
+
const num = n !== undefined ? c.faint(String(n).padStart(4)) : ' ';
|
|
852
|
+
const t = truncate(`${sign} ${text}`, w);
|
|
853
|
+
const padded = t + ' '.repeat(Math.max(0, w - visibleLength(t)));
|
|
854
|
+
const styled = sign === '+' ? c.addBg(c.mint(padded)) : sign === '-' ? c.delBg(c.rose(padded)) : sign === '$' ? c.panelBg(c.lilac(padded)) : c.mist(t);
|
|
855
|
+
lines.push(row(`${num} ${styled}`));
|
|
811
856
|
}
|
|
812
|
-
if (body.length >
|
|
813
|
-
}
|
|
814
|
-
lines.push(
|
|
815
|
-
|
|
816
|
-
m.options.
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
lines.push(row(sel ? `${c.accent('❯')} ${c.accent(text)}` : ` ${text}`));
|
|
857
|
+
if (body.length > 16) lines.push(row(c.faint(` +${body.length - 16} more lines`)));
|
|
858
|
+
}
|
|
859
|
+
lines.push(bar);
|
|
860
|
+
// Choices as chips side by side, or stacked when the terminal is narrow.
|
|
861
|
+
const chips = m.options.map((o, i) => {
|
|
862
|
+
const text = ` ${i + 1} ${o.label} `;
|
|
863
|
+
return i === m.selected ? c.violetBg(c.ink(c.bold(text))) : c.raiseBg(c.lilac(text));
|
|
820
864
|
});
|
|
821
|
-
|
|
865
|
+
const together = chips.join(' ');
|
|
866
|
+
if (visibleLength(together) <= inner - 2) lines.push(row(together));
|
|
867
|
+
else chips.forEach((chip) => lines.push(row(chip)));
|
|
868
|
+
lines.push(row(c.faint('←→ choose · enter confirm · esc to say no')));
|
|
822
869
|
return { lines, cursorRow: lines.length - 1, cursorCol: 0 };
|
|
823
870
|
}
|
|
824
871
|
|
|
@@ -828,41 +875,78 @@ export class FancyUI extends UI {
|
|
|
828
875
|
const c = this.c;
|
|
829
876
|
const home = process.env.HOME ?? '';
|
|
830
877
|
const tild = (p) => (home && p.startsWith(home) ? '~' + p.slice(home.length) : p);
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
c.
|
|
837
|
-
c.
|
|
878
|
+
const side = [`${c.lilac(c.bold('arrakis'))} ${c.mist(`v${version}`)}`, c.mist('a coding agent by Mumbrane')];
|
|
879
|
+
let out = '\n';
|
|
880
|
+
LOGO.forEach((row, i) => (out += ` ${c.bold(c.gradient(row))} ${side[i] ?? ''}\n`));
|
|
881
|
+
out += '\n';
|
|
882
|
+
const facts = [
|
|
883
|
+
['model', `${c.lilac(model)} ${c.faint('·')} ${c.mist(provider)}`],
|
|
884
|
+
['folder', c.lilac(middle(tild(cwd), Math.max(20, (this.out.columns || 100) - 16)))],
|
|
838
885
|
];
|
|
839
|
-
if (
|
|
840
|
-
if (mcp.length)
|
|
841
|
-
if (hooks)
|
|
842
|
-
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
out += `\n ${c.gray('Tips for getting started:')}\n`;
|
|
849
|
-
const tips = [
|
|
850
|
-
instructions.length ? null : 'Run /init to write an ARRAKIS.md with notes about this project',
|
|
851
|
-
'Ask about the code, or ask for a change, a fix or a new feature',
|
|
852
|
-
'Use /plan for big changes, so arrakis proposes a plan before editing',
|
|
853
|
-
'Mention files with @, and press shift+tab to let it edit without asking',
|
|
854
|
-
].filter(Boolean);
|
|
855
|
-
tips.forEach((t, i) => (out += ` ${c.gray(`${i + 1}. ${t}`)}\n`));
|
|
856
|
-
}
|
|
886
|
+
if (instructions.length) facts.push(['notes', c.lilac(instructions.map((f) => tild(f).split('/').pop()).join(', '))]);
|
|
887
|
+
if (mcp.length) facts.push(['mcp', mcp.map((s) => (s.status === 'connected' ? `${c.lilac(s.name)} ${c.faint(`${s.tools.length} tools`)}` : c.rose(`${s.name} failed`))).join(c.faint(' · '))]);
|
|
888
|
+
if (hooks) facts.push(['hooks', c.lilac(`${hooks} active`)]);
|
|
889
|
+
if (resumed) facts.push(['session', c.lilac(resumed)]);
|
|
890
|
+
for (const [k, v] of facts) out += ` ${c.iris(GLYPH.tool)} ${c.mist(k.padEnd(8))} ${v}\n`;
|
|
891
|
+
if (update) out += `\n ${c.orchid('↑')} ${c.lilac(`arrakis ${update} is out`)} ${c.faint('·')} ${c.mist('npm install -g @mumbrane/arrakis')}\n`;
|
|
892
|
+
out += `\n ${c.mist(instructions.length || resumed ? 'What are we building?' : 'Ask a question, describe a task, or run /init to map this project.')}\n`;
|
|
893
|
+
const k = (key, desc) => `${c.violet(key)} ${c.faint(desc)}`;
|
|
894
|
+
out += ` ${[k('/', 'commands'), k('@', 'files'), k('⇧⇥', 'modes'), k('esc', 'interrupt'), k('?', 'shortcuts')].join(' ')}\n`;
|
|
857
895
|
this.printAbove(out + '\n');
|
|
858
896
|
}
|
|
859
897
|
|
|
860
898
|
info(msg) {
|
|
861
899
|
this.endText();
|
|
862
|
-
this.write(this.out, this.c.
|
|
900
|
+
this.write(this.out, this.c.mist(msg) + '\n');
|
|
863
901
|
}
|
|
864
902
|
}
|
|
865
903
|
|
|
904
|
+
// Shorten a path in the middle: ~/projects/…/src/app.js
|
|
905
|
+
function middle(s, max) {
|
|
906
|
+
if (s.length <= max) return s;
|
|
907
|
+
const keep = max - 1;
|
|
908
|
+
return s.slice(0, Math.ceil(keep * 0.35)) + '…' + s.slice(s.length - Math.floor(keep * 0.65));
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// Word-wrap a styled line to `width` visible columns. Continuation lines get
|
|
912
|
+
// a hanging indent that lines up with the text after a bullet or number.
|
|
913
|
+
export function wrapAnsi(line, width) {
|
|
914
|
+
if (visibleLength(line) <= width) return [line];
|
|
915
|
+
const plain = line.replace(/\x1b\[[0-9;]*m/g, '');
|
|
916
|
+
const lead = plain.match(/^(\s*(?:[•◦○●◉┃]|\d+\.)?\s*)/)?.[1] ?? '';
|
|
917
|
+
const indent = ' '.repeat(Math.min(lead.length, Math.floor(width / 2)));
|
|
918
|
+
const tokens = line.match(/\x1b\[[0-9;]*m|\s+|[^\s\x1b]+/g) ?? [];
|
|
919
|
+
const rows = [];
|
|
920
|
+
let cur = '';
|
|
921
|
+
let len = 0;
|
|
922
|
+
for (const t of tokens) {
|
|
923
|
+
if (t.startsWith('\x1b')) {
|
|
924
|
+
cur += t;
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
if (len + t.length > width && len > indent.length) {
|
|
928
|
+
rows.push(cur);
|
|
929
|
+
cur = indent;
|
|
930
|
+
len = indent.length;
|
|
931
|
+
if (/^\s+$/.test(t)) continue;
|
|
932
|
+
}
|
|
933
|
+
// A single word longer than the line: hard-break it.
|
|
934
|
+
let word = t;
|
|
935
|
+
while (len + word.length > width) {
|
|
936
|
+
const room = width - len;
|
|
937
|
+
cur += word.slice(0, room);
|
|
938
|
+
rows.push(cur);
|
|
939
|
+
word = word.slice(room);
|
|
940
|
+
cur = indent;
|
|
941
|
+
len = indent.length;
|
|
942
|
+
}
|
|
943
|
+
cur += word;
|
|
944
|
+
len += word.length;
|
|
945
|
+
}
|
|
946
|
+
if (cur.trim()) rows.push(cur);
|
|
947
|
+
return rows;
|
|
948
|
+
}
|
|
949
|
+
|
|
866
950
|
// Wrap text into rows of at most `width` characters, tracking source offsets.
|
|
867
951
|
function wrap(text, width) {
|
|
868
952
|
const rows = [];
|
package/src/ui.js
CHANGED
|
@@ -2,22 +2,12 @@ import readline from 'node:readline';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import { MarkdownStream, visibleLength } from './markdown.js';
|
|
5
|
+
import { makeTheme, GLYPH } from './theme.js';
|
|
5
6
|
|
|
6
|
-
const colorOn = (stream) => stream.isTTY && !process.env.NO_COLOR;
|
|
7
|
-
const paint = (code, on) => (s) => (on ? `\x1b[${code}m${s}\x1b[0m` : String(s));
|
|
7
|
+
const colorOn = (stream) => Boolean(stream.isTTY) && !process.env.NO_COLOR;
|
|
8
8
|
|
|
9
9
|
export function colors(stream = process.stdout) {
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
on,
|
|
13
|
-
dim: paint('2', on), bold: paint('1', on), italic: paint('3', on), underline: paint('4', on),
|
|
14
|
-
red: paint('31', on), green: paint('32', on), yellow: paint('33', on),
|
|
15
|
-
blue: paint('34', on), magenta: paint('35', on), cyan: paint('36', on),
|
|
16
|
-
gray: paint('90', on),
|
|
17
|
-
accent: paint('38;5;208', on), // spice orange
|
|
18
|
-
sand: paint('38;5;180', on),
|
|
19
|
-
userBg: paint('48;5;236', on),
|
|
20
|
-
};
|
|
10
|
+
return makeTheme(colorOn(stream));
|
|
21
11
|
}
|
|
22
12
|
|
|
23
13
|
const SPINNER = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
@@ -249,7 +239,7 @@ export class UI {
|
|
|
249
239
|
};
|
|
250
240
|
const draw = () => {
|
|
251
241
|
const secs = Math.floor((Date.now() - spinner.started) / 1000);
|
|
252
|
-
let line = `${lc.
|
|
242
|
+
let line = `${lc.orchid(SPINNER[spinner.frame % SPINNER.length])} ${lc.shimmer(spinner.label + '…', spinner.frame++)} ${lc.faint(`${secs}s · esc to interrupt`)}`;
|
|
253
243
|
if (spinner.detail) line += lc.gray(` ${spinner.detail}`);
|
|
254
244
|
stream.write(`\r\x1b[2K${truncate(line, this.width)}`);
|
|
255
245
|
spinner.drawn = true;
|
|
@@ -314,96 +304,100 @@ export class UI {
|
|
|
314
304
|
|
|
315
305
|
toolStart(name, summary, { prefix = '' } = {}) {
|
|
316
306
|
this.endText();
|
|
317
|
-
const
|
|
318
|
-
const
|
|
307
|
+
const t = this.lc;
|
|
308
|
+
const sum = String(summary ?? '').split('\n')[0];
|
|
319
309
|
const label = TOOL_LABELS[name] ?? name;
|
|
320
|
-
|
|
321
|
-
|
|
310
|
+
if (prefix) {
|
|
311
|
+
// A sub-agent's tool call, nested under its parent.
|
|
312
|
+
this.write(this.log, truncate(` ${t.faint('│')} ${t.mist(prefix)} ${t.faint('·')} ${t.lilac(label)}${sum ? ` ${t.mist(sum)}` : ''}`, this.width) + '\n');
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const lead = this.atLineStart ? '' : '\n';
|
|
316
|
+
this.write(this.log, truncate(`${lead}${t.violet(GLYPH.tool)} ${t.bold(t.lilac(label))}${sum ? ` ${t.mist(sum)}` : ''}`, this.width) + '\n');
|
|
322
317
|
}
|
|
323
318
|
|
|
324
319
|
toolResult(result, isError = false, { lines: extra } = {}) {
|
|
325
|
-
const
|
|
320
|
+
const t = this.lc;
|
|
326
321
|
const all = String(result).split('\n');
|
|
327
322
|
const shown = all.slice(0, 4).map((l) => truncate(l, this.width - 6));
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
323
|
+
const color = isError ? t.rose : t.mist;
|
|
324
|
+
let body = shown.map((l, i) => ` ${i === 0 ? t.faint(GLYPH.result) : ' '} ${color(l)}`).join('\n');
|
|
325
|
+
if (all.length > 4) body += `\n ${t.faint(`+${all.length - 4} more lines`)}`;
|
|
326
|
+
this.write(this.log, body + '\n');
|
|
331
327
|
if (extra?.length) this.diff(extra);
|
|
332
328
|
}
|
|
333
329
|
|
|
334
|
-
|
|
335
|
-
|
|
330
|
+
// Diff lines on tinted backgrounds, with line numbers.
|
|
331
|
+
diff(lines, { indent = ' ', width } = {}) {
|
|
332
|
+
const t = this.lc;
|
|
333
|
+
const w = Math.max(20, (width ?? this.width) - indent.length - 6);
|
|
336
334
|
for (const { sign, text, n } of lines) {
|
|
337
|
-
const num = n !== undefined ?
|
|
338
|
-
const body = truncate(`${sign} ${text}`,
|
|
339
|
-
|
|
335
|
+
const num = n !== undefined ? t.faint(String(n).padStart(4)) : ' ';
|
|
336
|
+
const body = truncate(`${sign === ' ' ? ' ' : sign} ${text}`, w);
|
|
337
|
+
const padded = body + ' '.repeat(Math.max(0, w - visibleLength(body)));
|
|
338
|
+
const line =
|
|
339
|
+
sign === '+' ? t.addBg(t.mint(padded))
|
|
340
|
+
: sign === '-' ? t.delBg(t.rose(padded))
|
|
341
|
+
: sign === '$' ? t.panelBg(t.lilac(padded))
|
|
342
|
+
: t.mist(body);
|
|
343
|
+
this.write(this.log, `${indent}${num} ${line}\n`);
|
|
340
344
|
}
|
|
341
345
|
}
|
|
342
346
|
|
|
343
347
|
todos(list) {
|
|
344
|
-
const
|
|
345
|
-
for (const
|
|
346
|
-
const
|
|
347
|
-
const
|
|
348
|
-
|
|
348
|
+
const t = this.lc;
|
|
349
|
+
for (const item of list) {
|
|
350
|
+
const g = GLYPH.todo[item.status] ?? GLYPH.todo.pending;
|
|
351
|
+
const line =
|
|
352
|
+
item.status === 'completed' ? `${t.mint(g)} ${t.mist(t.strike(item.content))}`
|
|
353
|
+
: item.status === 'in_progress' ? `${t.orchid(g)} ${t.bold(t.lilac(item.content))}`
|
|
354
|
+
: `${t.mist(g)} ${t.lilac(item.content)}`;
|
|
355
|
+
this.write(this.log, ` ${line}\n`);
|
|
349
356
|
}
|
|
350
357
|
}
|
|
351
358
|
|
|
352
359
|
async confirm(preview) {
|
|
353
360
|
this.stopSpinner();
|
|
354
|
-
const
|
|
361
|
+
const t = this.lc;
|
|
355
362
|
if (preview) {
|
|
356
|
-
this.write(this.log, ` ${
|
|
363
|
+
this.write(this.log, ` ${t.orchid(GLYPH.user)} ${t.bold(t.lilac(preview.title))}\n`);
|
|
357
364
|
if (preview.lines?.length) this.diff(preview.lines);
|
|
358
365
|
}
|
|
359
|
-
const answer = await this.readLine(` ${
|
|
366
|
+
const answer = await this.readLine(` ${t.orchid(GLYPH.user)} ${t.bold('Allow?')} ${t.mist('[y]es [a]lways this session [n]o')} `);
|
|
360
367
|
const a = (answer ?? 'n').trim().toLowerCase();
|
|
361
368
|
if (a === 'a' || a === 'always') return 'always';
|
|
362
369
|
if (a === 'y' || a === 'yes' || a === '') return 'yes';
|
|
363
370
|
return 'no';
|
|
364
371
|
}
|
|
365
372
|
|
|
366
|
-
banner({ version, model, provider, cwd
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
`${c.gray('model ')} ${c.bold(model)} ${c.gray(`· ${provider}`)}`,
|
|
379
|
-
`${c.gray('folder ')} ${tildify(cwd)}`,
|
|
380
|
-
];
|
|
381
|
-
if (instructions.length) rows.push(`${c.gray('notes ')} ${instructions.map((f) => tildify(f)).join(', ')}`);
|
|
382
|
-
if (resumed) rows.push(`${c.gray('session ')} ${resumed}`);
|
|
383
|
-
if (mcp.length) rows.push(`${c.gray('mcp ')} ${mcp.map((s) => (s.status === 'connected' ? `${s.name} ${c.gray(`(${s.tools.length})`)}` : c.red(`${s.name} ✗`))).join(', ')}`);
|
|
384
|
-
if (hooks) rows.push(`${c.gray('hooks ')} ${hooks} active`);
|
|
385
|
-
rows.push('', c.gray('/help commands · @file attach · /plan plan first · /undo revert · esc interrupt'));
|
|
386
|
-
const inner = Math.min(this.width - 4, Math.max(...rows.map(visibleLength)) + 2);
|
|
387
|
-
const line = (s) => `${c.accent('│')} ${truncate(s, inner)}${' '.repeat(Math.max(0, inner - visibleLength(truncate(s, inner))))} ${c.accent('│')}`;
|
|
388
|
-
const out = [c.accent(`╭${'─'.repeat(inner + 2)}╮`), ...rows.map(line), c.accent(`╰${'─'.repeat(inner + 2)}╯`)];
|
|
389
|
-
this.write(this.out, '\n' + out.join('\n') + '\n');
|
|
390
|
-
if (update) this.write(this.out, ` ${c.accent('↑')} ${c.bold(`arrakis ${update} is available`)} ${c.gray('· npm install -g @mumbrane/arrakis')}\n`);
|
|
391
|
-
else if (!instructions.length) this.write(this.out, c.gray(' Tip: run /init to have arrakis write project notes (ARRAKIS.md) for this folder.\n'));
|
|
373
|
+
banner({ version, model, provider, cwd }) {
|
|
374
|
+
const t = this.c;
|
|
375
|
+
this.write(this.out, `\n ${t.gradient('◆ arrakis')} ${t.mist(`v${version}`)}\n`);
|
|
376
|
+
this.write(this.out, t.mist(` ${model} · ${provider} · ${cwd}\n`));
|
|
377
|
+
this.write(this.out, t.mist(' /help for commands · Ctrl-C to interrupt · Ctrl-D to quit\n\n'));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Clear the screen and the scrollback.
|
|
381
|
+
clearScreen() {
|
|
382
|
+
this.endText();
|
|
383
|
+
if (this.out.isTTY) this.out.write('\x1b[2J\x1b[3J\x1b[H');
|
|
384
|
+
this.atLineStart = true;
|
|
392
385
|
}
|
|
393
386
|
|
|
394
387
|
info(msg) {
|
|
395
388
|
this.endText();
|
|
396
|
-
this.write(this.log, this.lc.
|
|
389
|
+
this.write(this.log, this.lc.mist(msg) + '\n');
|
|
397
390
|
}
|
|
398
391
|
|
|
399
392
|
success(msg) {
|
|
400
393
|
this.endText();
|
|
401
|
-
this.write(this.log, `${this.lc.
|
|
394
|
+
this.write(this.log, `${this.lc.mint(GLYPH.ok)} ${this.lc.lilac(msg)}\n`);
|
|
402
395
|
}
|
|
403
396
|
|
|
404
397
|
error(msg) {
|
|
405
398
|
this.endText();
|
|
406
|
-
|
|
399
|
+
const [first, ...rest] = String(msg).split('\n');
|
|
400
|
+
this.write(this.log, `${this.lc.rose(GLYPH.fail)} ${this.lc.rose(first)}${rest.length ? '\n' + rest.map((l) => ` ${this.lc.mist(l)}`).join('\n') : ''}\n`);
|
|
407
401
|
}
|
|
408
402
|
}
|
|
409
403
|
|