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:
committed by
GitHub
parent
8aa379e313
commit
18c5b4c7b5
@@ -1,19 +1,19 @@
|
||||
import { create } from "zustand";
|
||||
import { devtools, persist, createJSONStorage } from "zustand/middleware";
|
||||
import { opencodeClient } from "@/lib/opencode/client";
|
||||
import type { Permission, PermissionResponse } from "@/types/permission";
|
||||
import type { PermissionRequest, PermissionResponse } from "@/types/permission";
|
||||
import { isEditPermissionType, getAgentDefaultEditPermission } from "./utils/permissionUtils";
|
||||
import { getSafeStorage } from "./utils/safeStorage";
|
||||
import { useMessageStore } from "./messageStore";
|
||||
import { useSessionStore } from "./sessionStore";
|
||||
|
||||
interface PermissionState {
|
||||
permissions: Map<string, Permission[]>;
|
||||
permissions: Map<string, PermissionRequest[]>;
|
||||
}
|
||||
|
||||
interface PermissionActions {
|
||||
addPermission: (permission: Permission, contextData?: { currentAgentContext?: Map<string, string>, sessionAgentSelections?: Map<string, string>, getSessionAgentEditMode?: (sessionId: string, agentName: string | undefined) => string }) => void;
|
||||
respondToPermission: (sessionId: string, permissionId: string, response: PermissionResponse) => Promise<void>;
|
||||
addPermission: (permission: PermissionRequest, contextData?: { currentAgentContext?: Map<string, string>, sessionAgentSelections?: Map<string, string>, getSessionAgentEditMode?: (sessionId: string, agentName: string | undefined) => string }) => void;
|
||||
respondToPermission: (sessionId: string, requestId: string, response: PermissionResponse) => Promise<void>;
|
||||
}
|
||||
|
||||
type PermissionStore = PermissionState & PermissionActions;
|
||||
@@ -21,11 +21,11 @@ type PermissionStore = PermissionState & PermissionActions;
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
||||
typeof value === "object" && value !== null;
|
||||
|
||||
const sanitizePermissionEntries = (value: unknown): Array<[string, Permission[]]> => {
|
||||
const sanitizePermissionEntries = (value: unknown): Array<[string, PermissionRequest[]]> => {
|
||||
if (!Array.isArray(value)) {
|
||||
return [];
|
||||
}
|
||||
const entries: Array<[string, Permission[]]> = [];
|
||||
const entries: Array<[string, PermissionRequest[]]> = [];
|
||||
value.forEach((entry) => {
|
||||
if (!Array.isArray(entry) || entry.length !== 2) {
|
||||
return;
|
||||
@@ -34,7 +34,7 @@ const sanitizePermissionEntries = (value: unknown): Array<[string, Permission[]]
|
||||
if (typeof sessionId !== "string" || !Array.isArray(permissions)) {
|
||||
return;
|
||||
}
|
||||
entries.push([sessionId, permissions as Permission[]]);
|
||||
entries.push([sessionId, permissions as PermissionRequest[]]);
|
||||
});
|
||||
return entries;
|
||||
};
|
||||
@@ -42,15 +42,7 @@ const sanitizePermissionEntries = (value: unknown): Array<[string, Permission[]]
|
||||
const executeWithPermissionDirectory = async <T>(sessionId: string, operation: () => Promise<T>): Promise<T> => {
|
||||
try {
|
||||
const sessionStore = useSessionStore.getState();
|
||||
const metadata = sessionStore.getWorktreeMetadata(sessionId);
|
||||
if (metadata?.path) {
|
||||
return opencodeClient.withDirectory(metadata.path, operation);
|
||||
}
|
||||
|
||||
const session = sessionStore.sessions.find((entry) => entry.id === sessionId) as { directory?: string } | undefined;
|
||||
const directory =
|
||||
typeof session?.directory === 'string' && session.directory.length > 0 ? session.directory : undefined;
|
||||
|
||||
const directory = sessionStore.getDirectoryForSession(sessionId);
|
||||
if (directory) {
|
||||
return opencodeClient.withDirectory(directory, operation);
|
||||
}
|
||||
@@ -67,13 +59,18 @@ export const usePermissionStore = create<PermissionStore>()(
|
||||
|
||||
permissions: new Map(),
|
||||
|
||||
addPermission: (permission: Permission, contextData?: { currentAgentContext?: Map<string, string>, sessionAgentSelections?: Map<string, string>, getSessionAgentEditMode?: (sessionId: string, agentName: string | undefined) => string }) => {
|
||||
addPermission: (permission: PermissionRequest, contextData?: { currentAgentContext?: Map<string, string>, sessionAgentSelections?: Map<string, string>, getSessionAgentEditMode?: (sessionId: string, agentName: string | undefined) => string }) => {
|
||||
const sessionId = permission.sessionID;
|
||||
if (!sessionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const permissionType = permission.type?.toLowerCase?.() ?? null;
|
||||
const existing = get().permissions.get(sessionId);
|
||||
if (existing?.some((entry) => entry.id === permission.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const permissionType = permission.permission?.toLowerCase?.() ?? null;
|
||||
|
||||
let agentName = contextData?.currentAgentContext?.get(sessionId);
|
||||
if (!agentName) {
|
||||
@@ -109,8 +106,8 @@ export const usePermissionStore = create<PermissionStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
respondToPermission: async (sessionId: string, permissionId: string, response: PermissionResponse) => {
|
||||
await executeWithPermissionDirectory(sessionId, () => opencodeClient.respondToPermission(sessionId, permissionId, response));
|
||||
respondToPermission: async (sessionId: string, requestId: string, response: PermissionResponse) => {
|
||||
await executeWithPermissionDirectory(sessionId, () => opencodeClient.replyToPermission(requestId, response));
|
||||
|
||||
if (response === 'reject') {
|
||||
const messageStore = useMessageStore.getState();
|
||||
@@ -120,7 +117,7 @@ export const usePermissionStore = create<PermissionStore>()(
|
||||
|
||||
set((state) => {
|
||||
const sessionPermissions = state.permissions.get(sessionId) || [];
|
||||
const updatedPermissions = sessionPermissions.filter((p) => p.id !== permissionId);
|
||||
const updatedPermissions = sessionPermissions.filter((p) => p.id !== requestId);
|
||||
const newPermissions = new Map(state.permissions);
|
||||
newPermissions.set(sessionId, updatedPermissions);
|
||||
return { permissions: newPermissions };
|
||||
|
||||
Reference in New Issue
Block a user