feat: add multi-project support (#110)

* feat: Implement project management store with project path validation and synchronization

- Added `useProjectsStore` for managing projects, including adding, removing, renaming, and validating project paths.
- Implemented persistence for projects and active project ID using safe storage.
- Introduced synchronization from desktop settings to keep project data consistent.
- Enhanced session store to manage sessions by directory and added new methods for session management.
- Updated todo store to fetch session todos based on the directory context.
- Refactored server code to validate and resolve project directories for various API endpoints.
- Added project entry validation and sanitization to ensure data integrity.

* feat(settings): migrate legacy project settings and update settings loading logic

* feat: enhance project management with directory-aware settings and improved agent/command source handling

* feat: enhance session and project management with directory-aware settings and improved configuration refresh logic

* feat: enhance project management with worktree manager integration and project directory resolution

* feat: enhance agent groups store with project directory resolution and loading logic

* feat: add heartbeat management and global wrapping for SSE blocks in agent and chat providers

* feat: refactor command and project handling in useCommandsStore

- Replaced useDirectoryStore with useProjectsStore to manage project paths.
- Introduced getRequestDirectory function to determine the active project directory.
- Updated command fetching to respect project-level scoping.
- Enhanced error handling and logging for command configuration fetching.
- Improved command configuration saving and updating to utilize project directory context.

feat: enhance project path normalization in useProjectsStore

- Added resolveTildePath function to expand paths starting with ~.
- Updated normalizeProjectPath to utilize home directory for path expansion.

fix: update permission handling in useSessionStore

- Changed Permission type to PermissionRequest for clarity.
- Updated respondToPermission method to use requestId instead of permissionId.

refactor: improve permission utilities

- Introduced types for PermissionAction and PermissionRule.
- Enhanced getAgentDefinition and resolveConfigStore functions for better type safety.
- Added resolvePermissionAction to streamline permission resolution logic.

feat: add agent configuration retrieval endpoint

- Implemented new API endpoint to fetch agent configuration based on project directory.
- Enhanced getAgentPermissionSource to prioritize project-level permissions.

chore: update SDK version in package.json files

- Bumped @opencode-ai/sdk version to ^1.1.1 across all relevant package.json files.

refactor: streamline bridge message handling

- Updated handleBridgeMessage to accept directory parameter for agent and command requests.
- Improved local API request handling to extract directory from query parameters and headers.

feat: enhance project configuration management

- Added functions to retrieve and merge project configuration paths.
- Improved handling of existing project configuration files for agents and commands.

* feat: enhance VSCode integration and session management

- Added support for a sticky sidebar header background in light and dark themes.
- Introduced functions to read VSCode workspace directory and check if running in VSCode.
- Implemented detailed logging for session loading and creation processes.
- Enhanced session filtering based on directory structure and canonical paths.
- Added a new method to reorder projects and prevent modifications in VSCode workspace.
- Improved error handling and logging for app initialization and markdown file parsing.
- Updated API checks and health checks to ensure readiness before proceeding.
- Refactored code for better readability and maintainability across various modules.

* feat: improve agent and branch selection logic, enhance session management, and update multi-run creation response

* feat: add worktree management actions in agent group detail and sidebar, including delete and keep only options

* fix(ui): share IME guard and cover multi-run

* fix(session): reduce maximum visible sessions in group from 7 to 5
This commit is contained in:
Bohdan Triapitsyn
2026-01-06 21:31:04 +02:00
committed by GitHub
parent 8aa379e313
commit 18c5b4c7b5
84 changed files with 8399 additions and 2854 deletions
+6 -151
View File
@@ -1,15 +1,9 @@
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import { opencodeClient } from '@/lib/opencode/client';
import type { DirectorySwitchResult } from '@/lib/opencode/client';
import { getDesktopHomeDirectory } from '@/lib/desktop';
import { updateDesktopSettings } from '@/lib/persistence';
import { startConfigUpdate, finishConfigUpdate, updateConfigUpdateMessage } from '@/lib/configUpdate';
import { useSessionStore } from '@/stores/useSessionStore';
import { refreshAfterOpenCodeRestart } from '@/stores/useAgentsStore';
import { useCommandsStore } from '@/stores/useCommandsStore';
import { useFileSearchStore } from '@/stores/useFileSearchStore';
import { emitConfigChange } from '@/lib/configSync';
import { streamDebugEnabled } from '@/stores/utils/streamDebug';
import { getSafeStorage } from './utils/safeStorage';
@@ -37,89 +31,6 @@ const persistedLastDirectory = safeStorage.getItem('lastDirectory');
const initialHasPersistedDirectory =
typeof persistedLastDirectory === 'string' && persistedLastDirectory.length > 0;
const notifyOpenCodeWorkingDirectory = (path: string, options?: { showOverlay?: boolean }) => {
const showOverlay = options?.showOverlay ?? true;
if (showOverlay) {
startConfigUpdate('Switching project directory…');
}
return opencodeClient.setOpenCodeWorkingDirectory(path).catch((error) => {
console.warn('Failed to synchronize OpenCode working directory:', error);
throw error;
});
};
const scheduleDirectoryFollowUp = (
restartPromise: Promise<DirectorySwitchResult | null>,
options: { showOverlay: boolean },
onComplete?: (result: DirectorySwitchResult | null) => void
) => {
const { showOverlay } = options;
const reloadSessions = () => {
try {
useSessionStore.getState().loadSessions();
} catch (err) {
console.error('Failed to reload sessions after directory change:', err);
}
};
void (async () => {
let result: DirectorySwitchResult | null = null;
try {
result = await restartPromise;
} catch (error) {
console.error('Failed to update OpenCode working directory:', error);
if (showOverlay) {
updateConfigUpdateMessage('Failed to switch directory. Please try again.');
await new Promise((resolve) => setTimeout(resolve, 1500));
finishConfigUpdate();
}
onComplete?.(result);
reloadSessions();
return;
}
try {
if (result && result.restarted) {
try {
if (typeof window !== 'undefined' && window.localStorage) {
window.localStorage.removeItem('commands-store');
}
} catch (storageError) {
console.warn('Failed to reset commands-store cache:', storageError);
}
await refreshAfterOpenCodeRestart({ message: 'Refreshing OpenCode configuration…' });
try {
await useCommandsStore.getState().loadCommands();
try {
emitConfigChange('commands', { source: 'useCommandsStore' });
} catch (syncError) {
console.warn('Failed to emit command configuration change:', syncError);
}
} catch (commandError) {
console.warn('Failed to reload commands after directory change:', commandError);
}
} else if (showOverlay) {
finishConfigUpdate();
}
} catch (error) {
console.error('Failed to refresh configuration after directory change:', error);
if (showOverlay) {
updateConfigUpdateMessage('Failed to refresh configuration. Please reload manually.');
await new Promise((resolve) => setTimeout(resolve, 1500));
finishConfigUpdate();
}
} finally {
onComplete?.(result);
reloadSessions();
}
})();
};
const invalidateFileSearchCache = (scope?: string | null) => {
try {
@@ -295,26 +206,20 @@ export const useDirectoryStore = create<DirectoryStore>()(
isSwitchingDirectory: false,
setDirectory: (path: string, options?: { showOverlay?: boolean }) => {
void options;
const homeDir = cachedHomeDirectory || get().homeDirectory || safeStorage.getItem('homeDirectory');
const resolvedPath = resolveDirectoryPath(path, homeDir);
if (streamDebugEnabled()) {
console.log('[DirectoryStore] setDirectory called with path:', resolvedPath);
}
const showOverlay = options?.showOverlay ?? true;
opencodeClient.setDirectory(resolvedPath);
invalidateFileSearchCache();
const restartPromise = notifyOpenCodeWorkingDirectory(resolvedPath, { showOverlay });
if (streamDebugEnabled()) {
console.log('[DirectoryStore] notifyOpenCodeWorkingDirectory initiated');
}
set((state) => {
const newHistory = [...state.directoryHistory.slice(0, state.historyIndex + 1), resolvedPath];
safeStorage.setItem('lastDirectory', resolvedPath);
void updateDesktopSettings({ lastDirectory: resolvedPath });
return {
@@ -323,21 +228,9 @@ export const useDirectoryStore = create<DirectoryStore>()(
historyIndex: newHistory.length - 1,
hasPersistedDirectory: true,
isHomeReady: true,
isSwitchingDirectory: true,
isSwitchingDirectory: false,
};
});
scheduleDirectoryFollowUp(restartPromise, { showOverlay }, () => {
set((state) => {
if (state.currentDirectory !== resolvedPath) {
return {};
}
if (!state.isSwitchingDirectory) {
return {};
}
return { isSwitchingDirectory: false };
});
});
},
goBack: () => {
@@ -348,7 +241,6 @@ export const useDirectoryStore = create<DirectoryStore>()(
opencodeClient.setDirectory(newDirectory);
invalidateFileSearchCache();
const restartPromise = notifyOpenCodeWorkingDirectory(newDirectory);
safeStorage.setItem('lastDirectory', newDirectory);
@@ -359,19 +251,7 @@ export const useDirectoryStore = create<DirectoryStore>()(
historyIndex: newIndex,
hasPersistedDirectory: true,
isHomeReady: true,
isSwitchingDirectory: true,
});
scheduleDirectoryFollowUp(restartPromise, { showOverlay: true }, () => {
set((state) => {
if (state.currentDirectory !== newDirectory) {
return {};
}
if (!state.isSwitchingDirectory) {
return {};
}
return { isSwitchingDirectory: false };
});
isSwitchingDirectory: false,
});
}
},
@@ -384,7 +264,6 @@ export const useDirectoryStore = create<DirectoryStore>()(
opencodeClient.setDirectory(newDirectory);
invalidateFileSearchCache();
const restartPromise = notifyOpenCodeWorkingDirectory(newDirectory);
safeStorage.setItem('lastDirectory', newDirectory);
@@ -395,19 +274,7 @@ export const useDirectoryStore = create<DirectoryStore>()(
historyIndex: newIndex,
hasPersistedDirectory: true,
isHomeReady: true,
isSwitchingDirectory: true,
});
scheduleDirectoryFollowUp(restartPromise, { showOverlay: true }, () => {
set((state) => {
if (state.currentDirectory !== newDirectory) {
return {};
}
if (!state.isSwitchingDirectory) {
return {};
}
return { isSwitchingDirectory: false };
});
isSwitchingDirectory: false,
});
}
},
@@ -484,12 +351,12 @@ export const useDirectoryStore = create<DirectoryStore>()(
updates.currentDirectory = resolvedHome;
updates.directoryHistory = [resolvedHome];
updates.historyIndex = 0;
updates.isSwitchingDirectory = true;
updates.isSwitchingDirectory = false;
} else if (currentChanged || historyChanged) {
updates.currentDirectory = resolvedCurrent as string;
updates.directoryHistory = resolvedHistory;
updates.historyIndex = Math.min(state.historyIndex, resolvedHistory.length - 1);
updates.isSwitchingDirectory = true;
updates.isSwitchingDirectory = false;
}
set(() => updates as Partial<DirectoryStore>);
@@ -501,18 +368,6 @@ export const useDirectoryStore = create<DirectoryStore>()(
safeStorage.setItem('lastDirectory', nextDirectory);
void updateDesktopSettings({ lastDirectory: nextDirectory });
const restartPromise = notifyOpenCodeWorkingDirectory(nextDirectory, { showOverlay: false });
scheduleDirectoryFollowUp(restartPromise, { showOverlay: false }, () => {
set((state) => {
if (state.currentDirectory !== nextDirectory) {
return {};
}
if (!state.isSwitchingDirectory) {
return {};
}
return { isSwitchingDirectory: false };
});
});
}
void updateDesktopSettings({ homeDirectory: resolvedHome });