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:
@@ -18,7 +18,8 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from '@/components/ui/context-menu';
|
||||
import { useAgentsStore, isAgentBuiltIn, isAgentHidden, type AgentScope, type AgentDraft } from '@/stores/useAgentsStore';
|
||||
import { useSettingsDirectory } from '@/hooks/useSettingsDirectory';
|
||||
import { selectAgentsForDirectory, useAgentsStore, isAgentBuiltIn, isAgentHidden, type AgentScope, type AgentDraft } from '@/stores/useAgentsStore';
|
||||
import { useShallow } from 'zustand/react/shallow';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { Agent } from '@opencode-ai/sdk/v2';
|
||||
@@ -113,7 +114,6 @@ export const AgentsSidebar: React.FC<AgentsSidebarProps> = ({ onItemSelect }) =>
|
||||
|
||||
const {
|
||||
selectedAgentName,
|
||||
agents,
|
||||
setSelectedAgent,
|
||||
setAgentDraft,
|
||||
createAgent,
|
||||
@@ -121,7 +121,6 @@ export const AgentsSidebar: React.FC<AgentsSidebarProps> = ({ onItemSelect }) =>
|
||||
loadAgents,
|
||||
} = useAgentsStore(useShallow((s) => ({
|
||||
selectedAgentName: s.selectedAgentName,
|
||||
agents: s.agents,
|
||||
setSelectedAgent: s.setSelectedAgent,
|
||||
setAgentDraft: s.setAgentDraft,
|
||||
createAgent: s.createAgent,
|
||||
@@ -129,9 +128,14 @@ export const AgentsSidebar: React.FC<AgentsSidebarProps> = ({ onItemSelect }) =>
|
||||
loadAgents: s.loadAgents,
|
||||
})));
|
||||
|
||||
// Settings browses whichever project its own selector points at; the app
|
||||
// stays where it is.
|
||||
const settingsDirectory = useSettingsDirectory();
|
||||
const agents = useAgentsStore((state) => selectAgentsForDirectory(state, settingsDirectory));
|
||||
|
||||
React.useEffect(() => {
|
||||
loadAgents();
|
||||
}, [loadAgents]);
|
||||
void loadAgents(settingsDirectory);
|
||||
}, [loadAgents, settingsDirectory]);
|
||||
|
||||
const bgClass = 'bg-background';
|
||||
|
||||
@@ -183,7 +187,7 @@ export const AgentsSidebar: React.FC<AgentsSidebarProps> = ({ onItemSelect }) =>
|
||||
|
||||
setIsConfirmActionPending(true);
|
||||
try {
|
||||
const result = await deleteAgent(confirmActionAgent.name, (confirmActionAgent as Agent & { scope?: AgentScope }).scope);
|
||||
const result = await deleteAgent(confirmActionAgent.name, (confirmActionAgent as Agent & { scope?: AgentScope }).scope, settingsDirectory);
|
||||
|
||||
if (result.ok) {
|
||||
if (result.requiresManualRestart) {
|
||||
@@ -291,11 +295,11 @@ export const AgentsSidebar: React.FC<AgentsSidebarProps> = ({ onItemSelect }) =>
|
||||
permission: rulesetToPermissionConfig(renameDialogAgent.permission),
|
||||
disable: renameExt.disable,
|
||||
scope: renameExt.scope,
|
||||
});
|
||||
}, settingsDirectory);
|
||||
|
||||
if (createResult.ok) {
|
||||
// Delete old agent
|
||||
const deleteResult = await deleteAgent(renameDialogAgent.name, renameExt.scope);
|
||||
const deleteResult = await deleteAgent(renameDialogAgent.name, renameExt.scope, settingsDirectory);
|
||||
if (deleteResult.ok) {
|
||||
if (createResult.requiresManualRestart || deleteResult.requiresManualRestart) {
|
||||
toast.warning(t('settings.agents.page.toast.savedManualRestart'));
|
||||
|
||||
Reference in New Issue
Block a user