@devries-cameron20 / t3code-1 / commits / 906550f9af
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Merge feature-branch checkout into atomic runStackedAction

Consolidate the fragile 3-RPC flow (suggestCommitAndBranch → createBranch + checkout → runStackedAction) into a single server-side operation triggered by `runStackedAction({ featureBranch: true })`. The server now generates the branch name via AI, deduplicates it, creates + checks out the branch, then runs the normal commit/push/PR pipeline atomically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Julius Marminge committed Mar 2, 2026 at 13:10 UTC 906550f9af7d6fc37e1c9e4f21018dcb9ea03591
19 files changed +182 -301
apps/server/src/git/Layers/GitCore.test.ts
+1
@@ -110,6 +110,7 @@ const makeIsolatedGitCore = (gitService: GitServiceShape) =>
110 createBranch: (input) => core.createBranch(input),
111 checkoutBranch: (input) => core.checkoutBranch(input),
112 initRepo: (input) => core.initRepo(input),
113 + listLocalBranchNames: (cwd) => core.listLocalBranchNames(cwd),
114 } satisfies GitCoreShape;
115 });
116
apps/server/src/git/Layers/GitCore.ts
+15
@@ -1172,6 +1172,20 @@ const makeGitCore = Effect.gen(function* () {
1172 fallbackErrorMessage: "git init failed",
1173 }).pipe(Effect.asVoid);
1174
1175 + const listLocalBranchNames: GitCoreShape["listLocalBranchNames"] = (cwd) =>
1176 + runGitStdout("GitCore.listLocalBranchNames", cwd, [
1177 + "branch",
1178 + "--list",
1179 + "--format=%(refname:short)",
1180 + ]).pipe(
1181 + Effect.map((stdout) =>
1182 + stdout
1183 + .split("\n")
1184 + .map((line) => line.trim())
1185 + .filter((line) => line.length > 0),
1186 + ),
1187 + );
1188 +
1189 return {
1190 status,
1191 statusDetails,
@@ -1188,6 +1202,7 @@ const makeGitCore = Effect.gen(function* () {
1202 createBranch,
1203 checkoutBranch,
1204 initRepo,
1205 + listLocalBranchNames,
1206 } satisfies GitCoreShape;
1207 });
1208
apps/server/src/git/Layers/GitManager.test.ts
+39 -26
@@ -290,21 +290,12 @@ function runStackedAction(
290 cwd: string;
291 action: "commit" | "commit_push" | "commit_push_pr";
292 commitMessage?: string;
293 + featureBranch?: boolean;
294 },
295 ) {
296 return manager.runStackedAction(input);
297 }
298
298 -function suggestCommitAndBranch(
299 - manager: GitManagerShape,
300 - input: {
301 - cwd: string;
302 - commitMessage?: string;
303 - },
304 -) {
305 - return manager.suggestCommitAndBranch(input);
306 -}
307 -
299 function makeManager(input?: {
300 ghScenario?: FakeGhScenario;
301 textGeneration?: Partial<FakeGitTextGeneration>;
@@ -492,6 +483,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
483 action: "commit",
484 });
485
486 + expect(result.branch.status).toBe("skipped_not_requested");
487 expect(result.commit.status).toBe("created");
488 expect(result.push.status).toBe("skipped_not_requested");
489 expect(result.pr.status).toBe("skipped_not_requested");
@@ -529,6 +521,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
521 commitMessage: "feat: custom summary line\n\n- details from user",
522 });
523
524 + expect(result.branch.status).toBe("skipped_not_requested");
525 expect(result.commit.status).toBe("created");
526 expect(result.commit.subject).toBe("feat: custom summary line");
527 expect(generatedCount).toBe(0);
@@ -545,29 +538,39 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
538 }),
539 );
540
548 - it.effect("suggests commit message and semantic branch for dirty worktree", () =>
541 + it.effect("creates feature branch, commits, and pushes with featureBranch option", () =>
542 Effect.gen(function* () {
543 const repoDir = yield* makeTempDir("t3code-git-manager-");
544 yield* initRepo(repoDir);
552 - fs.writeFileSync(path.join(repoDir, "README.md"), "hello\nsuggest\n");
545 + const remoteDir = yield* createBareRemote();
546 + yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
547 + yield* runGit(repoDir, ["push", "-u", "origin", "main"]);
548 + fs.writeFileSync(path.join(repoDir, "README.md"), "hello\nfeature-branch\n");
549
550 const { manager } = yield* makeManager();
555 - const suggestion = yield* suggestCommitAndBranch(manager, {
551 + const result = yield* runStackedAction(manager, {
552 cwd: repoDir,
553 + action: "commit_push",
554 + featureBranch: true,
555 });
556
559 - expect(suggestion).toEqual({
560 - commitMessage: "Implement stacked git actions",
561 - branch: "feature/implement-stacked-git-actions",
562 - });
557 + expect(result.branch.status).toBe("created");
558 + expect(result.branch.name).toBe("feature/implement-stacked-git-actions");
559 + expect(result.commit.status).toBe("created");
560 + expect(result.push.status).toBe("pushed");
561 + expect(
562 + yield* runGit(repoDir, ["rev-parse", "--abbrev-ref", "HEAD"]).pipe(
563 + Effect.map((result) => result.stdout.trim()),
564 + ),
565 + ).toBe("feature/implement-stacked-git-actions");
566 }),
567 );
568
566 - it.effect("suggests branch from custom commit message without AI generation", () =>
569 + it.effect("featureBranch uses custom commit message and derives branch name", () =>
570 Effect.gen(function* () {
571 const repoDir = yield* makeTempDir("t3code-git-manager-");
572 yield* initRepo(repoDir);
570 - fs.writeFileSync(path.join(repoDir, "README.md"), "hello\ncustom-suggest\n");
573 + fs.writeFileSync(path.join(repoDir, "README.md"), "hello\ncustom-feature\n");
574 let generatedCount = 0;
575
576 const { manager } = yield* makeManager({
@@ -583,15 +586,17 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
586 }),
587 },
588 });
586 - const suggestion = yield* suggestCommitAndBranch(manager, {
589 + const result = yield* runStackedAction(manager, {
590 cwd: repoDir,
591 + action: "commit",
592 + featureBranch: true,
593 commitMessage: "feat: custom summary line\n\n- details from user",
594 });
595
591 - expect(suggestion).toEqual({
592 - commitMessage: "feat: custom summary line\n\n- details from user",
593 - branch: "feature/feat-custom-summary-line",
594 - });
596 + expect(result.branch.status).toBe("created");
597 + expect(result.branch.name).toBe("feature/feat-custom-summary-line");
598 + expect(result.commit.status).toBe("created");
599 + expect(result.commit.subject).toBe("feat: custom summary line");
600 expect(generatedCount).toBe(0);
601 }),
602 );
@@ -607,20 +612,23 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
612 action: "commit",
613 });
614
615 + expect(result.branch.status).toBe("skipped_not_requested");
616 expect(result.commit.status).toBe("skipped_no_changes");
617 expect(result.push.status).toBe("skipped_not_requested");
618 expect(result.pr.status).toBe("skipped_not_requested");
619 }),
620 );
621
616 - it.effect("returns a clear error when suggesting from clean worktree", () =>
622 + it.effect("featureBranch returns error when worktree is clean", () =>
623 Effect.gen(function* () {
624 const repoDir = yield* makeTempDir("t3code-git-manager-");
625 yield* initRepo(repoDir);
626
627 const { manager } = yield* makeManager();
622 - const errorMessage = yield* suggestCommitAndBranch(manager, {
628 + const errorMessage = yield* runStackedAction(manager, {
629 cwd: repoDir,
630 + action: "commit",
631 + featureBranch: true,
632 }).pipe(
633 Effect.flip,
634 Effect.map((error) => error.message),
@@ -645,6 +653,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
653 action: "commit_push",
654 });
655
656 + expect(result.branch.status).toBe("skipped_not_requested");
657 expect(result.commit.status).toBe("created");
658 expect(result.push.status).toBe("pushed");
659 expect(result.push.setUpstream).toBe(true);
@@ -689,6 +698,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
698 action: "commit_push_pr",
699 });
700
701 + expect(result.branch.status).toBe("skipped_not_requested");
702 expect(result.commit.status).toBe("created");
703 expect(result.push.status).toBe("pushed");
704 expect(result.push.setUpstream).toBe(true);
@@ -721,6 +731,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
731 action: "commit_push",
732 });
733
734 + expect(result.branch.status).toBe("skipped_not_requested");
735 expect(result.commit.status).toBe("skipped_no_changes");
736 expect(result.push.status).toBe("skipped_up_to_date");
737 }),
@@ -755,6 +766,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
766 action: "commit_push_pr",
767 });
768
769 + expect(result.branch.status).toBe("skipped_not_requested");
770 expect(result.pr.status).toBe("opened_existing");
771 expect(result.pr.number).toBe(42);
772 expect(ghCalls.some((call) => call.startsWith("pr view "))).toBe(false);
@@ -795,6 +807,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
807 action: "commit_push_pr",
808 });
809
810 + expect(result.branch.status).toBe("skipped_not_requested");
811 expect(result.pr.status).toBe("created");
812 expect(result.pr.number).toBe(88);
813 expect(
apps/server/src/git/Layers/GitManager.ts
+41 -19
@@ -1,7 +1,7 @@
1 import { randomUUID } from "node:crypto";
2
3 import { Effect, FileSystem, Layer, Path } from "effect";
4 -import { sanitizeFeatureBranchName } from "@t3tools/shared/git";
4 +import { resolveAutoFeatureBranchName, sanitizeFeatureBranchName } from "@t3tools/shared/git";
5
6 import { GitManagerError } from "../Errors.ts";
7 import { GitManager, type GitManagerShape } from "../Services/GitManager.ts";
@@ -431,28 +431,33 @@ export const makeGitManager = Effect.gen(function* () {
431 };
432 });
433
434 - const suggestCommitAndBranch: GitManagerShape["suggestCommitAndBranch"] = Effect.fnUntraced(
435 - function* (input) {
436 - const details = yield* gitCore.statusDetails(input.cwd);
434 + const runFeatureBranchStep = (cwd: string, branch: string | null, commitMessage?: string) =>
435 + Effect.gen(function* () {
436 const suggestion = yield* resolveCommitAndBranchSuggestion({
438 - cwd: input.cwd,
439 - branch: details.branch,
440 - ...(input.commitMessage ? { commitMessage: input.commitMessage } : {}),
437 + cwd,
438 + branch,
439 + ...(commitMessage ? { commitMessage } : {}),
440 includeBranch: true,
441 });
442 if (!suggestion) {
443 return yield* gitManagerError(
445 - "suggestCommitAndBranch",
446 - "Cannot suggest a commit and branch because there are no changes to commit.",
444 + "runFeatureBranchStep",
445 + "Cannot create a feature branch because there are no changes to commit.",
446 );
447 }
448
449 + const preferredBranch = suggestion.branch ?? sanitizeFeatureBranchName(suggestion.subject);
450 + const existingBranchNames = yield* gitCore.listLocalBranchNames(cwd);
451 + const resolvedBranch = resolveAutoFeatureBranchName(existingBranchNames, preferredBranch);
452 +
453 + yield* gitCore.createBranch({ cwd, branch: resolvedBranch });
454 + yield* gitCore.checkoutBranch({ cwd, branch: resolvedBranch });
455 +
456 return {
451 - commitMessage: suggestion.commitMessage,
452 - branch: suggestion.branch ?? sanitizeFeatureBranchName(suggestion.subject),
457 + branchStep: { status: "created" as const, name: resolvedBranch },
458 + resolvedCommitMessage: suggestion.commitMessage,
459 };
454 - },
455 - );
460 + });
461
462 const runStackedAction: GitManagerShape["runStackedAction"] = Effect.fnUntraced(
463 function* (input) {
@@ -460,28 +465,46 @@ export const makeGitManager = Effect.gen(function* () {
465 const wantsPr = input.action === "commit_push_pr";
466
467 const initialStatus = yield* gitCore.statusDetails(input.cwd);
463 - if (wantsPush && !initialStatus.branch) {
468 + if (!input.featureBranch && wantsPush && !initialStatus.branch) {
469 return yield* gitManagerError("runStackedAction", "Cannot push from detached HEAD.");
470 }
466 - if (wantsPr && !initialStatus.branch) {
471 + if (!input.featureBranch && wantsPr && !initialStatus.branch) {
472 return yield* gitManagerError(
473 "runStackedAction",
474 "Cannot create a pull request from detached HEAD.",
475 );
476 }
477
473 - const commit = yield* runCommitStep(input.cwd, initialStatus.branch, input.commitMessage);
478 + let branchStep: { status: "created" | "skipped_not_requested"; name?: string };
479 + let commitMessageForStep = input.commitMessage;
480 +
481 + if (input.featureBranch) {
482 + const result = yield* runFeatureBranchStep(
483 + input.cwd,
484 + initialStatus.branch,
485 + input.commitMessage,
486 + );
487 + branchStep = result.branchStep;
488 + commitMessageForStep = result.resolvedCommitMessage;
489 + } else {
490 + branchStep = { status: "skipped_not_requested" as const };
491 + }
492 +
493 + const currentBranch = branchStep.name ?? initialStatus.branch;
494 +
495 + const commit = yield* runCommitStep(input.cwd, currentBranch, commitMessageForStep);
496
497 const push = wantsPush
476 - ? yield* gitCore.pushCurrentBranch(input.cwd, initialStatus.branch)
498 + ? yield* gitCore.pushCurrentBranch(input.cwd, currentBranch)
499 : { status: "skipped_not_requested" as const };
500
501 const pr = wantsPr
480 - ? yield* runPrStep(input.cwd, initialStatus.branch)
502 + ? yield* runPrStep(input.cwd, currentBranch)
503 : { status: "skipped_not_requested" as const };
504
505 return {
506 action: input.action,
507 + branch: branchStep,
508 commit,
509 push,
510 pr,
@@ -492,7 +515,6 @@ export const makeGitManager = Effect.gen(function* () {
515 return {
516 status,
517 runStackedAction,
495 - suggestCommitAndBranch,
518 } satisfies GitManagerShape;
519 });
520
apps/server/src/git/Services/GitCore.ts
+5
@@ -157,6 +157,11 @@ export interface GitCoreShape {
157 * Initialize a repository in the provided directory.
158 */
159 readonly initRepo: (input: GitInitInput) => Effect.Effect<void, GitCommandError>;
160 +
161 + /**
162 + * List local branch names (short format).
163 + */
164 + readonly listLocalBranchNames: (cwd: string) => Effect.Effect<string[], GitCommandError>;
165 }
166
167 /**
apps/server/src/git/Services/GitManager.ts
+1 -9
@@ -9,8 +9,6 @@
9 import {
10 GitRunStackedActionInput,
11 GitRunStackedActionResult,
12 - GitSuggestCommitAndBranchInput,
13 - GitSuggestCommitAndBranchResult,
12 GitStatusInput,
13 GitStatusResult,
14 } from "@t3tools/contracts";
@@ -31,17 +29,11 @@ export interface GitManagerShape {
29
30 /**
31 * Run a stacked Git action (`commit`, `commit_push`, `commit_push_pr`).
32 + * When `featureBranch` is set, creates and checks out a feature branch first.
33 */
34 readonly runStackedAction: (
35 input: GitRunStackedActionInput,
36 ) => Effect.Effect<GitRunStackedActionResult, GitManagerServiceError>;
38 -
39 - /**
40 - * Suggest a semantic branch name and commit message for current staged changes.
41 - */
42 - readonly suggestCommitAndBranch: (
43 - input: GitSuggestCommitAndBranchInput,
44 - ) => Effect.Effect<GitSuggestCommitAndBranchResult, GitManagerServiceError>;
37 }
38
39 /**
apps/server/src/wsServer.test.ts
+1 -31
@@ -1555,8 +1555,7 @@ describe("WebSocket Server", () => {
1555
1556 const status = vi.fn(() => Effect.succeed(statusResult));
1557 const runStackedAction = vi.fn(() => Effect.void as any);
1558 - const suggestCommitAndBranch = vi.fn(() => Effect.void as any);
1559 - const gitManager: GitManagerShape = { status, runStackedAction, suggestCommitAndBranch };
1558 + const gitManager: GitManagerShape = { status, runStackedAction };
1559
1560 server = await createTestServer({ cwd: "/test", gitManager });
1561 const addr = server.address();
@@ -1586,7 +1585,6 @@ describe("WebSocket Server", () => {
1585 const gitManager: GitManagerShape = {
1586 status: vi.fn(() => Effect.void as any),
1587 runStackedAction,
1589 - suggestCommitAndBranch: vi.fn(() => Effect.void as any),
1588 };
1589
1590 server = await createTestServer({ cwd: "/test", gitManager });
@@ -1609,34 +1607,6 @@ describe("WebSocket Server", () => {
1607 });
1608 });
1609
1612 - it("supports git.suggestCommitAndBranch over websocket", async () => {
1613 - const suggestCommitAndBranchResult = {
1614 - commitMessage: "feat: improve git actions",
1615 - branch: "feature/improve-git-actions",
1616 - };
1617 - const suggestCommitAndBranch = vi.fn(() => Effect.succeed(suggestCommitAndBranchResult));
1618 - const gitManager: GitManagerShape = {
1619 - status: vi.fn(() => Effect.void as any),
1620 - runStackedAction: vi.fn(() => Effect.void as any),
1621 - suggestCommitAndBranch,
1622 - };
1623 -
1624 - server = await createTestServer({ cwd: "/test", gitManager });
1625 - const addr = server.address();
1626 - const port = typeof addr === "object" && addr !== null ? addr.port : 0;
1627 -
1628 - const ws = await connectWs(port);
1629 - connections.push(ws);
1630 - await waitForMessage(ws);
1631 -
1632 - const response = await sendRequest(ws, WS_METHODS.gitSuggestCommitAndBranch, {
1633 - cwd: "/test",
1634 - });
1635 - expect(response.error).toBeUndefined();
1636 - expect(response.result).toEqual(suggestCommitAndBranchResult);
1637 - expect(suggestCommitAndBranch).toHaveBeenCalledWith({ cwd: "/test" });
1638 - });
1639 -
1610 it("rejects websocket connections without a valid auth token", async () => {
1611 server = await createTestServer({ cwd: "/test", authToken: "secret-token" });
1612 const addr = server.address();
apps/server/src/wsServer.ts
-5
@@ -668,11 +668,6 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
668 return yield* gitManager.runStackedAction(body);
669 }
670
671 - case WS_METHODS.gitSuggestCommitAndBranch: {
672 - const body = stripRequestTag(request.body);
673 - return yield* gitManager.suggestCommitAndBranch(body);
674 - }
675 -
671 case WS_METHODS.gitListBranches: {
672 const body = stripRequestTag(request.body);
673 return yield* git.listBranches(body);
apps/web/src/components/GitActionsControl.logic.test.ts
+4
@@ -823,6 +823,7 @@ describe("summarizeGitResult", () => {
823 it("returns commit-focused toast for commit action", () => {
824 const result = summarizeGitResult({
825 action: "commit",
826 + branch: { status: "skipped_not_requested" },
827 commit: {
828 status: "created",
829 commitSha: "0123456789abcdef",
@@ -841,6 +842,7 @@ describe("summarizeGitResult", () => {
842 it("returns push-focused toast for push action", () => {
843 const result = summarizeGitResult({
844 action: "commit_push",
845 + branch: { status: "skipped_not_requested" },
846 commit: {
847 status: "created",
848 commitSha: "abcdef0123456789",
@@ -863,6 +865,7 @@ describe("summarizeGitResult", () => {
865 it("returns PR-focused toast for created PR action", () => {
866 const result = summarizeGitResult({
867 action: "commit_push_pr",
868 + branch: { status: "skipped_not_requested" },
869 commit: {
870 status: "created",
871 commitSha: "89abcdef01234567",
@@ -888,6 +891,7 @@ describe("summarizeGitResult", () => {
891 it("truncates long description text", () => {
892 const result = summarizeGitResult({
893 action: "commit_push_pr",
894 + branch: { status: "skipped_not_requested" },
895 commit: {
896 status: "created",
897 commitSha: "89abcdef01234567",
apps/web/src/components/GitActionsControl.logic.ts
+7 -31
@@ -3,7 +3,6 @@ import type {
3 GitStackedAction,
4 GitStatusResult,
5 } from "@t3tools/contracts";
6 -import { sanitizeBranchFragment } from "@t3tools/shared/git";
6
7 export type GitActionIconName = "commit" | "push" | "pr";
8
@@ -36,7 +35,6 @@ export type DefaultBranchConfirmableAction = "commit_push" | "commit_push_pr";
35
36 const SHORT_SHA_LENGTH = 7;
37 const TOAST_DESCRIPTION_MAX = 72;
39 -const AUTO_FEATURE_BRANCH_FALLBACK = "feature/update";
38
39 function shortenSha(sha: string | undefined): string | null {
40 if (!sha) return null;
@@ -59,7 +57,9 @@ export function buildGitActionProgressStages(input: {
57 hasWorkingTreeChanges: boolean;
58 forcePushOnly?: boolean;
59 pushTarget?: string;
60 + featureBranch?: boolean;
61 }): string[] {
62 + const branchStages = input.featureBranch ? ["Preparing feature branch..."] : [];
63 const shouldIncludeCommitStages =
64 !input.forcePushOnly && (input.action === "commit" || input.hasWorkingTreeChanges);
65 const commitStages = !shouldIncludeCommitStages
@@ -69,12 +69,12 @@ export function buildGitActionProgressStages(input: {
69 : ["Generating commit message...", "Committing..."];
70 const pushStage = input.pushTarget ? `Pushing to ${input.pushTarget}...` : "Pushing...";
71 if (input.action === "commit") {
72 - return commitStages;
72 + return [...branchStages, ...commitStages];
73 }
74 if (input.action === "commit_push") {
75 - return [...commitStages, pushStage];
75 + return [...branchStages, ...commitStages, pushStage];
76 }
77 - return [...commitStages, pushStage, "Creating PR..."];
77 + return [...branchStages, ...commitStages, pushStage, "Creating PR..."];
78 }
79
80 const withDescription = (title: string, description: string | undefined) =>
@@ -322,29 +322,5 @@ export function resolveDefaultBranchActionDialogCopy(input: {
322 };
323 }
324
325 -export function resolveAutoFeatureBranchName(
326 - existingBranchNames: readonly string[],
327 - preferredBranch?: string,
328 -): string {
329 - const preferred = preferredBranch?.trim();
330 - const normalized = sanitizeBranchFragment(
331 - preferred && preferred.length > 0 ? preferred : AUTO_FEATURE_BRANCH_FALLBACK,
332 - );
333 - const resolvedBase = normalized.includes("/")
334 - ? normalized.startsWith("feature/")
335 - ? normalized
336 - : `feature/${normalized}`
337 - : `feature/${normalized}`;
338 - const existingNames = new Set(existingBranchNames);
339 -
340 - if (!existingNames.has(resolvedBase)) {
341 - return resolvedBase;
342 - }
343 -
344 - let suffix = 2;
345 - while (existingNames.has(`${resolvedBase}-${suffix}`)) {
346 - suffix += 1;
347 - }
348 -
349 - return `${resolvedBase}-${suffix}`;
350 -}
325 +// Re-export from shared for backwards compatibility in this module's exports
326 +export { resolveAutoFeatureBranchName } from "@t3tools/shared/git";
apps/web/src/components/GitActionsControl.tsx
+26 -129
@@ -1,4 +1,4 @@
1 -import { type GitStatusResult, type GitStackedAction, type ThreadId } from "@t3tools/contracts";
1 +import type { GitStackedAction, GitStatusResult, ThreadId } from "@t3tools/contracts";
2 import { useIsMutating, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3 import { useCallback, useEffect, useMemo, useState } from "react";
4 import { ChevronDownIcon, CloudUploadIcon, GitCommitIcon, InfoIcon } from "lucide-react";
@@ -11,7 +11,6 @@ import {
11 type GitQuickAction,
12 type DefaultBranchConfirmableAction,
13 requiresDefaultBranchConfirmation,
14 - resolveAutoFeatureBranchName,
14 resolveDefaultBranchActionDialogCopy,
15 resolveQuickAction,
16 summarizeGitResult,
@@ -34,12 +33,10 @@ import { Textarea } from "~/components/ui/textarea";
33 import { toastManager } from "~/components/ui/toast";
34 import {
35 gitBranchesQueryOptions,
37 - gitCreateBranchAndCheckoutMutationOptions,
36 gitInitMutationOptions,
37 gitMutationKeys,
38 gitPullMutationOptions,
39 gitRunStackedActionMutationOptions,
42 - gitSuggestCommitAndBranchMutationOptions,
40 gitStatusQueryOptions,
41 invalidateGitQueries,
42 } from "~/lib/gitReactQuery";
@@ -60,8 +57,6 @@ interface PendingDefaultBranchAction {
57 onConfirmed?: () => void;
58 }
59
63 -type GitActionToastId = ReturnType<typeof toastManager.add>;
64 -
60 function getMenuActionDisabledReason(
61 item: GitActionMenuItem,
62 gitStatus: GitStatusResult | null,
@@ -173,26 +168,12 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
168 const runImmediateGitActionMutation = useMutation(
169 gitRunStackedActionMutationOptions({ cwd: gitCwd, queryClient }),
170 );
176 - const suggestCommitAndBranchMutation = useMutation(
177 - gitSuggestCommitAndBranchMutationOptions({ cwd: gitCwd }),
178 - );
179 - const createBranchAndCheckoutMutation = useMutation(
180 - gitCreateBranchAndCheckoutMutationOptions({ cwd: gitCwd, queryClient }),
181 - );
171 const pullMutation = useMutation(gitPullMutationOptions({ cwd: gitCwd, queryClient }));
172
173 const isRunStackedActionRunning =
174 useIsMutating({ mutationKey: gitMutationKeys.runStackedAction(gitCwd) }) > 0;
186 - const isSuggestCommitAndBranchRunning =
187 - useIsMutating({ mutationKey: gitMutationKeys.suggestCommitAndBranch(gitCwd) }) > 0;
188 - const isCreateBranchAndCheckoutRunning =
189 - useIsMutating({ mutationKey: gitMutationKeys.createBranchAndCheckout(gitCwd) }) > 0;
175 const isPullRunning = useIsMutating({ mutationKey: gitMutationKeys.pull(gitCwd) }) > 0;
191 - const isGitActionRunning =
192 - isRunStackedActionRunning ||
193 - isSuggestCommitAndBranchRunning ||
194 - isCreateBranchAndCheckoutRunning ||
195 - isPullRunning;
176 + const isGitActionRunning = isRunStackedActionRunning || isPullRunning;
177 const isDefaultBranch = useMemo(() => {
178 const branchName = gitStatusForActions?.branch;
179 if (!branchName) return false;
@@ -255,26 +236,23 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
236 forcePushOnlyProgress = false,
237 onConfirmed,
238 skipDefaultBranchPrompt = false,
258 - statusOverride,
259 - isDefaultBranchOverride,
260 - progressToastId,
239 + featureBranch = false,
240 }: {
241 action: GitStackedAction;
242 commitMessage?: string;
243 forcePushOnlyProgress?: boolean;
244 onConfirmed?: () => void;
245 skipDefaultBranchPrompt?: boolean;
267 - statusOverride?: GitStatusResult | null;
268 - isDefaultBranchOverride?: boolean;
269 - progressToastId?: GitActionToastId;
246 + featureBranch?: boolean;
247 }) => {
271 - const actionStatus = statusOverride ?? gitStatusForActions;
272 - const actionIsDefaultBranch = isDefaultBranchOverride ?? isDefaultBranch;
248 + const actionStatus = gitStatusForActions;
249 + const actionIsDefaultBranch = featureBranch ? false : isDefaultBranch;
250 const actionBranch = actionStatus?.branch ?? null;
251 const includesCommit =
252 !forcePushOnlyProgress && (action === "commit" || !!actionStatus?.hasWorkingTreeChanges);
253 if (
254 !skipDefaultBranchPrompt &&
255 + !featureBranch &&
256 requiresDefaultBranchConfirmation(action, actionIsDefaultBranch) &&
257 actionBranch
258 ) {
@@ -293,36 +271,26 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
271 }
272 onConfirmed?.();
273
296 - const pushTarget = actionBranch ? `origin/${actionBranch}` : undefined;
274 + const pushTarget = !featureBranch && actionBranch ? `origin/${actionBranch}` : undefined;
275 const progressStages = buildGitActionProgressStages({
276 action,
277 hasCustomCommitMessage: !!commitMessage?.trim(),
278 hasWorkingTreeChanges: !!actionStatus?.hasWorkingTreeChanges,
279 forcePushOnly: forcePushOnlyProgress,
280 + featureBranch,
281 ...(pushTarget ? { pushTarget } : {}),
282 });
304 - const resolvedProgressToastId =
305 - progressToastId ??
306 - toastManager.add({
307 - type: "loading",
308 - title: progressStages[0] ?? "Running git action...",
309 - timeout: 0,
310 - data: threadToastData,
311 - });
312 -
313 - if (progressToastId) {
314 - toastManager.update(progressToastId, {
315 - type: "loading",
316 - title: progressStages[0] ?? "Running git action...",
317 - timeout: 0,
318 - data: threadToastData,
319 - });
320 - }
283 + const progressToastId = toastManager.add({
284 + type: "loading",
285 + title: progressStages[0] ?? "Running git action...",
286 + timeout: 0,
287 + data: threadToastData,
288 + });
289
290 let stageIndex = 0;
291 const stageInterval = setInterval(() => {
292 stageIndex = Math.min(stageIndex + 1, progressStages.length - 1);
325 - toastManager.update(resolvedProgressToastId, {
293 + toastManager.update(progressToastId, {
294 title: progressStages[stageIndex] ?? "Running git action...",
295 type: "loading",
296 timeout: 0,
@@ -337,6 +305,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
305 const promise = runImmediateGitActionMutation.mutateAsync({
306 action,
307 ...(commitMessage ? { commitMessage } : {}),
308 + ...(featureBranch ? { featureBranch } : {}),
309 });
310
311 try {
@@ -357,10 +326,10 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
326 result.push.status === "pushed" &&
327 !actionIsDefaultBranch;
328 const closeResultToast = () => {
360 - toastManager.close(resolvedProgressToastId);
329 + toastManager.close(progressToastId);
330 };
331
363 - toastManager.update(resolvedProgressToastId, {
332 + toastManager.update(progressToastId, {
333 type: "success",
334 title: resultToast.title,
335 description: resultToast.description,
@@ -378,8 +347,6 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
347 action: "commit_push",
348 forcePushOnlyProgress: true,
349 onConfirmed: closeResultToast,
381 - statusOverride: actionStatus,
382 - isDefaultBranchOverride: actionIsDefaultBranch,
350 });
351 },
352 },
@@ -404,8 +371,6 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
371 closeResultToast();
372 void runGitActionWithToast({
373 action: "commit_push_pr",
407 - statusOverride: actionStatus,
408 - isDefaultBranchOverride: actionIsDefaultBranch,
374 });
375 },
376 },
@@ -414,7 +379,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
379 });
380 } catch (err) {
381 stopProgressUpdates();
417 - toastManager.update(resolvedProgressToastId, {
382 + toastManager.update(progressToastId, {
383 type: "error",
384 title: "Action failed",
385 description: err instanceof Error ? err.message : "An error occurred.",
@@ -449,92 +414,24 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
414 (actionParams: {
415 action: GitStackedAction;
416 commitMessage?: string;
452 - forcePushOnlyProgress?: boolean;
417 onConfirmed?: () => void;
418 }) => {
455 - const existingBranchNames = branchList?.branches.map((branch) => branch.name) ?? [];
456 - const providedCommitMessage = actionParams.commitMessage?.trim() || undefined;
457 - const shouldSuggestCommitAndBranch =
458 - !providedCommitMessage && !!gitStatusForActions?.hasWorkingTreeChanges;
459 -
460 - const checkoutToastId = toastManager.add({
461 - type: "loading",
462 - title: "Preparing feature branch...",
463 - timeout: 0,
464 - data: threadToastData,
419 + void runGitActionWithToast({
420 + ...actionParams,
421 + featureBranch: true,
422 + skipDefaultBranchPrompt: true,
423 });
466 -
467 - const suggestionPromise = shouldSuggestCommitAndBranch
468 - ? suggestCommitAndBranchMutation.mutateAsync({}).catch(() => null)
469 - : Promise.resolve(null);
470 -
471 - void suggestionPromise
472 - .then((suggestion) => {
473 - const preferredBranch =
474 - suggestion?.branch ??
475 - (providedCommitMessage ? providedCommitMessage.split(/\r?\n/g)[0]?.trim() : undefined);
476 - const branchName = resolveAutoFeatureBranchName(existingBranchNames, preferredBranch);
477 - const resolvedCommitMessage = suggestion?.commitMessage ?? providedCommitMessage;
478 -
479 - toastManager.update(checkoutToastId, {
480 - type: "loading",
481 - title: `Creating ${branchName}...`,
482 - timeout: 0,
483 - data: threadToastData,
484 - });
485 -
486 - return createBranchAndCheckoutMutation.mutateAsync(branchName).then(() => ({
487 - branchName,
488 - resolvedCommitMessage,
489 - }));
490 - })
491 - .then(({ branchName, resolvedCommitMessage }) => {
492 - const statusOverride = gitStatusForActions
493 - ? {
494 - ...gitStatusForActions,
495 - branch: branchName,
496 - pr: null,
497 - hasUpstream: false,
498 - aheadCount: 0,
499 - behindCount: 0,
500 - }
501 - : null;
502 - return runGitActionWithToast({
503 - ...actionParams,
504 - ...(resolvedCommitMessage ? { commitMessage: resolvedCommitMessage } : {}),
505 - skipDefaultBranchPrompt: true,
506 - statusOverride,
507 - isDefaultBranchOverride: false,
508 - progressToastId: checkoutToastId,
509 - });
510 - })
511 - .catch((error) => {
512 - toastManager.update(checkoutToastId, {
513 - type: "error",
514 - title: "Failed to checkout feature branch",
515 - description: error instanceof Error ? error.message : "An error occurred.",
516 - data: threadToastData,
517 - });
518 - });
424 },
520 - [
521 - branchList?.branches,
522 - createBranchAndCheckoutMutation,
523 - gitStatusForActions,
524 - runGitActionWithToast,
525 - suggestCommitAndBranchMutation,
526 - threadToastData,
527 - ],
425 + [runGitActionWithToast],
426 );
427
428 const checkoutFeatureBranchAndContinuePendingAction = useCallback(() => {
429 if (!pendingDefaultBranchAction) return;
532 - const { action, commitMessage, forcePushOnlyProgress, onConfirmed } = pendingDefaultBranchAction;
430 + const { action, commitMessage, onConfirmed } = pendingDefaultBranchAction;
431 setPendingDefaultBranchAction(null);
432 checkoutNewBranchAndRunAction({
433 action,
434 ...(commitMessage ? { commitMessage } : {}),
537 - forcePushOnlyProgress,
435 ...(onConfirmed ? { onConfirmed } : {}),
436 });
437 }, [pendingDefaultBranchAction, checkoutNewBranchAndRunAction]);
apps/web/src/lib/gitReactQuery.test.ts
-12
@@ -4,7 +4,6 @@ import {
4 gitMutationKeys,
5 gitPullMutationOptions,
6 gitRunStackedActionMutationOptions,
7 - gitSuggestCommitAndBranchMutationOptions,
7 } from "./gitReactQuery";
8
9 describe("gitMutationKeys", () => {
@@ -17,12 +16,6 @@ describe("gitMutationKeys", () => {
16 it("scopes pull keys by cwd", () => {
17 expect(gitMutationKeys.pull("/repo/a")).not.toEqual(gitMutationKeys.pull("/repo/b"));
18 });
20 -
21 - it("scopes suggest-commit-and-branch keys by cwd", () => {
22 - expect(gitMutationKeys.suggestCommitAndBranch("/repo/a")).not.toEqual(
23 - gitMutationKeys.suggestCommitAndBranch("/repo/b"),
24 - );
25 - });
19 });
20
21 describe("git mutation options", () => {
@@ -37,9 +30,4 @@ describe("git mutation options", () => {
30 const options = gitPullMutationOptions({ cwd: "/repo/a", queryClient });
31 expect(options.mutationKey).toEqual(gitMutationKeys.pull("/repo/a"));
32 });
40 -
41 - it("attaches cwd-scoped mutation key for suggestCommitAndBranch", () => {
42 - const options = gitSuggestCommitAndBranchMutationOptions({ cwd: "/repo/a" });
43 - expect(options.mutationKey).toEqual(gitMutationKeys.suggestCommitAndBranch("/repo/a"));
44 - });
33 });
apps/web/src/lib/gitReactQuery.ts
+3 -16
@@ -19,8 +19,6 @@ export const gitMutationKeys = {
19 createBranchAndCheckout: (cwd: string | null) =>
20 ["git", "mutation", "create-branch-and-checkout", cwd] as const,
21 runStackedAction: (cwd: string | null) => ["git", "mutation", "run-stacked-action", cwd] as const,
22 - suggestCommitAndBranch: (cwd: string | null) =>
23 - ["git", "mutation", "suggest-commit-and-branch", cwd] as const,
22 pull: (cwd: string | null) => ["git", "mutation", "pull", cwd] as const,
23 };
24
@@ -118,9 +116,11 @@ export function gitRunStackedActionMutationOptions(input: {
116 mutationFn: async ({
117 action,
118 commitMessage,
119 + featureBranch,
120 }: {
121 action: GitStackedAction;
122 commitMessage?: string;
123 + featureBranch?: boolean;
124 }) => {
125 const api = ensureNativeApi();
126 if (!input.cwd) throw new Error("Git action is unavailable.");
@@ -128,6 +128,7 @@ export function gitRunStackedActionMutationOptions(input: {
128 cwd: input.cwd,
129 action,
130 ...(commitMessage ? { commitMessage } : {}),
131 + ...(featureBranch ? { featureBranch } : {}),
132 });
133 },
134 onSettled: async () => {
@@ -136,20 +137,6 @@ export function gitRunStackedActionMutationOptions(input: {
137 });
138 }
139
139 -export function gitSuggestCommitAndBranchMutationOptions(input: { cwd: string | null }) {
140 - return mutationOptions({
141 - mutationKey: gitMutationKeys.suggestCommitAndBranch(input.cwd),
142 - mutationFn: async ({ commitMessage }: { commitMessage?: string }) => {
143 - const api = ensureNativeApi();
144 - if (!input.cwd) throw new Error("Git action is unavailable.");
145 - return api.git.suggestCommitAndBranch({
146 - cwd: input.cwd,
147 - ...(commitMessage ? { commitMessage } : {}),
148 - });
149 - },
150 - });
151 -}
152 -
140 export function gitPullMutationOptions(input: { cwd: string | null; queryClient: QueryClient }) {
141 return mutationOptions({
142 mutationKey: gitMutationKeys.pull(input.cwd),
apps/web/src/wsNativeApi.test.ts
-1
@@ -6,7 +6,6 @@ import {
6 ProjectId,
7 ThreadId,
8 WS_CHANNELS,
9 - WS_METHODS,
9 } from "@t3tools/contracts";
10 import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
11
apps/web/src/wsNativeApi.ts
-2
@@ -163,8 +163,6 @@ export function createWsNativeApi(): NativeApi {
163 pull: (input) => transport.request(WS_METHODS.gitPull, input),
164 status: (input) => transport.request(WS_METHODS.gitStatus, input),
165 runStackedAction: (input) => transport.request(WS_METHODS.gitRunStackedAction, input),
166 - suggestCommitAndBranch: (input) =>
167 - transport.request(WS_METHODS.gitSuggestCommitAndBranch, input),
166 listBranches: (input) => transport.request(WS_METHODS.gitListBranches, input),
167 createWorktree: (input) => transport.request(WS_METHODS.gitCreateWorktree, input),
168 removeWorktree: (input) => transport.request(WS_METHODS.gitRemoveWorktree, input),
packages/contracts/src/git.ts
+6 -12
@@ -13,6 +13,7 @@ export const GitPushStepStatus = Schema.Literals([
13 "skipped_not_requested",
14 "skipped_up_to_date",
15 ]);
16 +export const GitBranchStepStatus = Schema.Literals(["created", "skipped_not_requested"]);
17 export const GitPrStepStatus = Schema.Literals([
18 "created",
19 "opened_existing",
@@ -53,15 +54,10 @@ export const GitRunStackedActionInput = Schema.Struct({
54 cwd: TrimmedNonEmptyStringSchema,
55 action: GitStackedAction,
56 commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),
57 + featureBranch: Schema.optional(Schema.Boolean),
58 });
59 export type GitRunStackedActionInput = typeof GitRunStackedActionInput.Type;
60
59 -export const GitSuggestCommitAndBranchInput = Schema.Struct({
60 - cwd: TrimmedNonEmptyStringSchema,
61 - commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),
62 -});
63 -export type GitSuggestCommitAndBranchInput = typeof GitSuggestCommitAndBranchInput.Type;
64 -
61 export const GitListBranchesInput = Schema.Struct({
62 cwd: TrimmedNonEmptyStringSchema,
63 });
@@ -145,6 +141,10 @@ export type GitCreateWorktreeResult = typeof GitCreateWorktreeResult.Type;
141
142 export const GitRunStackedActionResult = Schema.Struct({
143 action: GitStackedAction,
144 + branch: Schema.Struct({
145 + status: GitBranchStepStatus,
146 + name: Schema.optional(TrimmedNonEmptyStringSchema),
147 + }),
148 commit: Schema.Struct({
149 status: GitCommitStepStatus,
150 commitSha: Schema.optional(TrimmedNonEmptyStringSchema),
@@ -167,12 +167,6 @@ export const GitRunStackedActionResult = Schema.Struct({
167 });
168 export type GitRunStackedActionResult = typeof GitRunStackedActionResult.Type;
169
170 -export const GitSuggestCommitAndBranchResult = Schema.Struct({
171 - commitMessage: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000)),
172 - branch: TrimmedNonEmptyStringSchema,
173 -});
174 -export type GitSuggestCommitAndBranchResult = typeof GitSuggestCommitAndBranchResult.Type;
175 -
170 export const GitPullResult = Schema.Struct({
171 status: Schema.Literals(["pulled", "skipped_up_to_date"]),
172 branch: TrimmedNonEmptyStringSchema,
packages/contracts/src/ipc.ts
-5
@@ -11,8 +11,6 @@ import type {
11 GitRemoveWorktreeInput,
12 GitRunStackedActionInput,
13 GitRunStackedActionResult,
14 - GitSuggestCommitAndBranchInput,
15 - GitSuggestCommitAndBranchResult,
14 GitStatusInput,
15 GitStatusResult,
16 } from "./git";
@@ -90,9 +88,6 @@ export interface NativeApi {
88 pull: (input: GitPullInput) => Promise<GitPullResult>;
89 status: (input: GitStatusInput) => Promise<GitStatusResult>;
90 runStackedAction: (input: GitRunStackedActionInput) => Promise<GitRunStackedActionResult>;
93 - suggestCommitAndBranch: (
94 - input: GitSuggestCommitAndBranchInput,
95 - ) => Promise<GitSuggestCommitAndBranchResult>;
91 };
92 contextMenu: {
93 show: <T extends string>(
packages/contracts/src/ws.ts
-3
@@ -18,7 +18,6 @@ import {
18 GitPullInput,
19 GitRemoveWorktreeInput,
20 GitRunStackedActionInput,
21 - GitSuggestCommitAndBranchInput,
21 GitStatusInput,
22 } from "./git";
23 import {
@@ -49,7 +48,6 @@ export const WS_METHODS = {
48 gitPull: "git.pull",
49 gitStatus: "git.status",
50 gitRunStackedAction: "git.runStackedAction",
52 - gitSuggestCommitAndBranch: "git.suggestCommitAndBranch",
51 gitListBranches: "git.listBranches",
52 gitCreateWorktree: "git.createWorktree",
53 gitRemoveWorktree: "git.removeWorktree",
@@ -111,7 +109,6 @@ export const WebSocketRequestBody = Schema.Union([
109 tagRequestBody(WS_METHODS.gitPull, GitPullInput),
110 tagRequestBody(WS_METHODS.gitStatus, GitStatusInput),
111 tagRequestBody(WS_METHODS.gitRunStackedAction, GitRunStackedActionInput),
114 - tagRequestBody(WS_METHODS.gitSuggestCommitAndBranch, GitSuggestCommitAndBranchInput),
112 tagRequestBody(WS_METHODS.gitListBranches, GitListBranchesInput),
113 tagRequestBody(WS_METHODS.gitCreateWorktree, GitCreateWorktreeInput),
114 tagRequestBody(WS_METHODS.gitRemoveWorktree, GitRemoveWorktreeInput),
packages/shared/src/git.ts
+33
@@ -31,3 +31,36 @@ export function sanitizeFeatureBranchName(raw: string): string {
31 }
32 return `feature/${sanitized}`;
33 }
34 +
35 +const AUTO_FEATURE_BRANCH_FALLBACK = "feature/update";
36 +
37 +/**
38 + * Resolve a unique `feature/…` branch name that doesn't collide with
39 + * any existing branch. Appends a numeric suffix when needed.
40 + */
41 +export function resolveAutoFeatureBranchName(
42 + existingBranchNames: readonly string[],
43 + preferredBranch?: string,
44 +): string {
45 + const preferred = preferredBranch?.trim();
46 + const normalized = sanitizeBranchFragment(
47 + preferred && preferred.length > 0 ? preferred : AUTO_FEATURE_BRANCH_FALLBACK,
48 + );
49 + const resolvedBase = normalized.includes("/")
50 + ? normalized.startsWith("feature/")
51 + ? normalized
52 + : `feature/${normalized}`
53 + : `feature/${normalized}`;
54 + const existingNames = new Set(existingBranchNames);
55 +
56 + if (!existingNames.has(resolvedBase)) {
57 + return resolvedBase;
58 + }
59 +
60 + let suffix = 2;
61 + while (existingNames.has(`${resolvedBase}-${suffix}`)) {
62 + suffix += 1;
63 + }
64 +
65 + return `${resolvedBase}-${suffix}`;
66 +}