Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/desktop/src/components/BranchHeaderContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</script>

<script lang="ts">
import { goto } from '$app/navigation';
import BranchRenameModal, {
type BranchRenameModalProps
} from '$components/BranchRenameModal.svelte';
Expand All @@ -20,6 +21,7 @@
import { CLIPBOARD_SERVICE } from '$lib/backend/clipboard';
import { projectAiGenEnabled } from '$lib/config/config';
import { DEFAULT_FORGE_FACTORY } from '$lib/forge/forgeFactory.svelte';
import { codegenPath } from '$lib/routes/routes.svelte';
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
import { URL_SERVICE } from '$lib/utils/url';
import { inject } from '@gitbutler/core/context';
Expand Down Expand Up @@ -99,6 +101,12 @@
aiConfigurationValid = await aiService.validateConfiguration();
}
async function startCodingSession() {
if (!stackId) return;
goto(`${codegenPath(projectId)}?stackId=${stackId}`);
close();
}
async function generateBranchName(stackId: string, branchName: string) {
if (!$aiGenEnabled || !aiConfigurationValid) return;
Expand Down Expand Up @@ -265,6 +273,17 @@
{/if}
</ContextMenuSection>
<ContextMenuSection>
{#if $aiGenEnabled && aiConfigurationValid && stackId}
<ContextMenuItem
label="Start Coding Agent session"
icon="ai"
testId={TestId.BranchHeaderContextMenu_StartCodingSession}
disabled={isReadOnly}
onclick={() => {
startCodingSession();
}}
/>
{/if}
{#if $aiGenEnabled && aiConfigurationValid && !branch.remoteTrackingBranch && stackId}
<ContextMenuItem
label="Generate branch name"
Expand Down
31 changes: 31 additions & 0 deletions apps/desktop/src/routes/[projectId]/codegen/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,47 @@
import CodegenPage from '$components/codegen/CodegenPage.svelte';
import { codegenEnabled } from '$lib/config/uiFeatureFlags';
import { workspacePath } from '$lib/routes/routes.svelte';
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
import { UI_STATE } from '$lib/state/uiState.svelte';
import { inject } from '@gitbutler/core/context';

// TODO: Refactor so we don't need non-null assertion.
const projectId = $derived(page.params.projectId!);

const uiState = inject(UI_STATE);
const stackService = inject(STACK_SERVICE);
const projectState = $derived(uiState.project(projectId));

// Check for stackId in URL query parameters
const urlStackId = $derived(page.url.searchParams.get('stackId'));
const stacks = $derived(stackService.stacks(projectId));

// Redirect users when feature is disabled
$effect(() => {
if (!$codegenEnabled) {
goto(workspacePath(projectId));
}
});

// Handle stackId URL parameter to auto-select branch
$effect(() => {
if (urlStackId && stacks.current.data) {
// Find the stack with the matching ID
const targetStack = stacks.current.data.find((s) => s.id === urlStackId);
if (targetStack && targetStack.heads.length > 0) {
// Set the selected Claude session to the first head of this stack
projectState.selectedClaudeSession.set({
stackId: urlStackId,
head: targetStack.heads[0].name
});

// Remove the stackId parameter from the URL to keep it clean
const newUrl = new URL(page.url);
newUrl.searchParams.delete('stackId');
goto(newUrl.toString(), { replaceState: true });
}
}
});
</script>

{#if $codegenEnabled}
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/lib/utils/testIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum TestId {
BranchHeaderContextMenu_OpenInBrowser = 'branch-header-context-menu-open-in-browser',
BranchHeaderContextMenu_CopyBranchName = 'branch-header-context-menu-copy-branch-name',
BranchHeaderContextMenu_AddRemoveDescription = 'branch-header-context-menu-add-remove-description',
BranchHeaderContextMenu_StartCodingSession = 'branch-header-context-menu-start-coding-session',
BranchHeaderContextMenu_GenerateBranchName = 'branch-header-context-menu-generate-branch-name',
BranchHeaderContextMenu_Rename = 'branch-header-context-menu-rename',
BranchHeaderContextMenu_Delete = 'branch-header-context-menu-delete',
Expand Down
Loading