mu-coding 0.15.0 → 0.16.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 +9 -123
- package/bin/coding-agent.ts +95 -0
- package/package.json +10 -21
- package/src/config.ts +122 -0
- package/src/harness.test.ts +159 -0
- package/src/main.ts +53 -3
- package/src/plugins.ts +49 -0
- package/src/systemPrompt.ts +22 -0
- package/src/ui/ChatApp.ts +959 -0
- package/src/ui/commands.ts +35 -0
- package/src/ui/editor.ts +166 -0
- package/src/ui/markdown.ts +363 -0
- package/src/ui/picker.ts +126 -0
- package/src/ui/status.ts +61 -0
- package/src/ui/theme.ts +241 -0
- package/src/ui/transcript.test.ts +121 -0
- package/src/ui/transcript.ts +399 -0
- package/tsconfig.json +8 -0
- package/bin/mu.js +0 -2
- package/prompts/SYSTEM.md +0 -16
- package/src/app/shutdown.ts +0 -94
- package/src/app/startApp.ts +0 -49
- package/src/cli/args.ts +0 -133
- package/src/cli/install.ts +0 -107
- package/src/cli/subcommands.ts +0 -29
- package/src/cli/update.ts +0 -205
- package/src/config/index.test.ts +0 -77
- package/src/config/index.ts +0 -199
- package/src/plugin.ts +0 -124
- package/src/runtime/codingTools/bash.ts +0 -114
- package/src/runtime/codingTools/edit-file.ts +0 -60
- package/src/runtime/codingTools/index.ts +0 -39
- package/src/runtime/codingTools/read-file.ts +0 -83
- package/src/runtime/codingTools/utils.ts +0 -21
- package/src/runtime/codingTools/write-file.ts +0 -42
- package/src/runtime/createRegistry.test.ts +0 -147
- package/src/runtime/createRegistry.ts +0 -195
- package/src/runtime/fileMentionProvider.ts +0 -117
- package/src/runtime/messageBus.test.ts +0 -62
- package/src/runtime/messageBus.ts +0 -78
- package/src/runtime/pluginLoader.ts +0 -153
- package/src/runtime/startupUpdateCheck.ts +0 -163
- package/src/runtime/updateCheck.ts +0 -136
- package/src/sessions/index.test.ts +0 -66
- package/src/sessions/index.ts +0 -183
- package/src/sessions/peek.test.ts +0 -88
- package/src/sessions/project.ts +0 -51
- package/src/tui/channel/tuiChannel.test.ts +0 -107
- package/src/tui/channel/tuiChannel.ts +0 -62
- package/src/tui/chat/ChatContext.ts +0 -10
- package/src/tui/chat/MessageRendererContext.ts +0 -44
- package/src/tui/chat/ToolDisplayContext.ts +0 -33
- package/src/tui/chat/useAbort.ts +0 -85
- package/src/tui/chat/useAttachment.ts +0 -74
- package/src/tui/chat/useChat.ts +0 -113
- package/src/tui/chat/useChatPanel.ts +0 -120
- package/src/tui/chat/useChatSession.ts +0 -384
- package/src/tui/chat/useModels.ts +0 -83
- package/src/tui/chat/usePluginStatus.ts +0 -44
- package/src/tui/chat/useSessionPersistence.ts +0 -84
- package/src/tui/chat/useStatusSegments.ts +0 -85
- package/src/tui/chat/useSubagentBrowser.ts +0 -133
- package/src/tui/components/chat/ChatPanel.tsx +0 -54
- package/src/tui/components/chat/ChatPanelBody.tsx +0 -86
- package/src/tui/components/chat/Pickers.tsx +0 -44
- package/src/tui/components/chat/SubagentBrowserPanel.tsx +0 -145
- package/src/tui/components/messageView.tsx +0 -72
- package/src/tui/components/messages/EditOutput.tsx +0 -112
- package/src/tui/components/messages/ReadOutput.tsx +0 -48
- package/src/tui/components/messages/ToolHeader.tsx +0 -30
- package/src/tui/components/messages/WebFetchOutput.tsx +0 -30
- package/src/tui/components/messages/WriteOutput.tsx +0 -64
- package/src/tui/components/messages/assistantMessage.tsx +0 -72
- package/src/tui/components/messages/markdown.tsx +0 -407
- package/src/tui/components/messages/messageItem.tsx +0 -43
- package/src/tui/components/messages/reasoningBlock.tsx +0 -18
- package/src/tui/components/messages/streamingOutput.tsx +0 -18
- package/src/tui/components/messages/toolCallBlock.tsx +0 -125
- package/src/tui/components/messages/userMessage.tsx +0 -44
- package/src/tui/components/primitives/dropdown.tsx +0 -125
- package/src/tui/components/primitives/modal.tsx +0 -47
- package/src/tui/components/primitives/pickerModal.tsx +0 -47
- package/src/tui/components/primitives/scrollbar.tsx +0 -27
- package/src/tui/components/primitives/toast.tsx +0 -100
- package/src/tui/components/statusBar.tsx +0 -41
- package/src/tui/components/ui/dialogLayer.tsx +0 -175
- package/src/tui/context/ThemeContext.tsx +0 -18
- package/src/tui/hooks/useChordKeyboard.ts +0 -87
- package/src/tui/hooks/useInputInfoSegments.ts +0 -22
- package/src/tui/hooks/useScroll.ts +0 -64
- package/src/tui/hooks/useTerminal.ts +0 -40
- package/src/tui/hooks/useUI.ts +0 -15
- package/src/tui/input/InputBox.tsx +0 -6
- package/src/tui/input/InputBoxView.tsx +0 -293
- package/src/tui/input/commands.test.ts +0 -71
- package/src/tui/input/commands.ts +0 -55
- package/src/tui/input/cursor.test.ts +0 -136
- package/src/tui/input/cursor.ts +0 -214
- package/src/tui/input/dumpContext.ts +0 -107
- package/src/tui/input/sanitize.ts +0 -33
- package/src/tui/input/useCommandExecutor.ts +0 -32
- package/src/tui/input/useInputBox.ts +0 -265
- package/src/tui/input/useInputHandler.ts +0 -455
- package/src/tui/input/useMentionPicker.ts +0 -133
- package/src/tui/input/usePluginShortcuts.ts +0 -29
- package/src/tui/plugins/InkApprovalChannel.test.ts +0 -51
- package/src/tui/plugins/InkApprovalChannel.ts +0 -30
- package/src/tui/plugins/InkUIService.ts +0 -188
- package/src/tui/renderApp.tsx +0 -66
- package/src/tui/theme/index.ts +0 -1
- package/src/tui/theme/merge.test.ts +0 -49
- package/src/tui/theme/merge.ts +0 -43
- package/src/tui/theme/presets.ts +0 -90
- package/src/tui/theme/types.ts +0 -138
- package/src/tui/update/runUpdateInTui.ts +0 -127
- package/src/utils/clipboard.ts +0 -97
- package/src/utils/diff.test.ts +0 -56
- package/src/utils/diff.ts +0 -81
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, mock } from 'bun:test';
|
|
2
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import type { PluginRegistry } from 'mu-core';
|
|
6
|
-
import type { AppConfig } from '../config/index';
|
|
7
|
-
import { InkUIService } from '../tui/plugins/InkUIService';
|
|
8
|
-
import { createRegistry } from './createRegistry';
|
|
9
|
-
|
|
10
|
-
// ─── renderApp mock ───────────────────────────────────────────────────────────
|
|
11
|
-
// Captures the options renderApp is called with so tests can assert what the
|
|
12
|
-
// TUI actually receives — specifically, that the concrete PluginRegistry (with
|
|
13
|
-
// subscription methods) is passed rather than the narrow PluginRegistryView.
|
|
14
|
-
// This mock must be declared before any test imports createRegistry so Bun's
|
|
15
|
-
// module mock intercepts the import in the plugin chain.
|
|
16
|
-
|
|
17
|
-
const capturedRenderArgs: Array<{ registry: PluginRegistry }> = [];
|
|
18
|
-
const noop = (): void => {
|
|
19
|
-
/* stub */
|
|
20
|
-
};
|
|
21
|
-
mock.module('../tui/renderApp', () => ({
|
|
22
|
-
renderApp: (opts: { registry: PluginRegistry }) => {
|
|
23
|
-
capturedRenderArgs.push(opts);
|
|
24
|
-
return {
|
|
25
|
-
unmount: noop,
|
|
26
|
-
waitUntilExit: async (): Promise<void> => {
|
|
27
|
-
/* stub */
|
|
28
|
-
},
|
|
29
|
-
rerender: noop,
|
|
30
|
-
cleanup: noop,
|
|
31
|
-
clear: noop,
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
37
|
-
|
|
38
|
-
function fakeConfig(): AppConfig {
|
|
39
|
-
return {
|
|
40
|
-
baseUrl: 'http://localhost:0',
|
|
41
|
-
model: 'test-model',
|
|
42
|
-
maxTokens: 1024,
|
|
43
|
-
temperature: 0.7,
|
|
44
|
-
streamTimeoutMs: 10_000,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Methods the TUI subscribes to at runtime (not part of PluginRegistryView). */
|
|
49
|
-
const TUI_REGISTRY_METHODS = [
|
|
50
|
-
'onStatusChange',
|
|
51
|
-
'getStatusSegments',
|
|
52
|
-
'onRenderersChange',
|
|
53
|
-
'getRenderers',
|
|
54
|
-
'onShortcutsChange',
|
|
55
|
-
'getShortcuts',
|
|
56
|
-
'getCommands',
|
|
57
|
-
] as const;
|
|
58
|
-
|
|
59
|
-
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
60
|
-
|
|
61
|
-
describe('createRegistry — activation order + plugin propagation', () => {
|
|
62
|
-
it('registers builtins so coding-agents see ctx.agents', async () => {
|
|
63
|
-
const cwd = mkdtempSync(join(tmpdir(), 'mu-cr-'));
|
|
64
|
-
try {
|
|
65
|
-
const ui = new InkUIService();
|
|
66
|
-
const { registry, channels, providers } = await createRegistry({
|
|
67
|
-
cwd,
|
|
68
|
-
config: fakeConfig(),
|
|
69
|
-
uiService: ui,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Provider registered.
|
|
73
|
-
expect(providers.list().some((p) => p.id === 'openai')).toBe(true);
|
|
74
|
-
|
|
75
|
-
// All builtin plugins loaded in the correct order.
|
|
76
|
-
const names = registry.getPlugins().map((p) => p.name);
|
|
77
|
-
expect(names).toContain('mu-openai-provider');
|
|
78
|
-
expect(names).toContain('mu-agents');
|
|
79
|
-
expect(names).toContain('mu-coding');
|
|
80
|
-
// mu-coding-agents is opt-in via `config.plugins`, not auto-registered.
|
|
81
|
-
expect(names).not.toContain('mu-coding-agents');
|
|
82
|
-
|
|
83
|
-
// TUI channel registered.
|
|
84
|
-
expect(channels.list().map((c) => c.id)).toContain('tui');
|
|
85
|
-
|
|
86
|
-
// mu-agents exposes its approval gateway publicly.
|
|
87
|
-
interface GatewayBearer {
|
|
88
|
-
approvalGateway?: { registerChannel: unknown };
|
|
89
|
-
}
|
|
90
|
-
const agent = registry.getPlugin<GatewayBearer & { name: string; [k: string]: unknown }>('mu-agents');
|
|
91
|
-
expect(agent?.approvalGateway).toBeDefined();
|
|
92
|
-
} finally {
|
|
93
|
-
rmSync(cwd, { recursive: true, force: true });
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('TUI channel receives concrete PluginRegistry (not the narrow View)', async () => {
|
|
98
|
-
// This test is the REAL regression guard: it calls channels.startAll()
|
|
99
|
-
// which invokes tuiChannel.start() → renderApp(opts). The mock above
|
|
100
|
-
// captures `opts.registry`. If createCodingPlugin ever reverts to passing
|
|
101
|
-
// `ctx.registry` (the narrow View), the TUI methods below will be absent
|
|
102
|
-
// and the test fails — exactly mirroring the runtime crash that would occur.
|
|
103
|
-
const cwd = mkdtempSync(join(tmpdir(), 'mu-cr-'));
|
|
104
|
-
try {
|
|
105
|
-
const ui = new InkUIService();
|
|
106
|
-
capturedRenderArgs.length = 0;
|
|
107
|
-
const { channels } = await createRegistry({
|
|
108
|
-
cwd,
|
|
109
|
-
config: fakeConfig(),
|
|
110
|
-
uiService: ui,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
await channels.startAll();
|
|
114
|
-
await channels.stopAll();
|
|
115
|
-
|
|
116
|
-
expect(capturedRenderArgs).toHaveLength(1);
|
|
117
|
-
const reg = capturedRenderArgs[0].registry as unknown as Record<string, unknown>;
|
|
118
|
-
for (const method of TUI_REGISTRY_METHODS) {
|
|
119
|
-
expect(typeof reg[method], `registry.${method} should be a function`).toBe('function');
|
|
120
|
-
}
|
|
121
|
-
} finally {
|
|
122
|
-
capturedRenderArgs.length = 0;
|
|
123
|
-
rmSync(cwd, { recursive: true, force: true });
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('mu-agents contributes per-primary-agent slash commands but no generic /agent', async () => {
|
|
128
|
-
const cwd = mkdtempSync(join(tmpdir(), 'mu-cr-'));
|
|
129
|
-
try {
|
|
130
|
-
const ui = new InkUIService();
|
|
131
|
-
const { registry } = await createRegistry({
|
|
132
|
-
cwd,
|
|
133
|
-
config: fakeConfig(),
|
|
134
|
-
uiService: ui,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const commandNames = registry.getCommands().map((c) => c.name);
|
|
138
|
-
// The generic `/agent` command was removed; discoverability is via
|
|
139
|
-
// the per-agent switch commands and the Tab shortcut.
|
|
140
|
-
expect(commandNames).not.toContain('agent');
|
|
141
|
-
// `explore` originates from mu-coding-agents, which is no longer auto-loaded.
|
|
142
|
-
expect(commandNames).not.toContain('explore');
|
|
143
|
-
} finally {
|
|
144
|
-
rmSync(cwd, { recursive: true, force: true });
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { mkdir } from 'node:fs/promises';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
3
|
-
import { createAgentsPlugin } from 'mu-agents';
|
|
4
|
-
import type { ChatMessage } from 'mu-core';
|
|
5
|
-
import {
|
|
6
|
-
type ActivityBus,
|
|
7
|
-
type ChannelRegistry,
|
|
8
|
-
createActivityBus,
|
|
9
|
-
createChannelRegistry,
|
|
10
|
-
createProviderRegistry,
|
|
11
|
-
PluginRegistry,
|
|
12
|
-
type ProviderRegistry,
|
|
13
|
-
} from 'mu-core';
|
|
14
|
-
import { createOpenAIProviderPlugin } from 'mu-openai-provider';
|
|
15
|
-
import type { ShutdownFn } from '../app/shutdown';
|
|
16
|
-
import type { AppConfig } from '../config/index';
|
|
17
|
-
import { createCodingPlugin } from '../plugin';
|
|
18
|
-
import { saveSession } from '../sessions/index';
|
|
19
|
-
import type { InkUIService } from '../tui/plugins/InkUIService';
|
|
20
|
-
import { createMessageBus, type HostMessageBus } from './messageBus';
|
|
21
|
-
import { discoverPluginFiles, loadConfiguredPlugin } from './pluginLoader';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Tiny mutable holder used to bridge the React-owned current session path
|
|
25
|
-
* (`useSessionPersistence`) with plugins that need it at construction time
|
|
26
|
-
* (here, mu-agents — to derive a sibling directory for subagent runs).
|
|
27
|
-
*
|
|
28
|
-
* The holder is created up-front and passed both to `mu-agents` (read via
|
|
29
|
-
* `getParentSessionPath`) and to the TUI channel (which forwards it into
|
|
30
|
-
* the React tree where `useSessionPersistence` keeps it in sync).
|
|
31
|
-
*/
|
|
32
|
-
export interface SessionPathHolder {
|
|
33
|
-
current: string | undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function createSessionPathHolder(): SessionPathHolder {
|
|
37
|
-
return { current: undefined };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface CreateRegistryOptions {
|
|
41
|
-
cwd: string;
|
|
42
|
-
config: AppConfig;
|
|
43
|
-
uiService: InkUIService;
|
|
44
|
-
/**
|
|
45
|
-
* Initial transcript injected into the TUI's session (e.g. resumed from
|
|
46
|
-
* disk via `mu -c`). Threaded through to the coding plugin's TUI channel.
|
|
47
|
-
*/
|
|
48
|
-
initialMessages?: ChatMessage[];
|
|
49
|
-
/**
|
|
50
|
-
* Host shutdown is forwarded to plugins via PluginContext so a plugin
|
|
51
|
-
* calling shutdown gets the same graceful path as Ctrl+C — terminal
|
|
52
|
-
* restored, plugins deactivated.
|
|
53
|
-
*
|
|
54
|
-
* Optional because some callers (tests, single-shot) don't have one.
|
|
55
|
-
*/
|
|
56
|
-
shutdown?: ShutdownFn;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
interface RegistryBundle {
|
|
60
|
-
registry: PluginRegistry;
|
|
61
|
-
messageBus: HostMessageBus;
|
|
62
|
-
providers: ProviderRegistry;
|
|
63
|
-
channels: ChannelRegistry;
|
|
64
|
-
activity: ActivityBus;
|
|
65
|
-
sessionPathHolder: SessionPathHolder;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
interface PluginConfigInputs {
|
|
69
|
-
uiService: InkUIService;
|
|
70
|
-
shutdown: ShutdownFn | undefined;
|
|
71
|
-
appConfig: AppConfig;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Build the plugin config object passed into a plugin's factory.
|
|
76
|
-
* Every plugin (configured or locally discovered) receives:
|
|
77
|
-
* - `ui` — UIService for dialogs/toasts/status
|
|
78
|
-
* - `shutdown` — graceful shutdown hook (when available)
|
|
79
|
-
* - `config` — the host's ProviderConfig snapshot (baseUrl, model, …) so
|
|
80
|
-
* plugins that need to call the LLM (e.g. subagents) don't have to be
|
|
81
|
-
* re-configured manually
|
|
82
|
-
* - `model` — the host's currently configured model id
|
|
83
|
-
*/
|
|
84
|
-
function buildPluginConfig(inputs: PluginConfigInputs, base?: Record<string, unknown>): Record<string, unknown> {
|
|
85
|
-
const merged: Record<string, unknown> = base ? { ...base } : {};
|
|
86
|
-
merged.ui = inputs.uiService;
|
|
87
|
-
if (inputs.shutdown) merged.shutdown = inputs.shutdown;
|
|
88
|
-
// Forward provider info so plugins can re-issue LLM calls (e.g. subagents)
|
|
89
|
-
// without forcing users to duplicate `baseUrl`/`model` in plugin config.
|
|
90
|
-
if (!('config' in merged)) merged.config = inputs.appConfig;
|
|
91
|
-
if (!('model' in merged) && inputs.appConfig.model) merged.model = inputs.appConfig.model;
|
|
92
|
-
return merged;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Fallback shutdown used when the host (typically tests) doesn't supply one.
|
|
97
|
-
* Logs a warning when a plugin actually invokes it: production hosts always
|
|
98
|
-
* pass the real `registerShutdown(...)` handle, so an invocation here means
|
|
99
|
-
* either the test setup forgot to mock the plugin's shutdown call or a
|
|
100
|
-
* plugin is reaching for `ctx.shutdown()` in an environment that can't honour
|
|
101
|
-
* it. Resolves cleanly so the calling plugin sees no behavioural change.
|
|
102
|
-
*/
|
|
103
|
-
async function noopShutdown(code?: number): Promise<void> {
|
|
104
|
-
console.warn(`[mu-coding] noopShutdown invoked (code=${code ?? 0}); host did not register a real shutdown handler.`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Wire mu-coding's standard plugin set:
|
|
109
|
-
* 1. mu-openai-provider — registers the OpenAI streaming provider
|
|
110
|
-
* 2. mu-agents — agent switcher + permissions + approval gateway
|
|
111
|
-
* 3. mu-coding — coding tools + TUI channel + Ink approval channel
|
|
112
|
-
* (registered against mu-agents' gateway)
|
|
113
|
-
*
|
|
114
|
-
* Order matters: mu-coding must activate *after* mu-agents so the approval
|
|
115
|
-
* channel finds the gateway via `ctx.getPlugin('mu-agents')`.
|
|
116
|
-
*
|
|
117
|
-
* Optional plugins (mu-coding-agents, mu-repomap, …) are opt-in via
|
|
118
|
-
* `config.plugins` and loaded below by `loadConfiguredPlugin`.
|
|
119
|
-
*/
|
|
120
|
-
async function registerBuiltins(
|
|
121
|
-
registry: PluginRegistry,
|
|
122
|
-
options: CreateRegistryOptions,
|
|
123
|
-
inputs: PluginConfigInputs,
|
|
124
|
-
messageBus: HostMessageBus,
|
|
125
|
-
sessionPathHolder: SessionPathHolder,
|
|
126
|
-
): Promise<void> {
|
|
127
|
-
await registry.register(createOpenAIProviderPlugin());
|
|
128
|
-
await registry.register(
|
|
129
|
-
createAgentsPlugin({
|
|
130
|
-
config: options.config,
|
|
131
|
-
model: options.config.model,
|
|
132
|
-
approvalChannelId: 'tui',
|
|
133
|
-
// The chat session updates this holder once `useSessionPersistence`
|
|
134
|
-
// mounts; mu-agents reads it lazily so subagent runs always land
|
|
135
|
-
// beside the *current* parent transcript file (survives /new + load).
|
|
136
|
-
getParentSessionPath: () => sessionPathHolder.current,
|
|
137
|
-
sessionWriter: async (path, messages) => {
|
|
138
|
-
await mkdir(dirname(path), { recursive: true });
|
|
139
|
-
await saveSession(path, messages);
|
|
140
|
-
},
|
|
141
|
-
}),
|
|
142
|
-
);
|
|
143
|
-
await registry.register(
|
|
144
|
-
createCodingPlugin({
|
|
145
|
-
appConfig: options.config,
|
|
146
|
-
initialMessages: options.initialMessages,
|
|
147
|
-
messageBus,
|
|
148
|
-
uiService: options.uiService,
|
|
149
|
-
shutdown: options.shutdown ?? noopShutdown,
|
|
150
|
-
sessionPathHolder,
|
|
151
|
-
// Pass the concrete registry: the TUI subscribes to renderer / shortcut
|
|
152
|
-
// / status streams that are not part of the narrow `PluginRegistryView`
|
|
153
|
-
// exposed via `ctx.registry`.
|
|
154
|
-
registry,
|
|
155
|
-
}),
|
|
156
|
-
);
|
|
157
|
-
// Silence unused-input warning when no configured/local plugins exist.
|
|
158
|
-
void inputs;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export async function createRegistry(options: CreateRegistryOptions): Promise<RegistryBundle> {
|
|
162
|
-
const { cwd, config, uiService, shutdown } = options;
|
|
163
|
-
const messageBus = createMessageBus();
|
|
164
|
-
const providers = createProviderRegistry();
|
|
165
|
-
const channels = createChannelRegistry();
|
|
166
|
-
const activity = createActivityBus();
|
|
167
|
-
const sessionPathHolder = createSessionPathHolder();
|
|
168
|
-
const registry = new PluginRegistry({
|
|
169
|
-
cwd,
|
|
170
|
-
config: {},
|
|
171
|
-
ui: uiService,
|
|
172
|
-
shutdown,
|
|
173
|
-
messages: messageBus,
|
|
174
|
-
providers,
|
|
175
|
-
channels,
|
|
176
|
-
activity,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
const inputs: PluginConfigInputs = { uiService, shutdown, appConfig: config };
|
|
180
|
-
|
|
181
|
-
await registerBuiltins(registry, options, inputs, messageBus, sessionPathHolder);
|
|
182
|
-
|
|
183
|
-
// User-extension plugins ride on top of the builtins.
|
|
184
|
-
for (const filePath of discoverPluginFiles()) {
|
|
185
|
-
await loadConfiguredPlugin(registry, filePath, buildPluginConfig(inputs), uiService);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
for (const entry of config.plugins ?? []) {
|
|
189
|
-
const name = typeof entry === 'string' ? entry : entry.name;
|
|
190
|
-
const pluginConfig = typeof entry === 'string' ? undefined : entry.config;
|
|
191
|
-
await loadConfiguredPlugin(registry, name, buildPluginConfig(inputs, pluginConfig), uiService);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return { registry, messageBus, providers, channels, activity, sessionPathHolder };
|
|
195
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import { type Dirent, readdirSync } from 'node:fs';
|
|
3
|
-
import { join, relative, sep } from 'node:path';
|
|
4
|
-
import type { MentionCompletion, MentionProvider } from 'mu-core';
|
|
5
|
-
|
|
6
|
-
const CACHE_TTL_MS = 5_000;
|
|
7
|
-
const MAX_FILES = 5_000;
|
|
8
|
-
const MAX_RESULTS = 12;
|
|
9
|
-
const IGNORE_DIRS = new Set(['node_modules', '.git', 'dist', 'build', 'out', '.next', '.turbo', 'coverage']);
|
|
10
|
-
|
|
11
|
-
interface FileCache {
|
|
12
|
-
files: string[];
|
|
13
|
-
builtAt: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let cache: FileCache | null = null;
|
|
17
|
-
let cacheCwd = '';
|
|
18
|
-
|
|
19
|
-
function listGitFiles(cwd: string): string[] | null {
|
|
20
|
-
try {
|
|
21
|
-
const stdout = execFileSync('git', ['ls-files', '--cached', '--others', '--exclude-standard'], {
|
|
22
|
-
cwd,
|
|
23
|
-
encoding: 'utf8',
|
|
24
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
25
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
26
|
-
});
|
|
27
|
-
const files = stdout.split('\n').filter((line) => line.length > 0);
|
|
28
|
-
return files.slice(0, MAX_FILES);
|
|
29
|
-
} catch {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: iterative FS walker with MAX_FILES early-exit — branching is the algorithm; extracting helpers would scatter the cap check.
|
|
35
|
-
function walkFs(root: string): string[] {
|
|
36
|
-
const out: string[] = [];
|
|
37
|
-
const stack: string[] = [root];
|
|
38
|
-
while (stack.length > 0 && out.length < MAX_FILES) {
|
|
39
|
-
const dir = stack.pop();
|
|
40
|
-
if (!dir) break;
|
|
41
|
-
let entries: Dirent[];
|
|
42
|
-
try {
|
|
43
|
-
entries = readdirSync(dir, { withFileTypes: true }) as Dirent[];
|
|
44
|
-
} catch {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
for (const entry of entries) {
|
|
48
|
-
if (entry.name.startsWith('.') && entry.name !== '.env.example') continue;
|
|
49
|
-
if (IGNORE_DIRS.has(entry.name)) continue;
|
|
50
|
-
const full = join(dir, entry.name);
|
|
51
|
-
if (entry.isDirectory()) {
|
|
52
|
-
stack.push(full);
|
|
53
|
-
} else if (entry.isFile()) {
|
|
54
|
-
out.push(relative(root, full).split(sep).join('/'));
|
|
55
|
-
if (out.length >= MAX_FILES) break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return out;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function refreshCache(cwd: string): string[] {
|
|
63
|
-
if (cache && cacheCwd === cwd && Date.now() - cache.builtAt < CACHE_TTL_MS) {
|
|
64
|
-
return cache.files;
|
|
65
|
-
}
|
|
66
|
-
const files = listGitFiles(cwd) ?? walkFs(cwd);
|
|
67
|
-
cache = { files, builtAt: Date.now() };
|
|
68
|
-
cacheCwd = cwd;
|
|
69
|
-
return files;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Score a file path against `partial` for ranking.
|
|
74
|
-
* - exact basename match → 0 (best)
|
|
75
|
-
* - basename starts with partial → 1
|
|
76
|
-
* - basename contains partial → 2
|
|
77
|
-
* - path contains partial → 3
|
|
78
|
-
* - otherwise → Infinity (filtered out)
|
|
79
|
-
*/
|
|
80
|
-
function scorePath(path: string, partial: string): number {
|
|
81
|
-
if (!partial) return path.length; // empty partial → shorter paths first
|
|
82
|
-
const lower = path.toLowerCase();
|
|
83
|
-
const base = lower.slice(lower.lastIndexOf('/') + 1);
|
|
84
|
-
const p = partial.toLowerCase();
|
|
85
|
-
if (base === p) return 0;
|
|
86
|
-
if (base.startsWith(p)) return 1;
|
|
87
|
-
if (base.includes(p)) return 2;
|
|
88
|
-
if (lower.includes(p)) return 3;
|
|
89
|
-
return Number.POSITIVE_INFINITY;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Build the file mention provider bound to `cwd`. Suggests up to
|
|
94
|
-
* `MAX_RESULTS` files matched against the partial, ranked by basename
|
|
95
|
-
* proximity. Cached for {@link CACHE_TTL_MS} so rapid keystrokes don't
|
|
96
|
-
* re-walk the tree.
|
|
97
|
-
*/
|
|
98
|
-
export function createFileMentionProvider(cwd: string): MentionProvider {
|
|
99
|
-
return (partial: string): MentionCompletion[] => {
|
|
100
|
-
const files = refreshCache(cwd);
|
|
101
|
-
if (files.length === 0) return [];
|
|
102
|
-
const scored: { path: string; score: number }[] = [];
|
|
103
|
-
for (const f of files) {
|
|
104
|
-
const score = scorePath(f, partial);
|
|
105
|
-
if (score < Number.POSITIVE_INFINITY) scored.push({ path: f, score });
|
|
106
|
-
}
|
|
107
|
-
scored.sort((a, b) => a.score - b.score || a.path.length - b.path.length || a.path.localeCompare(b.path));
|
|
108
|
-
return scored.slice(0, MAX_RESULTS).map(({ path }) => ({
|
|
109
|
-
value: path,
|
|
110
|
-
// Show the full path so the basename sits at the end of the line —
|
|
111
|
-
// the picker truncates the prefix when needed (`wrap="truncate-start"`)
|
|
112
|
-
// so the filename stays visible.
|
|
113
|
-
label: path,
|
|
114
|
-
category: 'files',
|
|
115
|
-
}));
|
|
116
|
-
};
|
|
117
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, mock } from 'bun:test';
|
|
2
|
-
import type { ChatMessage } from 'mu-core';
|
|
3
|
-
import { createMessageBus } from './messageBus';
|
|
4
|
-
|
|
5
|
-
const userMsg = (text: string): ChatMessage => ({ role: 'user', content: text });
|
|
6
|
-
|
|
7
|
-
describe('createMessageBus', () => {
|
|
8
|
-
it('queues appends until an appender is wired', () => {
|
|
9
|
-
const bus = createMessageBus();
|
|
10
|
-
bus.append(userMsg('hi'));
|
|
11
|
-
bus.append(userMsg('there'));
|
|
12
|
-
const seen: ChatMessage[] = [];
|
|
13
|
-
bus.setAppender((m) => seen.push(m));
|
|
14
|
-
expect(seen.map((m) => m.content)).toEqual(['hi', 'there']);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('forwards subsequent appends through the wired appender', () => {
|
|
18
|
-
const bus = createMessageBus();
|
|
19
|
-
const appender = mock(() => {
|
|
20
|
-
/* spy only */
|
|
21
|
-
});
|
|
22
|
-
bus.setAppender(appender);
|
|
23
|
-
bus.append(userMsg('one'));
|
|
24
|
-
bus.append(userMsg('two'));
|
|
25
|
-
expect(appender).toHaveBeenCalledTimes(2);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('drainNext returns and clears injectNext payload', () => {
|
|
29
|
-
const bus = createMessageBus();
|
|
30
|
-
bus.injectNext(userMsg('a'));
|
|
31
|
-
bus.injectNext(userMsg('b'));
|
|
32
|
-
expect(bus.drainNext().map((m) => m.content)).toEqual(['a', 'b']);
|
|
33
|
-
expect(bus.drainNext()).toEqual([]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('subscribe replays the current snapshot once', () => {
|
|
37
|
-
const bus = createMessageBus();
|
|
38
|
-
bus.setMessages([userMsg('hello')]);
|
|
39
|
-
const seen: string[] = [];
|
|
40
|
-
bus.subscribe((m) => seen.push(m.map((x) => x.content).join(',')));
|
|
41
|
-
expect(seen).toEqual(['hello']);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('subscribe fires on subsequent setMessages and unsubscribes cleanly', () => {
|
|
45
|
-
const bus = createMessageBus();
|
|
46
|
-
const updates: number[] = [];
|
|
47
|
-
const off = bus.subscribe((m) => updates.push(m.length));
|
|
48
|
-
bus.setMessages([userMsg('a')]);
|
|
49
|
-
bus.setMessages([userMsg('a'), userMsg('b')]);
|
|
50
|
-
off();
|
|
51
|
-
bus.setMessages([userMsg('c')]);
|
|
52
|
-
expect(updates).toEqual([0, 1, 2]);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('get reflects the latest setMessages snapshot', () => {
|
|
56
|
-
const bus = createMessageBus();
|
|
57
|
-
expect(bus.get()).toEqual([]);
|
|
58
|
-
const msgs = [userMsg('x')];
|
|
59
|
-
bus.setMessages(msgs);
|
|
60
|
-
expect(bus.get()).toEqual(msgs);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { ChatMessage, MessageBus } from 'mu-core';
|
|
2
|
-
|
|
3
|
-
type MessageListener = (messages: ChatMessage[]) => void;
|
|
4
|
-
type Appender = (message: ChatMessage) => void;
|
|
5
|
-
|
|
6
|
-
export interface HostMessageBus extends MessageBus {
|
|
7
|
-
/**
|
|
8
|
-
* Provide the live "append a message to the transcript" hook from the React
|
|
9
|
-
* tree. Called by `useChatSession` once it has stable `setMessages`. Until
|
|
10
|
-
* the hook is wired, `append` queues messages so plugin activations during
|
|
11
|
-
* registry construction don't lose entries.
|
|
12
|
-
*/
|
|
13
|
-
setAppender: (fn: Appender | null) => void;
|
|
14
|
-
/**
|
|
15
|
-
* Replace the current `messages` array reported via `get()` and broadcast
|
|
16
|
-
* to subscribers. Driven by the chat session whenever the transcript
|
|
17
|
-
* changes (user send, streamed response, session reload, ...).
|
|
18
|
-
*/
|
|
19
|
-
setMessages: (messages: ChatMessage[]) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Host-side bridge between plugins and the live chat transcript.
|
|
24
|
-
*
|
|
25
|
-
* Plugins call `append`/`injectNext`/`get`/`subscribe` through the registry
|
|
26
|
-
* `PluginContext`. The mu-coding chat session wires the live transcript and
|
|
27
|
-
* appender into this bus so calls made before the React tree mounts are
|
|
28
|
-
* buffered and replayed once the wiring lands.
|
|
29
|
-
*/
|
|
30
|
-
export function createMessageBus(): HostMessageBus {
|
|
31
|
-
let appender: Appender | null = null;
|
|
32
|
-
const pendingAppends: ChatMessage[] = [];
|
|
33
|
-
const pendingNextTurn: ChatMessage[] = [];
|
|
34
|
-
let currentMessages: ChatMessage[] = [];
|
|
35
|
-
const listeners = new Set<MessageListener>();
|
|
36
|
-
|
|
37
|
-
const flushAppends = (): void => {
|
|
38
|
-
if (!appender) return;
|
|
39
|
-
while (pendingAppends.length) {
|
|
40
|
-
const msg = pendingAppends.shift();
|
|
41
|
-
if (msg) appender(msg);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
append(message) {
|
|
47
|
-
if (appender) appender(message);
|
|
48
|
-
else pendingAppends.push(message);
|
|
49
|
-
},
|
|
50
|
-
injectNext(message) {
|
|
51
|
-
pendingNextTurn.push(message);
|
|
52
|
-
},
|
|
53
|
-
drainNext() {
|
|
54
|
-
const out = pendingNextTurn.slice();
|
|
55
|
-
pendingNextTurn.length = 0;
|
|
56
|
-
return out;
|
|
57
|
-
},
|
|
58
|
-
subscribe(listener) {
|
|
59
|
-
listeners.add(listener);
|
|
60
|
-
// Replay current snapshot so subscribers don't miss the initial state.
|
|
61
|
-
listener(currentMessages);
|
|
62
|
-
return () => {
|
|
63
|
-
listeners.delete(listener);
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
get() {
|
|
67
|
-
return currentMessages;
|
|
68
|
-
},
|
|
69
|
-
setAppender(fn) {
|
|
70
|
-
appender = fn;
|
|
71
|
-
flushAppends();
|
|
72
|
-
},
|
|
73
|
-
setMessages(next) {
|
|
74
|
-
currentMessages = next;
|
|
75
|
-
for (const fn of listeners) fn(next);
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|