Add git integration: branch picker + worktrees

Allows users to right-click "+ New thread" to create threads from specific git branches, with optional worktree creation for isolated work. Includes branch sorting (current/default first), graceful handling of non-git repos, and ability to initialize git repos.

- New git IPC contract (listBranches, createWorktree, removeWorktree, init)
- Branch context menu with worktree sub-option in Sidebar
- Thread model extended with branch/worktreePath fields
- Session cwd uses worktree path when available
- Branch sorting: current > main/master > alphabetical

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Haiku 4.5 committed 2026-02-11 09:00:18 -08:00
1 parent 9023d13929
commit d64f78a949
5 files changed
+79

No files matched your search

+6
View File
@@ -34,6 +34,8 @@ const persistedThreadSchema = z.object({
model: z.string().min(1),
messages: z.array(persistedMessageSchema),
createdAt: z.string().min(1),
branch: z.string().min(1).nullable().optional(),
worktreePath: z.string().min(1).nullable().optional(),
});
const persistedStateBodySchema = z.object({
@@ -112,6 +114,8 @@ function hydrateThread(
events: [],
error: null,
createdAt: thread.createdAt,
branch: thread.branch ?? null,
worktreePath: thread.worktreePath ?? null,
};
}
@@ -170,6 +174,8 @@ export function toPersistedState(
model: thread.model,
messages: thread.messages,
createdAt: thread.createdAt,
branch: thread.branch,
worktreePath: thread.worktreePath,
})),
activeThreadId: state.activeThreadId,
runtimeMode: state.runtimeMode,
+2
View File
@@ -35,4 +35,6 @@ export interface Thread {
latestTurnStartedAt?: string | undefined;
latestTurnCompletedAt?: string | undefined;
latestTurnDurationMs?: number | undefined;
branch: string | null;
worktreePath: string | null;
}
+56
View File
@@ -0,0 +1,56 @@
import { z } from "zod";
// ── Input schemas ──
export const gitListBranchesInputSchema = z.object({
cwd: z.string().min(1),
});
export const gitCreateWorktreeInputSchema = z.object({
cwd: z.string().min(1),
branch: z.string().min(1),
path: z.string().min(1).optional(),
});
export const gitRemoveWorktreeInputSchema = z.object({
cwd: z.string().min(1),
path: z.string().min(1),
});
export const gitInitInputSchema = z.object({
cwd: z.string().min(1),
});
// ── Output schemas ──
export const gitBranchSchema = z.object({
name: z.string().min(1),
current: z.boolean(),
});
export const gitWorktreeSchema = z.object({
path: z.string().min(1),
branch: z.string().min(1),
});
// ── Types ──
export type GitListBranchesInput = z.infer<typeof gitListBranchesInputSchema>;
export type GitBranch = z.infer<typeof gitBranchSchema>;
export type GitCreateWorktreeInput = z.infer<
typeof gitCreateWorktreeInputSchema
>;
export type GitWorktree = z.infer<typeof gitWorktreeSchema>;
export type GitRemoveWorktreeInput = z.infer<
typeof gitRemoveWorktreeInputSchema
>;
export type GitInitInput = z.infer<typeof gitInitInputSchema>;
export interface GitListBranchesResult {
branches: GitBranch[];
isRepo: boolean;
}
export interface GitCreateWorktreeResult {
worktree: GitWorktree;
}
+1
View File
@@ -6,3 +6,4 @@ export * from "./provider";
export * from "./model";
export * from "./ws";
export * from "./project";
export * from "./git";
+14
View File
@@ -1,4 +1,12 @@
import type { AgentConfig, AgentExit, OutputChunk } from "./agent";
import type {
GitCreateWorktreeInput,
GitCreateWorktreeResult,
GitInitInput,
GitListBranchesInput,
GitListBranchesResult,
GitRemoveWorktreeInput,
} from "./git";
import type {
ProviderEvent,
ProviderInterruptTurnInput,
@@ -62,4 +70,10 @@ export interface NativeApi {
shell: {
openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
};
git: {
listBranches: (input: GitListBranchesInput) => Promise<GitListBranchesResult>;
createWorktree: (input: GitCreateWorktreeInput) => Promise<GitCreateWorktreeResult>;
removeWorktree: (input: GitRemoveWorktreeInput) => Promise<void>;
init: (input: GitInitInput) => Promise<void>;
};
}