Skip to content

Commit ead3158

Browse files
Add start codegen session button (#10272)
* Add start codegen session button * Add new "agents-tab" icon --------- Co-authored-by: Pavel Laptev <[email protected]>
1 parent 0bf808f commit ead3158

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

apps/desktop/src/components/BranchCard.svelte

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import { goto } from '$app/navigation';
32
import BranchBadge from '$components/BranchBadge.svelte';
43
import BranchDividerLine from '$components/BranchDividerLine.svelte';
54
import BranchHeader from '$components/BranchHeader.svelte';
@@ -14,13 +13,13 @@
1413
import CodegenBadge from '$components/codegen/CodegenBadge.svelte';
1514
import { CLAUDE_CODE_SERVICE } from '$lib/codegen/claude';
1615
import { CodegenRuleDropData, CodegenRuleDropHandler } from '$lib/codegen/dropzone';
16+
import { useGoToCodegenPage } from '$lib/codegen/redirect.svelte';
1717
import { MoveCommitDzHandler } from '$lib/commits/dropHandler';
1818
import { DRAG_STATE_SERVICE } from '$lib/dragging/dragStateService.svelte';
1919
import { draggableChips } from '$lib/dragging/draggable';
2020
import { DROPZONE_REGISTRY } from '$lib/dragging/registry';
2121
import { ReorderCommitDzHandler } from '$lib/dragging/stackingReorderDropzoneManager';
2222
import { DEFAULT_FORGE_FACTORY } from '$lib/forge/forgeFactory.svelte';
23-
import { codegenPath } from '$lib/routes/routes.svelte';
2423
import { RULES_SERVICE } from '$lib/rules/rulesService.svelte';
2524
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
2625
import { UI_STATE } from '$lib/state/uiState.svelte';
@@ -94,6 +93,8 @@
9493
9594
let { projectId, branchName, lineColor, readonly, ...args }: Props = $props();
9695
96+
const { goToCodegenPage } = useGoToCodegenPage();
97+
9798
const uiState = inject(UI_STATE);
9899
const stackService = inject(STACK_SERVICE);
99100
const forge = inject(DEFAULT_FORGE_FACTORY);
@@ -382,11 +383,7 @@
382383
if (!args.stackId) return;
383384
if (!sessionDetails.inGui) return;
384385

385-
projectState.selectedClaudeSession.set({
386-
stackId: args.stackId,
387-
head: branchName
388-
});
389-
goto(codegenPath(projectId));
386+
goToCodegenPage(projectId, args.stackId, branchName);
390387
}}
391388
/>
392389
</div>

apps/desktop/src/components/BranchHeaderContextMenu.svelte

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import { PROMPT_SERVICE } from '$lib/ai/promptService';
1919
import { AI_SERVICE } from '$lib/ai/service';
2020
import { CLIPBOARD_SERVICE } from '$lib/backend/clipboard';
21+
import { useGoToCodegenPage } from '$lib/codegen/redirect.svelte';
2122
import { projectAiGenEnabled } from '$lib/config/config';
23+
import { codegenEnabled } from '$lib/config/uiFeatureFlags';
2224
import { DEFAULT_FORGE_FACTORY } from '$lib/forge/forgeFactory.svelte';
25+
import { RULES_SERVICE } from '$lib/rules/rulesService.svelte';
2326
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
2427
import { URL_SERVICE } from '$lib/utils/url';
2528
import { inject } from '@gitbutler/core/context';
@@ -53,7 +56,10 @@
5356
contextData
5457
}: Props = $props();
5558
59+
const { goToCodegenPage } = useGoToCodegenPage();
60+
5661
const aiService = inject(AI_SERVICE);
62+
const rulesService = inject(RULES_SERVICE);
5763
const stackService = inject(STACK_SERVICE);
5864
const forge = inject(DEFAULT_FORGE_FACTORY);
5965
const promptService = inject(PROMPT_SERVICE);
@@ -265,6 +271,21 @@
265271
{/if}
266272
</ContextMenuSection>
267273
<ContextMenuSection>
274+
{#if stackId && first && $codegenEnabled}
275+
{@const rule = rulesService.aiRuleForStack({ projectId, stackId })}
276+
{#if !rule.current.data?.rule}
277+
<ContextMenuItem
278+
label="Start agent session"
279+
icon="agents-tab"
280+
testId={TestId.BranchHeaderContextMenu_StartCodegenAgent}
281+
disabled={isReadOnly}
282+
onclick={() => {
283+
goToCodegenPage(projectId, stackId, branchName);
284+
close();
285+
}}
286+
/>
287+
{/if}
288+
{/if}
268289
{#if $aiGenEnabled && aiConfigurationValid && !branch.remoteTrackingBranch && stackId}
269290
<ContextMenuItem
270291
label="Generate branch name"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { goto } from '$app/navigation';
2+
import { codegenPath } from '$lib/routes/routes.svelte';
3+
import { UI_STATE } from '$lib/state/uiState.svelte';
4+
import { inject } from '@gitbutler/core/context';
5+
6+
export function useGoToCodegenPage() {
7+
const uiState = inject(UI_STATE);
8+
9+
function goToCodegenPage(projectId: string, stackId: string, branchName: string) {
10+
const projectState = $derived(uiState.project(projectId));
11+
12+
projectState.selectedClaudeSession.set({
13+
stackId: stackId,
14+
head: branchName
15+
});
16+
goto(codegenPath(projectId));
17+
}
18+
19+
return {
20+
goToCodegenPage
21+
};
22+
}

packages/ui/src/lib/data/icons.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,6 @@
245245
"move-down": "M3.51056 7.9696L7.23029 11.6893L7.23029 5.49988C7.2302 4.25731 6.22288 3.24988 4.98029 3.24988L2.99982 3.24988L2.99982 1.74988L4.98029 1.74988C7.0513 1.74988 8.7302 3.42888 8.73029 5.49988L8.73029 11.6893L12.45 7.9696L13.5106 9.03015L9.21759 13.3231C8.53419 14.0064 7.42638 14.0064 6.74298 13.3231L2.45001 9.03015L3.51056 7.9696Z",
246246
"mixer": "M5.5 14.5H4V8H5.5V14.5ZM12 14.5H10.5V11.5H7.75V9.5H14.75V11.5H12V14.5ZM12 8.5H10.5V1.5H12V8.5ZM5.5 5H8.25V7H1.25V5H4V1.5H5.5V5Z",
247247
"stack": "M13.5 12.25C13.9142 12.25 14.25 12.5858 14.25 13C14.25 13.4142 13.9142 13.75 13.5 13.75L2.5 13.75C2.08579 13.75 1.75 13.4142 1.75 13C1.75 12.5858 2.08579 12.25 2.5 12.25L13.5 12.25ZM13.5 9.25C13.9142 9.25 14.25 9.58579 14.25 10C14.25 10.4142 13.9142 10.75 13.5 10.75L2.5 10.75C2.08579 10.75 1.75 10.4142 1.75 10C1.75 9.58579 2.08579 9.25 2.5 9.25L13.5 9.25ZM11.5 2.25C13.0188 2.25 14.25 3.48122 14.25 5C14.25 6.51878 13.0188 7.75 11.5 7.75L4.5 7.75C2.98122 7.75 1.75 6.51878 1.75 5C1.75 3.48122 2.98122 2.25 4.5 2.25L11.5 2.25ZM4.5 3.75C3.80964 3.75 3.25 4.30964 3.25 5C3.25 5.69036 3.80964 6.25 4.5 6.25L11.5 6.25C12.1904 6.25 12.75 5.69036 12.75 5C12.75 4.30964 12.1904 3.75 11.5 3.75L4.5 3.75Z",
248+
"agents-tab": "M5.98407 1.2617L6.18036 1.28514C6.86894 1.38873 7.48165 1.7031 8.00067 2.1533C8.56867 1.66093 9.24894 1.33207 10.0173 1.26268L10.28 1.249C11.5809 1.23402 12.7313 1.98367 13.5651 3.05662C14.4598 4.20805 15.0637 5.8104 15.2145 7.58689C15.3652 9.36328 15.041 11.048 14.3552 12.3398C13.7163 13.5431 12.7116 14.4845 11.4294 14.7021L11.1696 14.7363C9.94886 14.8464 8.85315 14.2782 8.00067 13.3779C7.21557 14.2071 6.2244 14.7548 5.11884 14.75L4.83173 14.7363C3.42495 14.6092 2.3276 13.6225 1.64618 12.3388C0.960468 11.0469 0.636081 9.36231 0.786804 7.58592C0.937663 5.80953 1.5416 4.20709 2.43622 3.05564C3.32572 1.91103 4.57562 1.13468 5.98407 1.2617ZM5.8493 2.75584C5.11845 2.68993 4.31758 3.0798 3.62079 3.97654C2.92925 4.86663 2.41099 6.18152 2.28094 7.71287C2.15104 9.2441 2.43926 10.6332 2.97137 11.6357C3.5079 12.6464 4.2341 13.176 4.96649 13.2422L5.11688 13.249C5.87324 13.2521 6.69452 12.7718 7.38055 11.7637L7.5788 11.4717L7.12177 10.1982C6.90091 9.58346 6.41715 9.09885 5.80243 8.87791L4.21747 8.30857C3.92774 8.20449 3.92774 7.79547 4.21747 7.69139L5.80243 7.12205C6.41714 6.90111 6.90092 6.41649 7.12177 5.80174L7.6911 4.21775C7.70489 4.17937 7.72367 4.14538 7.74677 4.11717L7.41473 3.70213C7.0044 3.18936 6.53813 2.888 6.05634 2.78709L5.8493 2.75584ZM10.152 2.75682C9.59695 2.80699 9.0551 3.11668 8.58661 3.70213L8.25262 4.11814C8.27561 4.14629 8.29552 4.17951 8.30927 4.21775L8.8786 5.80174C9.09949 6.4166 9.58308 6.90116 10.1979 7.12205L11.7829 7.69139C12.0722 7.7956 12.0722 8.20434 11.7829 8.30857L10.1979 8.87791C9.58308 9.0988 9.09949 9.58336 8.8786 10.1982L8.42059 11.4707L8.62079 11.7637C9.35257 12.8391 10.2382 13.314 11.0349 13.2422L11.1716 13.2246C11.857 13.1084 12.5269 12.5832 13.03 11.6357C13.5619 10.6335 13.8502 9.24481 13.7204 7.71385C13.5904 6.18238 13.0721 4.86756 12.3806 3.97752C11.7273 3.13683 10.9826 2.74173 10.2897 2.74998L10.152 2.75682Z",
248249
"plug": "M10.8955 4.84961H14.5C14.9139 4.84981 15.2498 5.1857 15.25 5.59961C15.25 6.0137 14.914 6.34941 14.5 6.34961L10.8955 6.34961L10.8955 9.65039L14.5 9.65039C14.914 9.65059 15.25 9.9863 15.25 10.4004C15.2498 10.8143 14.9139 11.1502 14.5 11.1504H10.8955V14H9.39551V12.9502L6.48242 12.9502C4.81006 12.95 3.46974 11.5796 3.46973 9.90918V8.75H0.0712891L0.0712891 7.25H3.46973V6.09082C3.46973 4.42036 4.81006 3.05001 6.48242 3.0498H9.39551V2L10.8955 2V4.84961ZM6.48242 4.5498C5.65599 4.55001 4.96973 5.23117 4.96973 6.09082V9.90918C4.96974 10.7688 5.656 11.45 6.48242 11.4502L9.39551 11.4502L9.39551 4.5498L6.48242 4.5498ZM7.37109 7.26172C7.85228 7.26172 8.24293 7.65168 8.24316 8.13281C8.24316 8.61415 7.85243 9.00488 7.37109 9.00488C6.88996 9.00464 6.5 8.614 6.5 8.13281C6.50024 7.65183 6.89011 7.26196 7.37109 7.26172Z"
249250
}

packages/ui/src/lib/utils/testIds.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export enum TestId {
1111
BranchHeaderContextMenu_CopyBranchName = 'branch-header-context-menu-copy-branch-name',
1212
BranchHeaderContextMenu_AddRemoveDescription = 'branch-header-context-menu-add-remove-description',
1313
BranchHeaderContextMenu_GenerateBranchName = 'branch-header-context-menu-generate-branch-name',
14+
BranchHeaderContextMenu_StartCodegenAgent = 'branch-header-context-menu-start-codegen-agent',
1415
BranchHeaderContextMenu_Rename = 'branch-header-context-menu-rename',
1516
BranchHeaderContextMenu_Delete = 'branch-header-context-menu-delete',
1617
BranchHeaderContextMenu_OpenPRInBrowser = 'branch-header-context-menu-open-pr-in-browser',

0 commit comments

Comments
 (0)