Implement branch selection and worktree management features

- Added a new BranchAutocomplete component for selecting branches in feature dialogs.
- Enhanced BoardView to fetch and display branch suggestions.
- Updated CreateWorktreeDialog and EditFeatureDialog to include branch selection.
- Modified worktree management to ensure proper handling of branch-specific worktrees.
- Refactored related components and hooks to support the new branch management functionality.
- Removed unused revert and merge handlers from Kanban components for cleaner code.
This commit is contained in:
Cody Seibert
2025-12-16 12:12:10 -05:00
parent 54a102f029
commit a3c9c9cee5
52 changed files with 2969 additions and 588 deletions

View File

@@ -224,7 +224,8 @@ export interface AutoModeAPI {
runFeature: (
projectPath: string,
featureId: string,
useWorktrees?: boolean
useWorktrees?: boolean,
worktreePath?: string
) => Promise<{ success: boolean; passes?: boolean; error?: string }>;
verifyFeature: (
projectPath: string,
@@ -245,11 +246,13 @@ export interface AutoModeAPI {
projectPath: string,
featureId: string,
prompt: string,
imagePaths?: string[]
imagePaths?: string[],
worktreePath?: string
) => Promise<{ success: boolean; passes?: boolean; error?: string }>;
commitFeature: (
projectPath: string,
featureId: string
featureId: string,
worktreePath?: string
) => Promise<{ success: boolean; error?: string }>;
onEvent: (callback: (event: AutoModeEvent) => void) => () => void;
}
@@ -1056,7 +1059,7 @@ function createMockWorktreeAPI(): WorktreeAPI {
return {
success: true,
worktrees: [
{ path: projectPath, branch: "main", isMain: true, hasChanges: false, changedFilesCount: 0 },
{ path: projectPath, branch: "main", isMain: true, isCurrent: true, hasWorktree: true, hasChanges: false, changedFilesCount: 0 },
],
};
},
@@ -1104,6 +1107,7 @@ function createMockWorktreeAPI(): WorktreeAPI {
result: {
branch: "feature-branch",
pushed: true,
message: "Successfully pushed to origin/feature-branch",
},
};
},
@@ -1205,6 +1209,73 @@ function createMockWorktreeAPI(): WorktreeAPI {
},
};
},
openInEditor: async (worktreePath: string) => {
console.log("[Mock] Opening in editor:", worktreePath);
return {
success: true,
result: {
message: `Opened ${worktreePath} in editor`,
},
};
},
initGit: async (projectPath: string) => {
console.log("[Mock] Initializing git:", projectPath);
return {
success: true,
result: {
initialized: true,
message: `Initialized git repository in ${projectPath}`,
},
};
},
activate: async (projectPath: string, worktreePath: string | null) => {
console.log("[Mock] Activating worktree:", { projectPath, worktreePath });
return {
success: true,
result: {
previousBranch: "main",
currentBranch: worktreePath ? "feature-branch" : "main",
message: worktreePath ? "Switched to worktree branch" : "Switched to main",
},
};
},
startDevServer: async (projectPath: string, worktreePath: string) => {
console.log("[Mock] Starting dev server:", { projectPath, worktreePath });
return {
success: true,
result: {
worktreePath,
port: 3001,
url: "http://localhost:3001",
message: "Dev server started on port 3001",
},
};
},
stopDevServer: async (worktreePath: string) => {
console.log("[Mock] Stopping dev server:", worktreePath);
return {
success: true,
result: {
worktreePath,
message: "Dev server stopped",
},
};
},
listDevServers: async () => {
console.log("[Mock] Listing dev servers");
return {
success: true,
result: {
servers: [],
},
};
},
};
}
@@ -1311,7 +1382,8 @@ function createMockAutoModeAPI(): AutoModeAPI {
runFeature: async (
projectPath: string,
featureId: string,
useWorktrees?: boolean
useWorktrees?: boolean,
worktreePath?: string
) => {
if (mockRunningFeatures.has(featureId)) {
return {
@@ -1321,7 +1393,7 @@ function createMockAutoModeAPI(): AutoModeAPI {
}
console.log(
`[Mock] Running feature ${featureId} with useWorktrees: ${useWorktrees}`
`[Mock] Running feature ${featureId} with useWorktrees: ${useWorktrees}, worktreePath: ${worktreePath}`
);
mockRunningFeatures.add(featureId);
simulateAutoModeLoop(projectPath, featureId);
@@ -1481,7 +1553,8 @@ function createMockAutoModeAPI(): AutoModeAPI {
projectPath: string,
featureId: string,
prompt: string,
imagePaths?: string[]
imagePaths?: string[],
worktreePath?: string
) => {
if (mockRunningFeatures.has(featureId)) {
return {
@@ -1506,8 +1579,8 @@ function createMockAutoModeAPI(): AutoModeAPI {
return { success: true };
},
commitFeature: async (projectPath: string, featureId: string) => {
console.log("[Mock] Committing feature:", { projectPath, featureId });
commitFeature: async (projectPath: string, featureId: string, worktreePath?: string) => {
console.log("[Mock] Committing feature:", { projectPath, featureId, worktreePath });
// Simulate commit operation
emitAutoModeEvent({

View File

@@ -509,12 +509,14 @@ export class HttpApiClient implements ElectronAPI {
runFeature: (
projectPath: string,
featureId: string,
useWorktrees?: boolean
useWorktrees?: boolean,
worktreePath?: string
) =>
this.post("/api/auto-mode/run-feature", {
projectPath,
featureId,
useWorktrees,
worktreePath,
}),
verifyFeature: (projectPath: string, featureId: string) =>
this.post("/api/auto-mode/verify-feature", { projectPath, featureId }),
@@ -528,16 +530,18 @@ export class HttpApiClient implements ElectronAPI {
projectPath: string,
featureId: string,
prompt: string,
imagePaths?: string[]
imagePaths?: string[],
worktreePath?: string
) =>
this.post("/api/auto-mode/follow-up-feature", {
projectPath,
featureId,
prompt,
imagePaths,
worktreePath,
}),
commitFeature: (projectPath: string, featureId: string) =>
this.post("/api/auto-mode/commit-feature", { projectPath, featureId }),
commitFeature: (projectPath: string, featureId: string, worktreePath?: string) =>
this.post("/api/auto-mode/commit-feature", { projectPath, featureId, worktreePath }),
onEvent: (callback: (event: AutoModeEvent) => void) => {
return this.subscribeToEvent(
"auto-mode:event",
@@ -586,6 +590,18 @@ export class HttpApiClient implements ElectronAPI {
this.post("/api/worktree/list-branches", { worktreePath }),
switchBranch: (worktreePath: string, branchName: string) =>
this.post("/api/worktree/switch-branch", { worktreePath, branchName }),
openInEditor: (worktreePath: string) =>
this.post("/api/worktree/open-in-editor", { worktreePath }),
initGit: (projectPath: string) =>
this.post("/api/worktree/init-git", { projectPath }),
activate: (projectPath: string, worktreePath: string | null) =>
this.post("/api/worktree/activate", { projectPath, worktreePath }),
startDevServer: (projectPath: string, worktreePath: string) =>
this.post("/api/worktree/start-dev", { projectPath, worktreePath }),
stopDevServer: (worktreePath: string) =>
this.post("/api/worktree/stop-dev", { worktreePath }),
listDevServers: () =>
this.post("/api/worktree/list-dev-servers", {}),
};
// Git API

View File

@@ -48,6 +48,31 @@ export async function initializeProject(
const existingFiles: string[] = [];
try {
// Initialize git repository if it doesn't exist
const gitDirExists = await api.exists(`${projectPath}/.git`);
if (!gitDirExists) {
console.log("[project-init] Initializing git repository...");
try {
// Initialize git and create an initial empty commit via server route
const result = await api.worktree?.initGit(projectPath);
if (result?.success && result.result?.initialized) {
createdFiles.push(".git");
console.log("[project-init] Git repository initialized with initial commit");
} else if (result?.success && !result.result?.initialized) {
// Git already existed (shouldn't happen since we checked, but handle it)
existingFiles.push(".git");
console.log("[project-init] Git repository already exists");
} else {
console.warn("[project-init] Failed to initialize git repository:", result?.error);
}
} catch (gitError) {
console.warn("[project-init] Failed to initialize git repository:", gitError);
// Don't fail the whole initialization if git init fails
}
} else {
existingFiles.push(".git");
}
// Create all required directories
for (const dir of REQUIRED_STRUCTURE.directories) {
const fullPath = `${projectPath}/${dir}`;