mu-coding 0.5.0 → 0.9.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.
Files changed (84) hide show
  1. package/README.md +49 -3
  2. package/package.json +9 -4
  3. package/prompts/SYSTEM.md +16 -0
  4. package/src/app/shutdown.ts +1 -1
  5. package/src/app/startApp.ts +11 -8
  6. package/src/cli/args.ts +14 -11
  7. package/src/cli/install.ts +18 -3
  8. package/src/config/index.test.ts +26 -0
  9. package/src/config/index.ts +25 -7
  10. package/src/plugin.ts +124 -0
  11. package/src/runtime/codingTools/bash.ts +114 -0
  12. package/src/runtime/codingTools/edit-file.ts +60 -0
  13. package/src/runtime/codingTools/index.ts +39 -0
  14. package/src/runtime/codingTools/read-file.ts +83 -0
  15. package/src/runtime/codingTools/utils.ts +21 -0
  16. package/src/runtime/codingTools/write-file.ts +42 -0
  17. package/src/runtime/createRegistry.test.ts +147 -0
  18. package/src/runtime/createRegistry.ts +160 -23
  19. package/src/runtime/fileMentionProvider.ts +116 -0
  20. package/src/runtime/messageBus.test.ts +62 -0
  21. package/src/runtime/messageBus.ts +78 -0
  22. package/src/runtime/pluginLoader.ts +59 -15
  23. package/src/sessions/index.ts +2 -9
  24. package/src/tui/channel/tuiChannel.test.ts +107 -0
  25. package/src/tui/channel/tuiChannel.ts +62 -0
  26. package/src/tui/chat/MessageRendererContext.ts +44 -0
  27. package/src/tui/chat/ToolDisplayContext.ts +1 -1
  28. package/src/tui/chat/useAbort.ts +5 -0
  29. package/src/tui/chat/useAttachment.ts +1 -1
  30. package/src/tui/chat/useChat.ts +38 -3
  31. package/src/tui/chat/useChatPanel.ts +29 -6
  32. package/src/tui/chat/useChatSession.ts +324 -57
  33. package/src/tui/chat/useModels.ts +26 -1
  34. package/src/tui/chat/usePluginStatus.ts +1 -1
  35. package/src/tui/chat/useSessionPersistence.ts +48 -21
  36. package/src/tui/chat/useStatusSegments.ts +38 -5
  37. package/src/tui/chat/useSubagentBrowser.ts +133 -0
  38. package/src/tui/components/chat/ChatPanel.tsx +25 -4
  39. package/src/tui/components/chat/ChatPanelBody.tsx +22 -1
  40. package/src/tui/components/chat/SubagentBrowserPanel.tsx +145 -0
  41. package/src/tui/components/messageView.tsx +4 -2
  42. package/src/tui/components/messages/EditOutput.tsx +17 -9
  43. package/src/tui/components/messages/ReadOutput.tsx +1 -1
  44. package/src/tui/components/messages/ToolHeader.tsx +8 -4
  45. package/src/tui/components/messages/WriteOutput.tsx +12 -4
  46. package/src/tui/components/messages/assistantMessage.tsx +55 -7
  47. package/src/tui/components/messages/markdown.tsx +402 -0
  48. package/src/tui/components/messages/messageItem.tsx +19 -1
  49. package/src/tui/components/messages/reasoningBlock.tsx +10 -6
  50. package/src/tui/components/messages/streamingOutput.tsx +6 -2
  51. package/src/tui/components/messages/toolCallBlock.tsx +7 -6
  52. package/src/tui/components/messages/userMessage.tsx +22 -7
  53. package/src/tui/components/primitives/dropdown.tsx +8 -4
  54. package/src/tui/components/primitives/modal.tsx +4 -2
  55. package/src/tui/components/primitives/pickerModal.tsx +3 -1
  56. package/src/tui/components/primitives/toast.tsx +43 -10
  57. package/src/tui/components/statusBar.tsx +26 -10
  58. package/src/tui/components/ui/dialogLayer.tsx +11 -6
  59. package/src/tui/context/ThemeContext.tsx +18 -0
  60. package/src/tui/hooks/useChordKeyboard.ts +87 -0
  61. package/src/tui/hooks/useInputInfoSegments.ts +22 -0
  62. package/src/tui/input/InputBoxView.tsx +191 -26
  63. package/src/tui/input/commands.test.ts +3 -1
  64. package/src/tui/input/commands.ts +11 -1
  65. package/src/tui/input/cursor.test.ts +136 -0
  66. package/src/tui/input/cursor.ts +214 -0
  67. package/src/tui/input/dumpContext.ts +107 -0
  68. package/src/tui/input/sanitize.ts +1 -1
  69. package/src/tui/input/useCommandExecutor.ts +1 -1
  70. package/src/tui/input/useInputBox.ts +160 -15
  71. package/src/tui/input/useInputHandler.ts +317 -126
  72. package/src/tui/input/useMentionPicker.ts +133 -0
  73. package/src/tui/input/usePluginShortcuts.ts +29 -0
  74. package/src/tui/plugins/InkApprovalChannel.test.ts +51 -0
  75. package/src/tui/plugins/InkApprovalChannel.ts +30 -0
  76. package/src/tui/plugins/InkUIService.ts +1 -1
  77. package/src/tui/renderApp.tsx +47 -13
  78. package/src/tui/theme/index.ts +1 -0
  79. package/src/tui/theme/merge.test.ts +49 -0
  80. package/src/tui/theme/merge.ts +43 -0
  81. package/src/tui/theme/presets.ts +90 -0
  82. package/src/tui/theme/types.ts +138 -0
  83. package/src/utils/clipboard.ts +1 -1
  84. package/src/tui/chat/useStreamConsumer.ts +0 -118
@@ -0,0 +1,133 @@
1
+ import type { MentionCompletion, PluginRegistry } from 'mu-core';
2
+ import { useCallback, useEffect, useState } from 'react';
3
+
4
+ export interface MentionPickerState {
5
+ /** Current trigger character (e.g. "@") when the picker is active. */
6
+ trigger: string | null;
7
+ /** Partial text after the trigger (excluding the trigger itself). */
8
+ partial: string;
9
+ /** Suggestions returned by the active provider. Empty array hides the picker. */
10
+ completions: MentionCompletion[];
11
+ /**
12
+ * Cursor offset where the trigger sits in the input. Lets the host replace
13
+ * `[triggerStart, cursor)` when the user accepts a completion.
14
+ */
15
+ triggerStart: number;
16
+ /** 0-based index of the currently highlighted completion. */
17
+ selectedIndex: number;
18
+ setSelectedIndex: (i: number) => void;
19
+ }
20
+
21
+ type BaseState = Omit<MentionPickerState, 'setSelectedIndex' | 'selectedIndex'>;
22
+
23
+ const EMPTY: BaseState = {
24
+ trigger: null,
25
+ partial: '',
26
+ completions: [],
27
+ triggerStart: -1,
28
+ };
29
+
30
+ interface DetectResult {
31
+ trigger: string;
32
+ start: number;
33
+ }
34
+
35
+ /**
36
+ * Detect a `<trigger><partial>` token at the cursor. Triggers are
37
+ * single-character (e.g. `@`) and the partial is anything up to the next
38
+ * whitespace before the cursor. Returns `null` when no trigger is active.
39
+ *
40
+ * Triggers must follow whitespace (or beginning of input) so they don't match
41
+ * inside email addresses.
42
+ */
43
+ function detectTrigger(value: string, cursor: number, triggers: Set<string>): DetectResult | null {
44
+ for (let i = cursor - 1; i >= 0; i--) {
45
+ const ch = value[i];
46
+ if (/\s/.test(ch)) return null;
47
+ if (triggers.has(ch)) {
48
+ const prev = i === 0 ? ' ' : value[i - 1];
49
+ if (!/\s/.test(prev)) return null;
50
+ return { trigger: ch, start: i };
51
+ }
52
+ }
53
+ return null;
54
+ }
55
+
56
+ /**
57
+ * Watch the input and resolve plugin-provided mention completions. Keeps the
58
+ * provider list in sync with `registry.onMentionProvidersChange`.
59
+ */
60
+ export function useMentionPicker(registry: PluginRegistry, value: string, cursor: number): MentionPickerState {
61
+ const [providers, setProviders] = useState(() => registry.getMentionProviders());
62
+ const [base, setBase] = useState<BaseState>(EMPTY);
63
+ const [selectedIndex, setSelectedIndex] = useState(0);
64
+
65
+ useEffect(() => {
66
+ setProviders(registry.getMentionProviders());
67
+ return registry.onMentionProvidersChange(() => setProviders(registry.getMentionProviders()));
68
+ }, [registry]);
69
+
70
+ useEffect(() => {
71
+ if (providers.length === 0) {
72
+ setBase(EMPTY);
73
+ return;
74
+ }
75
+ const triggers = new Set(providers.map((p) => p.trigger));
76
+ const match = detectTrigger(value, cursor, triggers);
77
+ if (!match) {
78
+ setBase(EMPTY);
79
+ return;
80
+ }
81
+ const partial = value.slice(match.start + 1, cursor);
82
+ const matching = providers.filter((p) => p.trigger === match.trigger);
83
+ if (matching.length === 0) {
84
+ setBase(EMPTY);
85
+ return;
86
+ }
87
+ let cancelled = false;
88
+ // Run every provider that registered for this trigger and concatenate
89
+ // results in registration order. Providers tag completions with
90
+ // `category` so the picker can render section headers (e.g. agents
91
+ // first, then files) without the picker hard-coding any plugin id.
92
+ Promise.all(
93
+ matching.map(async (entry) => {
94
+ try {
95
+ const out = await Promise.resolve(entry.provider(partial));
96
+ // Default the category to the plugin name so legacy providers
97
+ // that don't set `category` still get visually grouped.
98
+ return out.map((c) => ({ ...c, category: c.category ?? entry.plugin }));
99
+ } catch {
100
+ return [];
101
+ }
102
+ }),
103
+ ).then((groups) => {
104
+ if (cancelled) return;
105
+ const completions = groups.flat();
106
+ setBase({
107
+ trigger: match.trigger,
108
+ partial,
109
+ completions,
110
+ triggerStart: match.start,
111
+ });
112
+ });
113
+ return () => {
114
+ cancelled = true;
115
+ };
116
+ }, [providers, value, cursor]);
117
+
118
+ // Reset highlight whenever the active partial / completion list changes so
119
+ // the cursor tracks the visible options. Depending on `completions.length`
120
+ // (rather than the array reference) keeps the highlight stable when the
121
+ // provider returns equivalent results twice while still re-anchoring on a
122
+ // genuine list change.
123
+ // biome-ignore lint/correctness/useExhaustiveDependencies: trigger reset is intentional
124
+ useEffect(() => {
125
+ setSelectedIndex(0);
126
+ }, [base.partial, base.completions.length, base.trigger]);
127
+
128
+ const setIndex = useCallback((i: number) => {
129
+ setSelectedIndex(i);
130
+ }, []);
131
+
132
+ return { ...base, selectedIndex, setSelectedIndex: setIndex };
133
+ }
@@ -0,0 +1,29 @@
1
+ import type { PluginRegistry, ShortcutHandler } from 'mu-core';
2
+ import { useEffect, useState } from 'react';
3
+
4
+ interface PluginShortcuts {
5
+ /** Map of `keyId` (e.g. "tab", "ctrl+t") to plugin handler. */
6
+ handlers: Map<string, ShortcutHandler>;
7
+ }
8
+
9
+ /**
10
+ * Subscribe to the registry's shortcut bindings and expose a stable map keyed
11
+ * by keyId. Multiple registrations on the same key are last-write-wins; the
12
+ * agent plugin is expected to grab Tab and unregister cleanly on deactivation.
13
+ */
14
+ export function usePluginShortcuts(registry: PluginRegistry): PluginShortcuts {
15
+ const [handlers, setHandlers] = useState<Map<string, ShortcutHandler>>(() => buildMap(registry));
16
+ useEffect(() => {
17
+ setHandlers(buildMap(registry));
18
+ return registry.onShortcutsChange(() => setHandlers(buildMap(registry)));
19
+ }, [registry]);
20
+ return { handlers };
21
+ }
22
+
23
+ function buildMap(registry: PluginRegistry): Map<string, ShortcutHandler> {
24
+ const out = new Map<string, ShortcutHandler>();
25
+ for (const entry of registry.getShortcuts()) {
26
+ out.set(entry.key.toLowerCase(), entry.handler);
27
+ }
28
+ return out;
29
+ }
@@ -0,0 +1,51 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import type { ApprovalRequest } from 'mu-agents';
3
+ import { createInkApprovalChannel } from './InkApprovalChannel';
4
+ import { InkUIService } from './InkUIService';
5
+
6
+ function fakeRequest(extra?: Partial<ApprovalRequest>): ApprovalRequest {
7
+ return {
8
+ id: 'r1',
9
+ token: 't1',
10
+ agentId: 'build',
11
+ toolName: 'bash',
12
+ toolArgs: { cmd: 'echo hi' },
13
+ channelId: 'tui',
14
+ createdAt: 0,
15
+ status: 'pending',
16
+ ...extra,
17
+ };
18
+ }
19
+
20
+ describe('InkApprovalChannel', () => {
21
+ it('returns approved when user confirms', async () => {
22
+ const ui = new InkUIService();
23
+ const channel = createInkApprovalChannel(ui);
24
+ const promise = channel.sendApprovalRequest(fakeRequest());
25
+ // Resolve the dialog with `true` (approve).
26
+ await new Promise((r) => setTimeout(r, 0));
27
+ ui.resolveDialog(true);
28
+ expect(await promise).toBe('approved');
29
+ });
30
+
31
+ it('returns denied when user declines', async () => {
32
+ const ui = new InkUIService();
33
+ const channel = createInkApprovalChannel(ui);
34
+ const promise = channel.sendApprovalRequest(fakeRequest());
35
+ await new Promise((r) => setTimeout(r, 0));
36
+ ui.resolveDialog(false);
37
+ expect(await promise).toBe('denied');
38
+ });
39
+
40
+ it('serialises tool args into the dialog message', async () => {
41
+ const ui = new InkUIService();
42
+ const channel = createInkApprovalChannel(ui);
43
+ const promise = channel.sendApprovalRequest(fakeRequest({ toolArgs: { path: 'src/x.ts' } }));
44
+ await new Promise((r) => setTimeout(r, 0));
45
+ const dialog = ui.currentDialog();
46
+ expect(dialog?.title).toBe('Run `bash`?');
47
+ expect(dialog?.message).toContain('src/x.ts');
48
+ ui.resolveDialog(true);
49
+ await promise;
50
+ });
51
+ });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * InkApprovalChannel — bridges the ApprovalGateway to the Ink confirm
3
+ * dialog. Returns the user's choice synchronously (no token round-trip
4
+ * through HTTP / Telegram); the gateway honours that immediate result.
5
+ */
6
+
7
+ import type { ApprovalChannel, ApprovalRequest, ApprovalResult } from 'mu-agents';
8
+ import type { InkUIService } from './InkUIService';
9
+
10
+ function formatArgs(args: unknown): string {
11
+ if (args === null || args === undefined) return '';
12
+ if (typeof args === 'string') return args;
13
+ try {
14
+ const json = JSON.stringify(args, null, 2);
15
+ return json.length > 800 ? `${json.slice(0, 800)}…` : json;
16
+ } catch {
17
+ return String(args);
18
+ }
19
+ }
20
+
21
+ export function createInkApprovalChannel(ui: InkUIService): ApprovalChannel {
22
+ return {
23
+ async sendApprovalRequest(req: ApprovalRequest): Promise<ApprovalResult | undefined> {
24
+ const title = `Run \`${req.toolName}\`?`;
25
+ const message = formatArgs(req.toolArgs);
26
+ const ok = await ui.confirm(title, message);
27
+ return ok ? 'approved' : 'denied';
28
+ },
29
+ };
30
+ }
@@ -1,4 +1,4 @@
1
- import type { UIService } from 'mu-agents';
1
+ import type { UIService } from 'mu-core';
2
2
 
3
3
  export type DialogType = 'confirm' | 'select' | 'input';
4
4
 
@@ -1,27 +1,61 @@
1
- import { render } from 'ink';
2
- import type { PluginRegistry } from 'mu-agents';
3
- import type { ChatMessage, ProviderConfig } from 'mu-provider';
1
+ import { type Instance, render } from 'ink';
2
+ import { type SubagentRunRegistry, SubagentRunsProvider } from 'mu-agents';
3
+ import type { ChatMessage, PluginRegistry } from 'mu-core';
4
+ import type { ReactNode } from 'react';
4
5
  import type { ShutdownFn } from '../app/shutdown';
6
+ import type { AppConfig } from '../config/index';
7
+ import type { SessionPathHolder } from '../runtime/createRegistry';
8
+ import type { HostMessageBus } from '../runtime/messageBus';
5
9
  import { ChatPanel } from './components/chat/ChatPanel';
10
+ import { ThemeProvider } from './context/ThemeContext';
6
11
  import type { InkUIService } from './plugins/InkUIService';
12
+ import { resolveTheme } from './theme';
7
13
 
8
14
  interface RenderAppOptions {
9
- config: ProviderConfig;
15
+ config: AppConfig;
10
16
  initialMessages?: ChatMessage[];
11
17
  registry: PluginRegistry;
18
+ messageBus: HostMessageBus;
12
19
  uiService: InkUIService;
13
20
  shutdown: ShutdownFn;
21
+ sessionPathHolder?: SessionPathHolder;
22
+ subagentRuns?: SubagentRunRegistry;
14
23
  }
15
24
 
16
- export function renderApp(options: RenderAppOptions): void {
17
- render(
18
- <ChatPanel
19
- config={options.config}
20
- initialMessages={options.initialMessages}
21
- registry={options.registry}
22
- uiService={options.uiService}
23
- shutdown={options.shutdown}
24
- />,
25
+ /**
26
+ * Optionally wrap children with the subagent-runs provider so the
27
+ * `↳ subagent` header renderer can subscribe to live status updates.
28
+ * Wrapping is conditional because hosts that disabled the agent plugin
29
+ * have no registry to provide.
30
+ */
31
+ function withSubagentProvider(runs: SubagentRunRegistry | undefined, children: ReactNode): ReactNode {
32
+ if (!runs) return <>{children}</>;
33
+ return <SubagentRunsProvider registry={runs}>{children}</SubagentRunsProvider>;
34
+ }
35
+
36
+ /**
37
+ * Renders the chat TUI and returns the Ink `Instance` so callers (the TUI
38
+ * channel, tests) can unmount it explicitly. Ink stays mounted until the
39
+ * caller invokes `instance.unmount()` or the process exits.
40
+ */
41
+ export function renderApp(options: RenderAppOptions): Instance {
42
+ const theme = resolveTheme(options.config.theme);
43
+ return render(
44
+ <ThemeProvider theme={theme}>
45
+ {withSubagentProvider(
46
+ options.subagentRuns,
47
+ <ChatPanel
48
+ config={options.config}
49
+ initialMessages={options.initialMessages}
50
+ registry={options.registry}
51
+ messageBus={options.messageBus}
52
+ uiService={options.uiService}
53
+ shutdown={options.shutdown}
54
+ sessionPathHolder={options.sessionPathHolder}
55
+ subagentRuns={options.subagentRuns}
56
+ />,
57
+ )}
58
+ </ThemeProvider>,
25
59
  {
26
60
  exitOnCtrlC: false,
27
61
  kittyKeyboard: { mode: 'enabled' },
@@ -0,0 +1 @@
1
+ export { resolveTheme } from './merge';
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { mergeTheme, resolveTheme } from './merge';
3
+ import { DEFAULT_THEME } from './presets';
4
+
5
+ describe('mergeTheme', () => {
6
+ it('returns the base theme untouched when no override is provided', () => {
7
+ expect(mergeTheme(DEFAULT_THEME)).toBe(DEFAULT_THEME);
8
+ });
9
+
10
+ it('merges leaf overrides without dropping siblings', () => {
11
+ const merged = mergeTheme(DEFAULT_THEME, { input: { cursor: '#ff00ff' } });
12
+ expect(merged.input.cursor).toBe('#ff00ff');
13
+ expect(merged.input.background).toBe(DEFAULT_THEME.input.background);
14
+ expect(merged.user).toEqual(DEFAULT_THEME.user);
15
+ });
16
+
17
+ it('does not mutate the base theme', () => {
18
+ const before = DEFAULT_THEME.input.cursor;
19
+ mergeTheme(DEFAULT_THEME, { input: { cursor: '#000000' } });
20
+ expect(DEFAULT_THEME.input.cursor).toBe(before);
21
+ });
22
+
23
+ it('ignores non-object sections defensively', () => {
24
+ // biome-ignore lint/suspicious/noExplicitAny: testing malformed user input on purpose
25
+ const merged = mergeTheme(DEFAULT_THEME, { input: 'red' as any });
26
+ expect(merged.input).toEqual(DEFAULT_THEME.input);
27
+ });
28
+ });
29
+
30
+ describe('resolveTheme', () => {
31
+ it('returns the default theme when config is undefined', () => {
32
+ expect(resolveTheme(undefined)).toBe(DEFAULT_THEME);
33
+ });
34
+
35
+ it('applies overrides on top of the default theme', () => {
36
+ const theme = resolveTheme({ user: { border: 'magenta' } });
37
+ expect(theme.user.border).toBe('magenta');
38
+ expect(theme.input).toEqual(DEFAULT_THEME.input);
39
+ });
40
+
41
+ it('returns default for non-object input', () => {
42
+ // biome-ignore lint/suspicious/noExplicitAny: malformed value
43
+ expect(resolveTheme(42 as any)).toBe(DEFAULT_THEME);
44
+ // biome-ignore lint/suspicious/noExplicitAny: malformed value
45
+ expect(resolveTheme(null as any)).toBe(DEFAULT_THEME);
46
+ // biome-ignore lint/suspicious/noExplicitAny: string presets are no longer supported
47
+ expect(resolveTheme('dark' as any)).toBe(DEFAULT_THEME);
48
+ });
49
+ });
@@ -0,0 +1,43 @@
1
+ import { DEFAULT_THEME } from './presets';
2
+ import type { PartialTheme, Theme, ThemeConfig } from './types';
3
+
4
+ /**
5
+ * Two-level deep merge tailored to the `Theme` shape: each top-level key maps
6
+ * to an object of color leaves (strings), so we never need recursion beyond
7
+ * one nesting level. Keeping it flat avoids accidentally merging into nested
8
+ * structures users haven't opted into and also avoids `any`/recursion that
9
+ * would trip Biome's complexity rules.
10
+ */
11
+ function mergeTheme(base: Theme, override?: PartialTheme): Theme {
12
+ if (!override) return base;
13
+ const out: Theme = { ...base };
14
+ const keys = Object.keys(override) as (keyof Theme)[];
15
+ for (const key of keys) {
16
+ mergeSection(out, base, override, key);
17
+ }
18
+ return out;
19
+ }
20
+
21
+ function mergeSection<K extends keyof Theme>(out: Theme, base: Theme, override: PartialTheme, key: K): void {
22
+ const section = override[key];
23
+ if (section && typeof section === 'object') {
24
+ out[key] = { ...base[key], ...section };
25
+ }
26
+ }
27
+
28
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
29
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
30
+ }
31
+
32
+ /**
33
+ * Resolve the user-supplied `theme` field from config.json into a fully
34
+ * populated `Theme`. Tolerates malformed input (wrong type) by silently
35
+ * falling back to the default — config corruption should never crash the TUI.
36
+ */
37
+ export function resolveTheme(config: ThemeConfig | undefined): Theme {
38
+ if (config === undefined) return DEFAULT_THEME;
39
+ if (!isPlainObject(config)) return DEFAULT_THEME;
40
+ return mergeTheme(DEFAULT_THEME, config as PartialTheme);
41
+ }
42
+
43
+ export { mergeTheme };
@@ -0,0 +1,90 @@
1
+ import type { Theme } from './types';
2
+
3
+ /**
4
+ * The single built-in theme. Reproduces the exact hard-coded colors that
5
+ * lived inline in the components prior to the theme extraction — using it
6
+ * must be a visual no-op. Users may still override individual leaves via
7
+ * the `theme` field in their config.
8
+ */
9
+ export const DEFAULT_THEME: Theme = {
10
+ input: {
11
+ background: '#222222',
12
+ text: 'white',
13
+ cursor: 'white',
14
+ commandHighlight: 'green',
15
+ footerHint: 'gray',
16
+ attachmentName: 'cyan',
17
+ attachmentError: 'red',
18
+ modelLabel: 'white',
19
+ },
20
+ user: {
21
+ background: '#1a1a1a',
22
+ border: 'yellow',
23
+ attachment: 'cyan',
24
+ },
25
+ assistant: {
26
+ text: 'white',
27
+ },
28
+ tool: {
29
+ success: 'green',
30
+ error: 'red',
31
+ previewBackground: '#2a2a2a',
32
+ previewText: 'white',
33
+ summaryDim: 'gray',
34
+ warning: 'yellow',
35
+ },
36
+ reasoning: {
37
+ title: 'yellow',
38
+ body: 'gray',
39
+ },
40
+ modal: {
41
+ background: '#1a1a1a',
42
+ hint: 'gray',
43
+ },
44
+ toast: {
45
+ background: '#1a1a1a',
46
+ defaultColor: 'green',
47
+ closeHint: 'gray',
48
+ },
49
+ dropdown: {
50
+ selected: 'green',
51
+ description: 'gray',
52
+ placeholder: 'gray',
53
+ cursor: 'white',
54
+ empty: 'gray',
55
+ },
56
+ dialog: {
57
+ confirmYes: 'green',
58
+ confirmNo: 'red',
59
+ hint: 'gray',
60
+ cursor: 'white',
61
+ placeholder: 'gray',
62
+ },
63
+ diff: {
64
+ added: 'green',
65
+ removed: 'red',
66
+ context: 'gray',
67
+ warning: 'yellow',
68
+ },
69
+ status: {
70
+ separator: 'gray',
71
+ },
72
+ markdown: {
73
+ heading: 'cyan',
74
+ codeBackground: '#2a2a2a',
75
+ codeText: 'yellow',
76
+ codeBlockBackground: '#2a2a2a',
77
+ codeBlockText: 'white',
78
+ link: 'cyan',
79
+ blockquote: 'gray',
80
+ bullet: 'cyan',
81
+ tableBorder: 'gray',
82
+ },
83
+ common: {
84
+ error: 'red',
85
+ warning: 'yellow',
86
+ success: 'green',
87
+ accent: 'cyan',
88
+ info: 'blue',
89
+ },
90
+ };
@@ -0,0 +1,138 @@
1
+ // Theme type definitions. Kept free of any Ink import so the type can travel
2
+ // to `config/index.ts` without dragging the renderer into the config layer.
3
+ //
4
+ // Color values are plain strings: either an Ink-supported color name
5
+ // ("red", "cyan", "yellow"...) or a hex code ("#1a1a1a"). All optional fields
6
+ // in `PartialTheme` mirror this so users can override one leaf at a time
7
+ // without having to redeclare a full theme.
8
+
9
+ interface ThemeInput {
10
+ background: string;
11
+ text: string;
12
+ cursor: string;
13
+ commandHighlight: string;
14
+ footerHint: string;
15
+ attachmentName: string;
16
+ attachmentError: string;
17
+ modelLabel: string;
18
+ }
19
+
20
+ interface ThemeUser {
21
+ background: string;
22
+ border: string;
23
+ attachment: string;
24
+ }
25
+
26
+ interface ThemeAssistant {
27
+ text: string;
28
+ }
29
+
30
+ interface ThemeTool {
31
+ success: string;
32
+ error: string;
33
+ previewBackground: string;
34
+ previewText: string;
35
+ summaryDim: string;
36
+ warning: string;
37
+ }
38
+
39
+ interface ThemeReasoning {
40
+ title: string;
41
+ body: string;
42
+ }
43
+
44
+ interface ThemeModal {
45
+ background: string;
46
+ hint: string;
47
+ }
48
+
49
+ interface ThemeToast {
50
+ background: string;
51
+ defaultColor: string;
52
+ closeHint: string;
53
+ }
54
+
55
+ interface ThemeDropdown {
56
+ selected: string;
57
+ description: string;
58
+ placeholder: string;
59
+ cursor: string;
60
+ empty: string;
61
+ }
62
+
63
+ interface ThemeDialog {
64
+ confirmYes: string;
65
+ confirmNo: string;
66
+ hint: string;
67
+ cursor: string;
68
+ placeholder: string;
69
+ }
70
+
71
+ interface ThemeDiff {
72
+ added: string;
73
+ removed: string;
74
+ context: string;
75
+ warning: string;
76
+ }
77
+
78
+ interface ThemeStatus {
79
+ separator: string;
80
+ }
81
+
82
+ interface ThemeMarkdown {
83
+ /** Heading text color (h1/h2/h3 share this color, h1 is also bold). */
84
+ heading: string;
85
+ /** Inline code background. */
86
+ codeBackground: string;
87
+ /** Inline code text color. */
88
+ codeText: string;
89
+ /** Fenced code-block background. */
90
+ codeBlockBackground: string;
91
+ /** Fenced code-block text color. */
92
+ codeBlockText: string;
93
+ /** Link `[label](url)` rendering — label color. */
94
+ link: string;
95
+ /** Blockquote (`> …`) text color (also dimmed). */
96
+ blockquote: string;
97
+ /** List bullet color. */
98
+ bullet: string;
99
+ /** Table border color. */
100
+ tableBorder: string;
101
+ }
102
+
103
+ interface ThemeCommon {
104
+ error: string;
105
+ warning: string;
106
+ success: string;
107
+ accent: string;
108
+ info: string;
109
+ }
110
+
111
+ export interface Theme {
112
+ input: ThemeInput;
113
+ user: ThemeUser;
114
+ assistant: ThemeAssistant;
115
+ tool: ThemeTool;
116
+ reasoning: ThemeReasoning;
117
+ modal: ThemeModal;
118
+ toast: ThemeToast;
119
+ dropdown: ThemeDropdown;
120
+ dialog: ThemeDialog;
121
+ diff: ThemeDiff;
122
+ status: ThemeStatus;
123
+ markdown: ThemeMarkdown;
124
+ common: ThemeCommon;
125
+ }
126
+
127
+ type DeepPartial<T> = {
128
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
129
+ };
130
+
131
+ export type PartialTheme = DeepPartial<Theme>;
132
+
133
+ /**
134
+ * Shape stored in `~/.config/mu/config.json` under the `theme` key. An object
135
+ * with per-leaf overrides on top of the default theme. Kept loose on purpose:
136
+ * malformed input falls back to the default theme rather than throwing.
137
+ */
138
+ export type ThemeConfig = PartialTheme;
@@ -2,7 +2,7 @@ import { execFileSync, execSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync, statSync, unlinkSync } from 'node:fs';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
- import type { ImageAttachment } from 'mu-provider';
5
+ import type { ImageAttachment } from 'mu-core';
6
6
 
7
7
  const CLIPBOARD_TIMEOUT = 3000;
8
8