Merge pull request #243 from btriapitsyn/fix-worktrees

feat: add kind metadata for worktrees and PR workflow support
This commit is contained in:
yulia-ivashko
2026-01-29 21:38:15 +02:00
committed by GitHub
5 changed files with 22 additions and 6 deletions
@@ -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 };
+11 -3
View File
@@ -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,
});
}
@@ -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) {
@@ -170,6 +170,7 @@ export const useMultiRunStore = create<MultiRunStore>()(
const enrichedMetadata = {
...worktreeMetadata,
createdFromBranch: startPoint ?? 'HEAD',
kind: 'standard' as const,
};
// Session title format: groupSlug/provider/model (or groupSlug/provider/model/index for duplicates)
+2
View File
@@ -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.