refactor(settings): scope the settings project selector to settings

Picking a project in Settings called setActiveProject, which relocates
the chat, the session list, the file tree and the Git surface. Reading
another project's MCP servers or agents moved the user's whole app.

It had to, because the configuration stores resolved the directory
themselves from the active project and held one flat list. Each of them
now takes an explicit directory — omitted still means the active project,
so every caller outside Settings is unchanged — and keys loaded data by
directory next to a flat mirror of the active project. Chat, autocompletes
and pickers keep reading that mirror; a load for another directory writes
only the map. A failed load restores that directory's previous list.

Settings resolves its own directory through useSettingsDirectory, backed
by a session-local settingsProjectPath that follows the active project
until the user picks something else.
This commit is contained in:
Bohdan Triapitsyn
2026-08-22 20:31:31 +03:00
parent ac0b17c9fd
commit 0079347edc
25 changed files with 703 additions and 250 deletions
@@ -66,11 +66,38 @@ describe('useCommandsStore', () => {
useCommandsStore.setState({
selectedCommandName: null,
commands: [],
commandsByDirectory: {},
isLoading: false,
commandDraft: null,
});
});
test('loading another project leaves the active project\'s commands alone', async () => {
// Settings can browse a project the app is not on. Chat reads `commands`,
// so that list must keep describing the active project.
const activeCommands = [{
name: 'active-only',
description: 'Active project command',
template: 'run it',
scope: 'project' as const,
}];
useCommandsStore.setState({
commands: activeCommands,
commandsByDirectory: { [activeProjectPath]: activeCommands },
});
listCommandsWithDetailsImpl = async () => [
{ name: 'other-only', description: 'Other project command', template: 'run there' },
];
const result = await useCommandsStore.getState().loadCommands('/workspace/other');
expect(result).toBe(true);
const state = useCommandsStore.getState();
expect(state.commands).toEqual(activeCommands);
expect(state.commandsByDirectory['/workspace/other']?.map((command) => command.name)).toEqual(['other-only']);
expect(state.commandsByDirectory[activeProjectPath]).toEqual(activeCommands);
});
test('loadCommands preserves previous commands when the command list fails', async () => {
const previousCommands = [{
name: 'existing',