diff --git a/packages/ui/src/components/session/GitHubPullRequestPickerDialog.tsx b/packages/ui/src/components/session/GitHubPullRequestPickerDialog.tsx index 23ec2eea..eb9832b9 100644 --- a/packages/ui/src/components/session/GitHubPullRequestPickerDialog.tsx +++ b/packages/ui/src/components/session/GitHubPullRequestPickerDialog.tsx @@ -328,7 +328,9 @@ export function GitHubPullRequestPickerDialog({ throw new Error(`Local branch already exists: ${preferredBranch}`); } - const session = await createWorktreeSessionForNewBranchExact(projectDirectory, preferredBranch, headCommitish); + const session = await createWorktreeSessionForNewBranchExact(projectDirectory, preferredBranch, headCommitish, { + kind: 'pr', + }); if (!session?.id) { throw new Error('Failed to create PR worktree session'); } @@ -341,12 +343,12 @@ export function GitHubPullRequestPickerDialog({ // Switch the new worktree to the PR branch and delete the SDK-created opencode/* branch immediately. // This makes the worktree directly operate on the PR branch. - const originalBranch = (meta?.branch || session.branch || '').replace(/^refs\/heads\//, '').trim(); const commands: string[] = [ // Create local branch from the fetched PR head commit. `git -C ${JSON.stringify(worktreeDir)} switch -c ${JSON.stringify(preferredBranch)} ${JSON.stringify(headCommitish)}`, ]; - if (originalBranch && originalBranch.startsWith('opencode/')) { + const originalBranch = (meta?.branch || session.branch || '').replace(/^refs\/heads\//, '').trim(); + if (meta?.kind === 'pr' && originalBranch && originalBranch.startsWith('opencode/')) { commands.push(`git -C ${JSON.stringify(projectDirectory)} branch -D ${JSON.stringify(originalBranch)}`); } @@ -394,6 +396,7 @@ export function GitHubPullRequestPickerDialog({ branch: preferredBranch, label: preferredBranch, createdFromBranch: pr.base, + kind: 'pr' as const, }); return { id: session.id }; diff --git a/packages/ui/src/lib/worktreeSessionCreator.ts b/packages/ui/src/lib/worktreeSessionCreator.ts index d65ed1d6..349a9191 100644 --- a/packages/ui/src/lib/worktreeSessionCreator.ts +++ b/packages/ui/src/lib/worktreeSessionCreator.ts @@ -99,6 +99,7 @@ export async function createWorktreeSession(): Promise<{ id: string } | null> { const createdMetadata = { ...metadata, createdFromBranch: startPoint ?? 'HEAD', + kind: 'standard' as const, }; // Get worktree status @@ -271,6 +272,7 @@ export async function createWorktreeSessionForBranch( const createdMetadata = { ...metadata, createdFromBranch: branchName, + kind: 'standard' as const, }; // Get worktree status @@ -394,7 +396,7 @@ export async function createWorktreeSessionForNewBranch( projectDirectory: string, preferredBranchName: string, startPoint: string, - options?: { allowSuffix?: boolean } + options?: { allowSuffix?: boolean; kind?: 'pr' | 'standard' } ): Promise<{ id: string; branch: string } | null> { if (isCreatingWorktreeSession) { return null; @@ -425,6 +427,7 @@ export async function createWorktreeSessionForNewBranch( } const allowSuffix = options?.allowSuffix !== false; + const kind = options?.kind ?? 'standard'; const projectRef = resolveProjectRef(projectDirectory); if (!projectRef) { @@ -444,6 +447,7 @@ export async function createWorktreeSessionForNewBranch( const createdMetadata = { ...metadata, createdFromBranch: start, + kind, }; const status = await getWorktreeStatus(metadata.path).catch(() => undefined); @@ -543,7 +547,11 @@ export async function createWorktreeSessionForNewBranch( export async function createWorktreeSessionForNewBranchExact( projectDirectory: string, branchName: string, - startPoint: string + startPoint: string, + options?: { kind?: 'pr' | 'standard' } ): Promise<{ id: string; branch: string } | null> { - return createWorktreeSessionForNewBranch(projectDirectory, branchName, startPoint, { allowSuffix: false }); + return createWorktreeSessionForNewBranch(projectDirectory, branchName, startPoint, { + allowSuffix: false, + kind: options?.kind, + }); } diff --git a/packages/ui/src/lib/worktrees/worktreeManager.ts b/packages/ui/src/lib/worktrees/worktreeManager.ts index 482255a4..5dc82fae 100644 --- a/packages/ui/src/lib/worktrees/worktreeManager.ts +++ b/packages/ui/src/lib/worktrees/worktreeManager.ts @@ -71,6 +71,8 @@ export const buildSdkStartCommand = (args: { const startPoint = typeof args.startPoint === 'string' ? args.startPoint.trim() : ''; if (startPoint && startPoint !== 'HEAD') { commands.push(`git reset --hard ${shellQuote(startPoint)}`); + } else { + commands.push('git reset --hard HEAD'); } for (const raw of args.setupCommands) { diff --git a/packages/ui/src/stores/useMultiRunStore.ts b/packages/ui/src/stores/useMultiRunStore.ts index 35f928d2..810cd510 100644 --- a/packages/ui/src/stores/useMultiRunStore.ts +++ b/packages/ui/src/stores/useMultiRunStore.ts @@ -170,6 +170,7 @@ export const useMultiRunStore = create()( const enrichedMetadata = { ...worktreeMetadata, createdFromBranch: startPoint ?? 'HEAD', + kind: 'standard' as const, }; // Session title format: groupSlug/provider/model (or groupSlug/provider/model/index for duplicates) diff --git a/packages/ui/src/types/worktree.ts b/packages/ui/src/types/worktree.ts index 87646a61..171c557e 100644 --- a/packages/ui/src/types/worktree.ts +++ b/packages/ui/src/types/worktree.ts @@ -18,6 +18,8 @@ export interface WorktreeMetadata { /** SDK worktree name (slug), if available. */ name?: string; + kind?: 'pr' | 'standard'; + /** * Branch/ref this worktree was created from (intended integration target). * For SDK worktrees this is typically the user-selected base branch.