feat: add integrate commits to parental branch section and wired UI

Introduce IntegrateCommitsSection to plan and apply commits from source to target branch
Wire the integration panel into GitView so users can run integrate flow from the current worktree
This commit is contained in:
Bohdan Triapitsyn
2026-01-28 02:10:40 +02:00
parent 415b043326
commit 84e9391871
12 changed files with 932 additions and 16 deletions
+57
View File
@@ -0,0 +1,57 @@
import type { CommandExecResult, FilesAPI, RuntimeAPIs } from '@/lib/api/types';
type ExecResult = { success: boolean; results: CommandExecResult[] };
const DEFAULT_BASE_URL = import.meta.env.VITE_OPENCODE_URL || '/api';
const getBaseUrl = (): string => {
if (typeof DEFAULT_BASE_URL === 'string' && DEFAULT_BASE_URL.startsWith('/')) {
return DEFAULT_BASE_URL;
}
return DEFAULT_BASE_URL;
};
function getRuntimeFilesAPI(): FilesAPI | null {
if (typeof window === 'undefined') return null;
const apis = (window as typeof window & { __OPENCHAMBER_RUNTIME_APIS__?: RuntimeAPIs }).__OPENCHAMBER_RUNTIME_APIS__;
if (apis?.files) {
return apis.files;
}
return null;
}
export async function execCommands(commands: string[], cwd: string): Promise<ExecResult> {
const runtimeFiles = getRuntimeFilesAPI();
if (runtimeFiles?.execCommands) {
return runtimeFiles.execCommands(commands, cwd);
}
const response = await fetch(`${getBaseUrl()}/fs/exec`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ commands, cwd, background: false }),
});
if (!response.ok) {
const error = await response.json().catch(() => ({ error: response.statusText }));
throw new Error((error as { error?: string }).error || 'Command exec failed');
}
const payload = (await response.json().catch(() => null)) as
| { success?: boolean; results?: CommandExecResult[] }
| null;
return {
success: Boolean(payload?.success),
results: Array.isArray(payload?.results) ? payload!.results! : [],
};
}
export async function execCommand(command: string, cwd: string): Promise<CommandExecResult> {
const result = await execCommands([command], cwd);
const first = result.results[0];
if (!first) {
return { command, success: result.success };
}
return first;
}