@mumbrane/arrakis 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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 lines = text.split('\n');
190
- this.printAbove(lines.map((l, i) => c.gray(`${i === 0 ? '>' : ' '} ${l}`)).join('\n') + '\n\n');
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) {
@@ -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: `Yes, and don't ask again for ${what} this session`, value: 'always' },
478
- { label: 'No, and tell arrakis what to do differently', hint: 'esc', value: '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.gray('⎿')} ${this.c.red('Declined')}\n`);
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);
@@ -512,6 +528,8 @@ export class FancyUI extends UI {
512
528
 
513
529
  // Print complete lines above the live region.
514
530
  printAbove(s) {
531
+ this.lastBlank = s.endsWith('\n\n') || (s === '\n' && this.lastEndsNewline);
532
+ this.lastEndsNewline = s.endsWith('\n');
515
533
  this.transcript.push(s);
516
534
  this.transcriptSize += s.length;
517
535
  while (this.transcriptSize > 2_000_000 && this.transcript.length > 1) this.transcriptSize -= this.transcript.shift().length;
@@ -561,7 +579,10 @@ export class FancyUI extends UI {
561
579
 
562
580
  text(s) {
563
581
  this.addTokens(s.length / 4);
564
- if (this.mode === 'thinking') this.flushPartial();
582
+ if (this.mode === 'thinking') {
583
+ this.flushThinking();
584
+ this.mode = null;
585
+ }
565
586
  if (this.mode !== 'text') {
566
587
  this.md = new MarkdownStream(this.c, { width: this.width - 2 });
567
588
  this.firstLine = true;
@@ -574,20 +595,46 @@ export class FancyUI extends UI {
574
595
  if (!rendered) return;
575
596
  const lines = rendered.split('\n');
576
597
  lines.pop();
577
- const out = lines.map((l) => {
578
- const prefix = this.firstLine ? `${this.c.bold('⏺')} ` : ' ';
579
- this.firstLine = false;
580
- return prefix + l;
581
- });
598
+ const width = Math.max(20, (this.out.columns || 100) - 3);
599
+ const out = [];
600
+ for (const l of lines) {
601
+ for (const [i, part] of wrapAnsi(l, width).entries()) {
602
+ const prefix = this.firstLine ? `${this.c.violet(GLYPH.reply)} ` : ' ';
603
+ this.firstLine = false;
604
+ out.push(prefix + (i ? part.replace(/^/, '') : part));
605
+ }
606
+ }
582
607
  this.write(this.out, out.join('\n') + '\n');
583
608
  }
584
609
 
585
610
  thinking(s) {
586
611
  this.addTokens(s.length / 4);
587
612
  if (this.spinner) this.spinner.label = 'Thinking';
613
+ if (this.mode === 'text') this.endText();
614
+ this.mode = 'thinking';
615
+ this.thinkBuf = (this.thinkBuf ?? '') + s;
616
+ }
617
+
618
+ // Print the thinking summary, dim, above the reply.
619
+ flushThinking() {
620
+ const text = (this.thinkBuf ?? '').trim();
621
+ this.thinkBuf = '';
622
+ if (!text) return;
623
+ const c = this.c;
624
+ const width = Math.max(20, this.width - 4);
625
+ const rows = [];
626
+ for (const para of text.split('\n')) {
627
+ if (!para.trim()) continue;
628
+ for (let i = 0; i < para.length; i += width) rows.push(para.slice(i, i + width));
629
+ }
630
+ const shown = rows.slice(0, 10);
631
+ const out = shown.map((r, i) => `${i === 0 ? `${c.orchid(GLYPH.thinking)} ` : ' '}${c.mist(c.italic(r))}`);
632
+ if (rows.length > shown.length) out.push(` ${c.faint(`+${rows.length - shown.length} more lines of thinking`)}`);
633
+ this.printAbove((this.lastBlank ? '' : '\n') + out.join('\n') + '\n\n');
588
634
  }
589
635
 
590
636
  endText() {
637
+ if (this.thinkBuf) this.flushThinking();
591
638
  if (this.md) {
592
639
  this.emitText(this.md.flush());
593
640
  this.md = null;
@@ -698,100 +745,109 @@ export class FancyUI extends UI {
698
745
  const c = this.c;
699
746
  const cols = Math.max(30, (this.out.columns || 100) - 1);
700
747
  const lines = [];
701
- if (this.spinner) {
748
+ if (this.spinner && !this.menu) {
702
749
  const s = this.spinner;
703
750
  const secs = Math.floor((Date.now() - s.started) / 1000);
704
751
  const meta = [`${secs}s`];
705
- if (this.tokens >= 1) meta.push(`↓ ${fmtTokens(Math.round(this.tokens))} tokens`);
752
+ if (this.tokens >= 1) meta.push(`↓ ${fmtTokens(Math.round(this.tokens))}`);
706
753
  meta.push('esc to interrupt');
707
- let line = `${c.accent(SPIN[s.frame % SPIN.length])} ${c.accent(s.label + '…')} ${c.gray(`(${meta.join(' · ')})`)}`;
708
- if (s.detail) line += c.gray(` ⎿ ${s.detail}`);
709
- lines.push(truncate(line, cols - 1), '');
754
+ lines.push(truncate(`${c.orchid(SPIN[s.frame % SPIN.length])} ${c.shimmer(s.label + '…', s.frame)} ${c.faint(meta.join(' · '))}`, cols - 1));
755
+ if (s.detail) lines.push(truncate(` ${c.faint(GLYPH.result)} ${c.mist(s.detail)}`, cols - 1));
756
+ lines.push('');
710
757
  }
711
758
 
712
759
  if (this.menu) return this.menuLayout(lines, cols);
713
760
 
714
- for (const q of this.queued) lines.push(truncate(c.gray(` ⎿ queued: ${q.replace(/\n/g, ' ')}`), cols - 1));
761
+ 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));
715
762
  if (this.queued.length) lines.push('');
716
763
  if (this.pending?.label) lines.push(truncate(this.pending.label.trimEnd(), cols - 1));
717
764
 
718
- // Input box
719
- const inner = cols - 4;
720
- const width = Math.max(10, inner - 2);
765
+ // The input rail: a gradient line (it drifts while arrakis works), then the prompt.
766
+ const phase = this.busy && this.spinner ? (this.spinner.frame * 0.015) % 1 : 0;
767
+ lines.push(this.busy ? c.gradient('─'.repeat(cols), [PALETTE.iris, PALETTE.violet, PALETTE.dusk, PALETTE.iris], phase) : c.gradient('─'.repeat(cols)));
768
+ const width = Math.max(10, cols - 3);
721
769
  const shown = this.pending?.secret ? '•'.repeat(this.buffer.length) : this.buffer;
722
770
  const rows = wrap(shown, width);
723
- const boxTop = lines.length;
724
- const border = this.busy && !this.pending ? c.gray : (s) => c.gray(s);
725
- lines.push(border(`╭${'─'.repeat(cols - 2)}╮`));
771
+ const top = lines.length;
726
772
  let cursorRow = null;
727
773
  let cursorCol = 0;
728
- const placeholder = !this.buffer && !this.pending?.label ? (this.busy ? 'Type to queue a message…' : 'Ask arrakis anything, / for commands, @ for files') : '';
774
+ const placeholder = !this.buffer && !this.pending?.label ? (this.busy ? 'Type ahead; your message will be sent next' : 'Ask, plan or build something. / commands @ files') : '';
729
775
  rows.forEach((r, i) => {
730
- const prefix = i === 0 ? c.accent('> ') : ' ';
731
- const body = placeholder && i === 0 ? c.gray(truncate(placeholder, width)) : r.text;
732
- const pad = Math.max(0, width - visibleLength(body));
733
- lines.push(`${border('│')} ${prefix}${body}${' '.repeat(pad)} ${border('│')}`);
776
+ const prefix = i === 0 ? `${this.busy ? c.iris(GLYPH.prompt) : c.orchid(GLYPH.prompt)} ` : ' ';
777
+ const body = placeholder && i === 0 ? c.faint(c.italic(truncate(placeholder, width))) : c.lilac(r.text);
778
+ lines.push(`${prefix}${body}`);
734
779
  if (this.cursor >= r.start && this.cursor <= r.end && cursorRow === null) {
735
780
  if (this.cursor === r.end && r.full && i < rows.length - 1) return;
736
781
  cursorRow = lines.length - 1;
737
- cursorCol = 4 + (this.cursor - r.start);
782
+ cursorCol = 2 + (this.cursor - r.start);
738
783
  }
739
784
  });
740
785
  if (cursorRow === null) {
741
- cursorRow = boxTop + rows.length;
742
- cursorCol = 4 + (rows.at(-1)?.text.length ?? 0);
786
+ cursorRow = top + rows.length - 1;
787
+ cursorCol = 2 + (rows.at(-1)?.text.length ?? 0);
743
788
  }
744
- lines.push(border(`╰${'─'.repeat(cols - 2)}╯`));
745
789
 
746
- // Below the box: suggestions, shortcuts, or the hint line.
790
+ // Below the input: suggestions, shortcuts, or the hint line.
747
791
  if (this.suggest) {
792
+ const labelW = Math.min(28, Math.max(...this.suggest.items.map((x) => x.label.length)) + 2);
748
793
  for (const [i, item] of this.suggest.items.slice(0, 8).entries()) {
749
794
  const sel = i === this.suggest.selected;
750
- const label = sel ? c.accent(item.label) : item.label;
751
- const hint = item.hint ? ` ${c.gray(item.hint)}` : '';
752
- lines.push(truncate(` ${label.padEnd ? label : label}${' '.repeat(Math.max(1, 22 - item.label.length))}${hint}`, cols - 1));
795
+ const label = item.label.padEnd(labelW);
796
+ const row = ` ${sel ? c.bold(c.violet(label)) : c.lilac(label)}${item.hint ? (sel ? c.lilac(item.hint) : c.mist(item.hint)) : ''}`;
797
+ const fit = truncate(row, cols - 1);
798
+ lines.push(sel ? c.raiseBg(fit + ' '.repeat(Math.max(0, cols - 1 - visibleLength(fit)))) : fit);
753
799
  }
754
800
  } else if (this.showHelp) {
801
+ const k = (key, desc) => `${c.violet(key)} ${c.mist(desc)}`;
755
802
  const help = [
756
- ['/ for commands', '@ for file paths', '\\⏎ or shift+⏎ for newline'],
757
- ['shift+tab to cycle modes', 'esc to interrupt', '↑↓ for history'],
758
- ['ctrl+c to clear / exit', 'tab to complete', 'esc esc to clear input'],
803
+ [k('/', 'commands'), k('@', 'attach files'), k('\\⏎', 'new line')],
804
+ [k('⇧⇥', 'cycle modes'), k('esc', 'interrupt'), k('↑↓', 'history')],
805
+ [k('tab', 'complete'), k('esc esc', 'clear input'), k('ctrl+c', 'clear / exit')],
759
806
  ];
760
- for (const row of help) lines.push(c.gray(' ' + row.map((x) => x.padEnd(28)).join('')));
807
+ for (const row of help) lines.push(' ' + row.map((x) => x + ' '.repeat(Math.max(2, 24 - visibleLength(x)))).join(''));
761
808
  } else {
762
- const left = this.exitArmed ? c.yellow('Press Ctrl-C again to exit') : this.modeLabel() || c.gray('? for shortcuts');
763
- const right = c.gray(this.statusLine());
764
- const gap = Math.max(2, cols - 2 - visibleLength(left) - visibleLength(right));
809
+ const left = this.exitArmed ? c.amber('press ctrl+c again to exit') : this.modeLabel() || c.faint('? shortcuts');
810
+ const right = c.mist(this.statusLine());
811
+ const gap = Math.max(2, cols - 3 - visibleLength(left) - visibleLength(right));
765
812
  lines.push(truncate(` ${left}${' '.repeat(gap)}${right}`, cols - 1));
766
813
  }
767
814
  return { lines, cursorRow, cursorCol };
768
815
  }
769
816
 
817
+ // A permission request: a card with an orchid edge, the preview, and choices.
770
818
  menuLayout(lines, cols) {
771
819
  const c = this.c;
772
820
  const m = this.menu;
773
- const inner = cols - 4;
774
- const row = (s = '') => `${c.accent('│')} ${truncate(s, inner)}${' '.repeat(Math.max(0, inner - visibleLength(truncate(s, inner))))} ${c.accent('│')}`;
775
- lines.push(c.accent(`╭${'─'.repeat(cols - 2)}╮`));
776
- lines.push(row(c.bold(m.preview?.title ?? 'Allow this action?')));
821
+ const bar = c.orchid(GLYPH.user);
822
+ const inner = cols - 3;
823
+ const row = (s = '') => `${bar} ${truncate(s, inner)}`;
824
+ const label = { edit_file: 'Edit', write_file: 'Write', bash: 'Bash', web_fetch: 'Fetch' }[m.toolName] ?? (m.toolName ?? '').replace(/^mcp__/, '').replace(/__/, ':');
825
+ let title = m.preview?.title ?? 'wants to run';
826
+ if (title.toLowerCase().startsWith(label.toLowerCase() + ' ')) title = title.slice(label.length + 1);
827
+ lines.push(row(`${c.violet(GLYPH.tool)} ${c.bold(c.lilac(label))} ${c.mist(title)}`));
777
828
  const body = m.preview?.lines ?? [];
778
829
  if (body.length) {
779
- lines.push(row());
780
- for (const { sign, text, n } of body.slice(0, 18)) {
781
- const num = n !== undefined ? c.gray(String(n).padStart(4) + ' ') : ' ';
782
- const t = `${sign} ${text}`;
783
- lines.push(row(`${num}${sign === '+' ? c.green(t) : sign === '-' ? c.red(t) : c.gray(t)}`));
830
+ lines.push(bar);
831
+ const w = Math.max(20, inner - 8);
832
+ for (const { sign, text, n } of body.slice(0, 16)) {
833
+ const num = n !== undefined ? c.faint(String(n).padStart(4)) : ' ';
834
+ const t = truncate(`${sign} ${text}`, w);
835
+ const padded = t + ' '.repeat(Math.max(0, w - visibleLength(t)));
836
+ const styled = sign === '+' ? c.addBg(c.mint(padded)) : sign === '-' ? c.delBg(c.rose(padded)) : sign === '$' ? c.panelBg(c.lilac(padded)) : c.mist(t);
837
+ lines.push(row(`${num} ${styled}`));
784
838
  }
785
- if (body.length > 18) lines.push(row(c.gray(` … ${body.length - 18} more lines`)));
786
- }
787
- lines.push(row());
788
- lines.push(row('Do you want to proceed?'));
789
- m.options.forEach((o, i) => {
790
- const sel = i === m.selected;
791
- const text = `${i + 1}. ${o.label}${o.hint ? c.gray(` (${o.hint})`) : ''}`;
792
- lines.push(row(sel ? `${c.accent('❯')} ${c.accent(text)}` : ` ${text}`));
839
+ if (body.length > 16) lines.push(row(c.faint(` +${body.length - 16} more lines`)));
840
+ }
841
+ lines.push(bar);
842
+ // Choices as chips side by side, or stacked when the terminal is narrow.
843
+ const chips = m.options.map((o, i) => {
844
+ const text = ` ${i + 1} ${o.label} `;
845
+ return i === m.selected ? c.violetBg(c.ink(c.bold(text))) : c.raiseBg(c.lilac(text));
793
846
  });
794
- lines.push(c.accent(`╰${'─'.repeat(cols - 2)}╯`));
847
+ const together = chips.join(' ');
848
+ if (visibleLength(together) <= inner - 2) lines.push(row(together));
849
+ else chips.forEach((chip) => lines.push(row(chip)));
850
+ lines.push(row(c.faint('←→ choose · enter confirm · esc to say no')));
795
851
  return { lines, cursorRow: lines.length - 1, cursorCol: 0 };
796
852
  }
797
853
 
@@ -801,41 +857,78 @@ export class FancyUI extends UI {
801
857
  const c = this.c;
802
858
  const home = process.env.HOME ?? '';
803
859
  const tild = (p) => (home && p.startsWith(home) ? '~' + p.slice(home.length) : p);
804
- const rows = [
805
- `${c.accent('◆')} Welcome to ${c.bold('Arrakis')}!`,
806
- '',
807
- c.gray(' /help for commands, /status for your current setup'),
808
- '',
809
- c.gray(` cwd: ${tild(cwd)}`),
810
- c.gray(` model: ${model} · ${provider}`),
860
+ const side = [`${c.lilac(c.bold('arrakis'))} ${c.mist(`v${version}`)}`, c.mist('a coding agent by Mumbrane')];
861
+ let out = '\n';
862
+ LOGO.forEach((row, i) => (out += ` ${c.bold(c.gradient(row))} ${side[i] ?? ''}\n`));
863
+ out += '\n';
864
+ const facts = [
865
+ ['model', `${c.lilac(model)} ${c.faint('·')} ${c.mist(provider)}`],
866
+ ['folder', c.lilac(middle(tild(cwd), Math.max(20, (this.out.columns || 100) - 16)))],
811
867
  ];
812
- if (resumed) rows.push(c.gray(` session: ${resumed}`));
813
- if (mcp.length) rows.push(c.gray(` mcp: ${mcp.map((s) => (s.status === 'connected' ? `${s.name} (${s.tools.length} tools)` : `${s.name} (failed)`)).join(', ')}`));
814
- if (hooks) rows.push(c.gray(` hooks: ${hooks} active`));
815
- const cols = Math.max(30, (this.out.columns || 100) - 1);
816
- const inner = Math.min(cols - 4, Math.max(46, ...rows.map(visibleLength)));
817
- const line = (s) => `${c.accent('│')} ${truncate(s, inner)}${' '.repeat(Math.max(0, inner - visibleLength(truncate(s, inner))))} ${c.accent('│')}`;
818
- let out = `\n${c.accent(`╭${'─'.repeat(inner + 2)}╮`)}\n${rows.map(line).join('\n')}\n${c.accent(`╰${'─'.repeat(inner + 2)}╯`)}\n`;
819
- if (update) out += `\n ${c.accent('↑')} ${c.bold(`Arrakis ${update} is available.`)} ${c.gray('Run: npm install -g @mumbrane/arrakis')}\n`;
820
- if (!resumed) {
821
- out += `\n ${c.gray('Tips for getting started:')}\n`;
822
- const tips = [
823
- instructions.length ? null : 'Run /init to write an ARRAKIS.md with notes about this project',
824
- 'Ask about the code, or ask for a change, a fix or a new feature',
825
- 'Use /plan for big changes, so arrakis proposes a plan before editing',
826
- 'Mention files with @, and press shift+tab to let it edit without asking',
827
- ].filter(Boolean);
828
- tips.forEach((t, i) => (out += ` ${c.gray(`${i + 1}. ${t}`)}\n`));
829
- }
868
+ if (instructions.length) facts.push(['notes', c.lilac(instructions.map((f) => tild(f).split('/').pop()).join(', '))]);
869
+ 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(' · '))]);
870
+ if (hooks) facts.push(['hooks', c.lilac(`${hooks} active`)]);
871
+ if (resumed) facts.push(['session', c.lilac(resumed)]);
872
+ for (const [k, v] of facts) out += ` ${c.iris(GLYPH.tool)} ${c.mist(k.padEnd(8))} ${v}\n`;
873
+ if (update) out += `\n ${c.orchid('↑')} ${c.lilac(`arrakis ${update} is out`)} ${c.faint('·')} ${c.mist('npm install -g @mumbrane/arrakis')}\n`;
874
+ 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`;
875
+ const k = (key, desc) => `${c.violet(key)} ${c.faint(desc)}`;
876
+ out += ` ${[k('/', 'commands'), k('@', 'files'), k('⇧⇥', 'modes'), k('esc', 'interrupt'), k('?', 'shortcuts')].join(' ')}\n`;
830
877
  this.printAbove(out + '\n');
831
878
  }
832
879
 
833
880
  info(msg) {
834
881
  this.endText();
835
- this.write(this.out, this.c.gray(msg) + '\n');
882
+ this.write(this.out, this.c.mist(msg) + '\n');
836
883
  }
837
884
  }
838
885
 
886
+ // Shorten a path in the middle: ~/projects/…/src/app.js
887
+ function middle(s, max) {
888
+ if (s.length <= max) return s;
889
+ const keep = max - 1;
890
+ return s.slice(0, Math.ceil(keep * 0.35)) + '…' + s.slice(s.length - Math.floor(keep * 0.65));
891
+ }
892
+
893
+ // Word-wrap a styled line to `width` visible columns. Continuation lines get
894
+ // a hanging indent that lines up with the text after a bullet or number.
895
+ export function wrapAnsi(line, width) {
896
+ if (visibleLength(line) <= width) return [line];
897
+ const plain = line.replace(/\x1b\[[0-9;]*m/g, '');
898
+ const lead = plain.match(/^(\s*(?:[•◦○●◉┃]|\d+\.)?\s*)/)?.[1] ?? '';
899
+ const indent = ' '.repeat(Math.min(lead.length, Math.floor(width / 2)));
900
+ const tokens = line.match(/\x1b\[[0-9;]*m|\s+|[^\s\x1b]+/g) ?? [];
901
+ const rows = [];
902
+ let cur = '';
903
+ let len = 0;
904
+ for (const t of tokens) {
905
+ if (t.startsWith('\x1b')) {
906
+ cur += t;
907
+ continue;
908
+ }
909
+ if (len + t.length > width && len > indent.length) {
910
+ rows.push(cur);
911
+ cur = indent;
912
+ len = indent.length;
913
+ if (/^\s+$/.test(t)) continue;
914
+ }
915
+ // A single word longer than the line: hard-break it.
916
+ let word = t;
917
+ while (len + word.length > width) {
918
+ const room = width - len;
919
+ cur += word.slice(0, room);
920
+ rows.push(cur);
921
+ word = word.slice(room);
922
+ cur = indent;
923
+ len = indent.length;
924
+ }
925
+ cur += word;
926
+ len += word.length;
927
+ }
928
+ if (cur.trim()) rows.push(cur);
929
+ return rows;
930
+ }
931
+
839
932
  // Wrap text into rows of at most `width` characters, tracking source offsets.
840
933
  function wrap(text, width) {
841
934
  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
- const on = colorOn(stream);
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.accent(SPINNER[spinner.frame++ % SPINNER.length])} ${lc.sand(spinner.label + '…')} ${lc.gray(`(${secs}s · esc to interrupt)`)}`;
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,93 @@ export class UI {
314
304
 
315
305
  toolStart(name, summary, { prefix = '' } = {}) {
316
306
  this.endText();
317
- const lc = this.lc;
318
- const s = String(summary ?? '').split('\n')[0];
307
+ const t = this.lc;
308
+ const sum = String(summary ?? '').split('\n')[0];
319
309
  const label = TOOL_LABELS[name] ?? name;
320
- const head = prefix ? ` ${lc.gray('⎿')} ${lc.gray(prefix)} ` : `${this.atLineStart ? '' : '\n'}${lc.accent('⏺')} `;
321
- this.write(this.log, truncate(`${head}${lc.bold(label)}${s ? lc.gray(`(${s})`) : ''}`, this.width) + '\n');
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 lc = this.lc;
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
- let body = shown.map((l, i) => `${i === 0 ? ' ⎿ ' : ' '}${l}`).join('\n');
329
- if (all.length > 4) body += `\n ${lc.gray(`… +${all.length - 4} lines`)}`;
330
- this.write(this.log, (isError ? lc.red(body) : lc.gray(body)) + '\n');
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
- diff(lines) {
335
- const lc = this.lc;
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 ? lc.gray(String(n).padStart(4) + ' ') : ' ';
338
- const body = truncate(`${sign} ${text}`, this.width - 10);
339
- this.write(this.log, ` ${num}${sign === '+' ? lc.green(body) : sign === '-' ? lc.red(body) : lc.gray(body)}\n`);
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 lc = this.lc;
345
- for (const t of list) {
346
- const mark = t.status === 'completed' ? lc.green('☑') : t.status === 'in_progress' ? lc.accent('◼') : lc.gray('☐');
347
- const text = t.status === 'completed' ? lc.gray(t.content) : t.status === 'in_progress' ? lc.bold(t.content) : t.content;
348
- this.write(this.log, ` ${mark} ${text}\n`);
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 c = this.lc;
361
+ const t = this.lc;
355
362
  if (preview) {
356
- this.write(this.log, ` ${c.yellow('?')} ${c.bold(preview.title)}\n`);
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(` ${c.bold('Allow?')} ${c.gray('[y]es [a]lways this session [n]o')} `);
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, instructions = [], resumed, mcp = [], hooks = 0, update }) {
367
- const c = this.c;
368
- if (!this.fancy) {
369
- this.write(this.out, `\n${c.accent(c.bold(' ◆ arrakis'))} ${c.dim(`v${version}`)}\n`);
370
- this.write(this.out, c.dim(` ${model} · ${provider} · ${cwd}\n`));
371
- if (resumed) this.write(this.out, c.dim(` ${resumed}\n`));
372
- this.write(this.out, c.dim(' /help for commands · Ctrl-C to interrupt · Ctrl-D to quit\n\n'));
373
- return;
374
- }
375
- const rows = [
376
- `${c.accent(c.bold('◆ arrakis'))} ${c.gray(`v${version}`)}`,
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'));
392
378
  }
393
379
 
394
380
  info(msg) {
395
381
  this.endText();
396
- this.write(this.log, this.lc.gray(msg) + '\n');
382
+ this.write(this.log, this.lc.mist(msg) + '\n');
397
383
  }
398
384
 
399
385
  success(msg) {
400
386
  this.endText();
401
- this.write(this.log, `${this.lc.green('✓')} ${msg}\n`);
387
+ this.write(this.log, `${this.lc.mint(GLYPH.ok)} ${this.lc.lilac(msg)}\n`);
402
388
  }
403
389
 
404
390
  error(msg) {
405
391
  this.endText();
406
- this.write(this.log, this.lc.red(`✗ ${msg}`) + '\n');
392
+ const [first, ...rest] = String(msg).split('\n');
393
+ 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
394
  }
408
395
  }
409
396