From 1f44d61dcf1c42d08baee124b70be1335b8348de Mon Sep 17 00:00:00 2001 From: Pedram Amini Date: Tue, 30 Dec 2025 02:51:46 -0600 Subject: [PATCH] MAESTRO: Wire up SSH context to worktree batch processing hooks - Added sshRemoteId parameter to useWorktreeValidation deps interface - Updated worktreeInfo() and getRepoRoot() calls to pass SSH context - Added sshRemoteId to WorktreeConfig interface in useWorktreeManager - Updated worktreeSetup() and worktreeCheckout() to use sshRemoteId - Modified useBatchProcessor to inject session.sshRemoteId into worktree config This ensures batch processing worktree operations work correctly on remote SSH sessions, completing the SSH remote support implementation. All 12 existing worktree validation tests pass. --- src/renderer/hooks/batch/useBatchProcessor.ts | 4 +++- src/renderer/hooks/batch/useWorktreeManager.ts | 8 ++++++-- src/renderer/hooks/batch/useWorktreeValidation.ts | 9 ++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/renderer/hooks/batch/useBatchProcessor.ts b/src/renderer/hooks/batch/useBatchProcessor.ts index 068318e4..16e4d090 100644 --- a/src/renderer/hooks/batch/useBatchProcessor.ts +++ b/src/renderer/hooks/batch/useBatchProcessor.ts @@ -401,7 +401,9 @@ export function useBatchProcessor({ delete errorResolutionRefs.current[sessionId]; // Set up worktree if enabled using extracted hook - const worktreeResult = await worktreeManager.setupWorktree(session.cwd, worktree); + // Inject sshRemoteId from session into worktree config for remote worktree operations + const worktreeWithSsh = worktree ? { ...worktree, sshRemoteId: session.sshRemoteId } : undefined; + const worktreeResult = await worktreeManager.setupWorktree(session.cwd, worktreeWithSsh); if (!worktreeResult.success) { window.maestro.logger.log('error', 'Worktree setup failed', 'BatchProcessor', { sessionId, error: worktreeResult.error }); return; diff --git a/src/renderer/hooks/batch/useWorktreeManager.ts b/src/renderer/hooks/batch/useWorktreeManager.ts index 0dd733a7..dabb87d8 100644 --- a/src/renderer/hooks/batch/useWorktreeManager.ts +++ b/src/renderer/hooks/batch/useWorktreeManager.ts @@ -26,6 +26,8 @@ export interface WorktreeConfig { prTargetBranch?: string; /** Path to gh CLI binary (if not in PATH) */ ghPath?: string; + /** SSH remote ID for remote sessions (optional) */ + sshRemoteId?: string; } /** @@ -167,7 +169,8 @@ ${docList} const setupResult = await window.maestro.git.worktreeSetup( sessionCwd, worktree.path, - worktree.branchName + worktree.branchName, + worktree.sshRemoteId ); window.maestro.logger.log('info', 'worktreeSetup result', 'WorktreeManager', { @@ -205,7 +208,8 @@ ${docList} const checkoutResult = await window.maestro.git.worktreeCheckout( worktree.path, worktree.branchName, - true // createIfMissing + true, // createIfMissing + worktree.sshRemoteId ); window.maestro.logger.log('info', 'worktreeCheckout result', 'WorktreeManager', { diff --git a/src/renderer/hooks/batch/useWorktreeValidation.ts b/src/renderer/hooks/batch/useWorktreeValidation.ts index 6f657cae..b806e8a4 100644 --- a/src/renderer/hooks/batch/useWorktreeValidation.ts +++ b/src/renderer/hooks/batch/useWorktreeValidation.ts @@ -38,6 +38,8 @@ export interface UseWorktreeValidationDeps { worktreeEnabled: boolean; /** The session's current working directory (main repo) */ sessionCwd: string; + /** SSH remote ID for remote sessions (optional) */ + sshRemoteId?: string; } /** @@ -90,6 +92,7 @@ export function useWorktreeValidation({ branchName, worktreeEnabled, sessionCwd, + sshRemoteId, }: UseWorktreeValidationDeps): UseWorktreeValidationReturn { const [validation, setValidation] = useState(INITIAL_VALIDATION_STATE); @@ -108,7 +111,7 @@ export function useWorktreeValidation({ const timeoutId = setTimeout(async () => { try { // Check if the path exists and get worktree info - const worktreeInfoResult = await window.maestro.git.worktreeInfo(worktreePath); + const worktreeInfoResult = await window.maestro.git.worktreeInfo(worktreePath, sshRemoteId); if (!worktreeInfoResult.success) { setValidation({ @@ -138,7 +141,7 @@ export function useWorktreeValidation({ // Path exists - check if it's part of the same repo // If there's no repoRoot, the directory exists but isn't a git repo - that's fine for a new worktree - const mainRepoRootResult = await window.maestro.git.getRepoRoot(sessionCwd); + const mainRepoRootResult = await window.maestro.git.getRepoRoot(sessionCwd, sshRemoteId); const sameRepo = !worktreeInfoResult.repoRoot || (mainRepoRootResult.success && worktreeInfoResult.repoRoot === mainRepoRootResult.root); @@ -190,7 +193,7 @@ export function useWorktreeValidation({ // Cleanup timeout on unmount or when dependencies change return () => clearTimeout(timeoutId); - }, [worktreePath, branchName, worktreeEnabled, sessionCwd]); + }, [worktreePath, branchName, worktreeEnabled, sessionCwd, sshRemoteId]); return { validation }; }