Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Move PR checkout flow to dialog and drop /checkout-pr command
Julius Marminged28ced8fd747
diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsxindex 1817e2907..dbef056ca 100644--- a/apps/web/src/components/BranchToolbarBranchSelector.tsx+++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx@@ -291,7 +291,8 @@ export function BranchToolbarBranchSelector({const branchListScrollElementRef = useRef<HTMLDivElement | null>(null);const branchListVirtualizer = useVirtualizer({count: filteredBranchPickerItems.length,- estimateSize: () => 28,+ estimateSize: (index) =>+ filteredBranchPickerItems[index] === checkoutPullRequestItemValue ? 44 : 28,getScrollElement: () => branchListScrollElementRef.current,overscan: 12,enabled: isBranchMenuOpen && shouldVirtualizeBranchList,@@ -409,7 +410,7 @@ export function BranchToolbarBranchSelector({items={branchPickerItems}filteredItems={filteredBranchPickerItems}autoHighlight- virtualized+ virtualized={shouldVirtualizeBranchList}onItemHighlighted={(_value, eventDetails) => {if (!isBranchMenuOpen || eventDetails.index < 0) return;branchListVirtualizer.scrollToIndex(eventDetails.index, { align: "auto" });diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 80d440994..ee3de304e 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -119,7 +119,6 @@ import {type TurnDiffTreeNode,} from "../lib/turnDiffTree";import BranchToolbar from "./BranchToolbar";-import { ComposerPullRequestCommandMenu } from "./ComposerPullRequestCommandMenu";import GitActionsControl from "./GitActionsControl";import {isOpenFavoriteEditorShortcut,@@ -217,6 +216,7 @@ import { shouldUseCompactComposerFooter } from "./composerFooterLayout";import { selectThreadTerminalState, useTerminalStateStore } from "../terminalStateStore";import { clamp } from "effect/Number";import { ComposerPromptEditor, type ComposerPromptEditorHandle } from "./ComposerPromptEditor";+import { PullRequestThreadDialog } from "./PullRequestThreadDialog";import { estimateTimelineMessageHeight } from "./timelineHeight";function formatMessageMeta(createdAt: string, duration: string | null): string {@@ -408,7 +408,7 @@ type ComposerCommandItem =type SendPhase = "idle" | "preparing-worktree" | "sending-turn";-interface PullRequestComposerMenuState {+interface PullRequestDialogState {initialReference: string | null;key: number;}@@ -657,8 +657,9 @@ export default function ChatView({ threadId }: ChatViewProps) {const [nowTick, setNowTick] = useState(() => Date.now());const [terminalFocusRequestId, setTerminalFocusRequestId] = useState(0);const [composerHighlightedItemId, setComposerHighlightedItemId] = useState<string | null>(null);- const [pullRequestComposerMenuState, setPullRequestComposerMenuState] =- useState<PullRequestComposerMenuState | null>(null);+ const [pullRequestDialogState, setPullRequestDialogState] = useState<PullRequestDialogState | null>(+ null,+ );const [attachmentPreviewHandoffByMessageId, setAttachmentPreviewHandoffByMessageId] = useState<Record<string, string[]>>({});@@ -764,19 +765,19 @@ export default function ChatView({ threadId }: ChatViewProps) {const latestTurnSettled = isLatestTurnSettled(activeLatestTurn, activeThread?.session ?? null);const activeProject = projects.find((p) => p.id === activeThread?.projectId);- const openPullRequestComposerMenu = useCallback((reference?: string) => {+ const openPullRequestDialog = useCallback((reference?: string) => {if (!canCheckoutPullRequestIntoThread) {return;}- setPullRequestComposerMenuState({+ setPullRequestDialogState({initialReference: reference ?? null,key: Date.now(),});setComposerHighlightedItemId(null);}, [canCheckoutPullRequestIntoThread]);- const closePullRequestComposerMenu = useCallback(() => {- setPullRequestComposerMenuState(null);+ const closePullRequestDialog = useCallback(() => {+ setPullRequestDialogState(null);}, []);const openOrReuseProjectDraftThread = useCallback(@@ -1254,7 +1255,6 @@ export default function ChatView({ threadId }: ChatViewProps) {timelineEntries,]);const gitCwd = activeThread?.worktreePath ?? activeProject?.cwd ?? null;- const pullRequestComposerMenuOpen = pullRequestComposerMenuState !== null;const composerTriggerKind = composerTrigger?.kind ?? null;const pathTriggerQuery = composerTrigger?.kind === "path" ? composerTrigger.query : "";const isPathTrigger = composerTriggerKind === "path";@@ -1311,22 +1311,12 @@ export default function ChatView({ threadId }: ChatViewProps) {label: "/default",description: "Switch this thread back to normal chat mode",},- {- id: "slash:checkout-pr",- type: "slash-command",- command: "checkout-pr",- label: "/checkout-pr",- description: "Create a new thread from a GitHub pull request",- },] satisfies ReadonlyArray<Extract<ComposerCommandItem, { type: "slash-command" }>>;- const availableSlashCommandItems = canCheckoutPullRequestIntoThread- ? slashCommandItems- : slashCommandItems.filter((item) => item.command !== "checkout-pr");const query = composerTrigger.query.trim().toLowerCase();if (!query) {- return [...availableSlashCommandItems];+ return [...slashCommandItems];}- return availableSlashCommandItems.filter(+ return slashCommandItems.filter((item) => item.command.includes(query) || item.label.slice(1).includes(query),);}@@ -1347,16 +1337,14 @@ export default function ChatView({ threadId }: ChatViewProps) {label: name,description: `${providerLabel} · ${slug}`,}));- }, [canCheckoutPullRequestIntoThread, composerTrigger, searchableModelOptions, workspaceEntries]);- const composerMenuOpen = Boolean(composerTrigger) || pullRequestComposerMenuOpen;+ }, [composerTrigger, searchableModelOptions, workspaceEntries]);+ const composerMenuOpen = Boolean(composerTrigger);const activeComposerMenuItem = useMemo(() =>- pullRequestComposerMenuOpen- ? null- : (composerMenuItems.find((item) => item.id === composerHighlightedItemId) ??- composerMenuItems[0] ??- null),- [composerHighlightedItemId, composerMenuItems, pullRequestComposerMenuOpen],+ composerMenuItems.find((item) => item.id === composerHighlightedItemId) ??+ composerMenuItems[0] ??+ null,+ [composerHighlightedItemId, composerMenuItems],);composerMenuOpenRef.current = composerMenuOpen;composerMenuItemsRef.current = composerMenuItems;@@ -2055,7 +2043,7 @@ export default function ChatView({ threadId }: ChatViewProps) {useEffect(() => {setExpandedWorkGroups({});- setPullRequestComposerMenuState(null);+ setPullRequestDialogState(null);if (planSidebarOpenOnNextThreadRef.current) {planSidebarOpenOnNextThreadRef.current = false;setPlanSidebarOpen(true);@@ -2070,16 +2058,12 @@ export default function ChatView({ threadId }: ChatViewProps) {setComposerHighlightedItemId(null);return;}- if (pullRequestComposerMenuOpen) {- setComposerHighlightedItemId(null);- return;- }setComposerHighlightedItemId((existing) =>existing && composerMenuItems.some((item) => item.id === existing)? existing: (composerMenuItems[0]?.id ?? null),);- }, [composerMenuItems, composerMenuOpen, pullRequestComposerMenuOpen]);+ }, [composerMenuItems, composerMenuOpen]);useEffect(() => {setIsRevertingCheckpoint(false);@@ -2589,15 +2573,8 @@ export default function ChatView({ threadId }: ChatViewProps) {}const standaloneSlashCommand =composerImages.length === 0 ? parseStandaloneComposerSlashCommand(trimmed) : null;- const shouldHandleStandaloneSlashCommand =- standaloneSlashCommand !== null &&- (standaloneSlashCommand !== "checkout-pr" || canCheckoutPullRequestIntoThread);- if (shouldHandleStandaloneSlashCommand && standaloneSlashCommand) {- if (standaloneSlashCommand === "checkout-pr") {- openPullRequestComposerMenu();- } else {- await handleInteractionModeChange(standaloneSlashCommand);- }+ if (standaloneSlashCommand) {+ await handleInteractionModeChange(standaloneSlashCommand);promptRef.current = "";clearComposerDraftContent(activeThread.id);setComposerHighlightedItemId(null);@@ -3386,11 +3363,7 @@ export default function ChatView({ threadId }: ChatViewProps) {}return;}- if (item.command === "checkout-pr") {- openPullRequestComposerMenu();- } else {- void handleInteractionModeChange(item.command === "plan" ? "plan" : "default");- }+ void handleInteractionModeChange(item.command === "plan" ? "plan" : "default");const applied = applyPromptReplacement(trigger.rangeStart, trigger.rangeEnd, "", {expectedText: expectedToken,});@@ -3410,7 +3383,6 @@ export default function ChatView({ threadId }: ChatViewProps) {[applyPromptReplacement,handleInteractionModeChange,- openPullRequestComposerMenu,onProviderModelSelect,resolveActiveComposerTrigger,],@@ -3485,12 +3457,6 @@ export default function ChatView({ threadId }: ChatViewProps) {const { trigger } = resolveActiveComposerTrigger();const menuIsActive = composerMenuOpenRef.current || trigger !== null;- if (pullRequestComposerMenuOpen) {- if (key === "ArrowDown" || key === "ArrowUp" || key === "Tab" || key === "Enter") {- return true;- }- }-if (menuIsActive) {const currentItems = composerMenuItemsRef.current;if (key === "ArrowDown" && currentItems.length > 0) {@@ -3712,28 +3678,15 @@ export default function ChatView({ threadId }: ChatViewProps) {>{composerMenuOpen && !isComposerApprovalState && (<div className="absolute inset-x-0 bottom-full z-20 mb-2 px-1">- {pullRequestComposerMenuState ? (- <ComposerPullRequestCommandMenu- key={pullRequestComposerMenuState.key}- cwd={activeProject?.cwd ?? null}- initialReference={pullRequestComposerMenuState.initialReference}- onCancel={closePullRequestComposerMenu}- onPrepared={async (input) => {- await handlePreparedPullRequestThread(input);- closePullRequestComposerMenu();- }}- />- ) : (- <ComposerCommandMenu- items={composerMenuItems}- resolvedTheme={resolvedTheme}- isLoading={isComposerMenuLoading}- triggerKind={composerTriggerKind}- activeItemId={activeComposerMenuItem?.id ?? null}- onHighlightedItemChange={onComposerMenuItemHighlighted}- onSelect={onSelectComposerItem}- />- )}+ <ComposerCommandMenu+ items={composerMenuItems}+ resolvedTheme={resolvedTheme}+ isLoading={isComposerMenuLoading}+ triggerKind={composerTriggerKind}+ activeItemId={activeComposerMenuItem?.id ?? null}+ onHighlightedItemChange={onComposerMenuItemHighlighted}+ onSelect={onSelectComposerItem}+ /></div>)}@@ -4160,10 +4113,24 @@ export default function ChatView({ threadId }: ChatViewProps) {envLocked={envLocked}onComposerFocusRequest={scheduleComposerFocus}{...(canCheckoutPullRequestIntoThread- ? { onCheckoutPullRequestRequest: openPullRequestComposerMenu }+ ? { onCheckoutPullRequestRequest: openPullRequestDialog }: {})}/>)}+ {pullRequestDialogState ? (+ <PullRequestThreadDialog+ key={pullRequestDialogState.key}+ open+ cwd={activeProject?.cwd ?? null}+ initialReference={pullRequestDialogState.initialReference}+ onOpenChange={(open) => {+ if (!open) {+ closePullRequestDialog();+ }+ }}+ onPrepared={handlePreparedPullRequestThread}+ />+ ) : null}</div>{/* end chat column */}{/* Plan sidebar */}diff --git a/apps/web/src/components/ComposerPullRequestCommandMenu.tsx b/apps/web/src/components/PullRequestThreadDialog.tsxsimilarity index 62%rename from apps/web/src/components/ComposerPullRequestCommandMenu.tsxrename to apps/web/src/components/PullRequestThreadDialog.tsxindex 53dd7ab2e..ced24aca7 100644--- a/apps/web/src/components/ComposerPullRequestCommandMenu.tsx+++ b/apps/web/src/components/PullRequestThreadDialog.tsx@@ -10,22 +10,33 @@ import {import { cn } from "~/lib/utils";import { parsePullRequestReference } from "~/pullRequestReference";import { Button } from "./ui/button";+import {+ Dialog,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogPanel,+ DialogPopup,+ DialogTitle,+} from "./ui/dialog";import { Input } from "./ui/input";import { Spinner } from "./ui/spinner";-interface ComposerPullRequestCommandMenuProps {+interface PullRequestThreadDialogProps {+ open: boolean;cwd: string | null;initialReference: string | null;- onCancel: () => void;+ onOpenChange: (open: boolean) => void;onPrepared: (input: { branch: string; worktreePath: string | null }) => Promise<void> | void;}-export function ComposerPullRequestCommandMenu({+export function PullRequestThreadDialog({+ open,cwd,initialReference,- onCancel,+ onOpenChange,onPrepared,-}: ComposerPullRequestCommandMenuProps) {+}: PullRequestThreadDialogProps) {const queryClient = useQueryClient();const referenceInputRef = useRef<HTMLInputElement>(null);const [reference, setReference] = useState(initialReference ?? "");@@ -38,12 +49,14 @@ export function ComposerPullRequestCommandMenu({);useEffect(() => {+ if (!open) return;setReference(initialReference ?? "");setReferenceDirty(false);setPreparingMode(null);- }, [initialReference]);+ }, [initialReference, open]);useEffect(() => {+ if (!open) return;const frame = window.requestAnimationFrame(() => {referenceInputRef.current?.focus();referenceInputRef.current?.select();@@ -51,14 +64,14 @@ export function ComposerPullRequestCommandMenu({return () => {window.cancelAnimationFrame(frame);};- }, []);+ }, [open]);const parsedReference = parsePullRequestReference(reference);const parsedDebouncedReference = parsePullRequestReference(debouncedReference);const resolvePullRequestQuery = useQuery(gitResolvePullRequestQueryOptions({cwd,- reference: parsedDebouncedReference,+ reference: open ? parsedDebouncedReference : null,}),);const cachedPullRequest = useMemo(() => {@@ -83,6 +96,7 @@ export function ComposerPullRequestCommandMenu({: null;const resolvedPullRequest = liveResolvedPullRequest ?? cachedPullRequest;const isResolving =+ open &&parsedReference !== null &&resolvedPullRequest === null &&(referenceDebouncer.state.isPending ||@@ -120,11 +134,13 @@ export function ComposerPullRequestCommandMenu({branch: result.branch,worktreePath: result.worktreePath,});+ onOpenChange(false);} finally {setPreparingMode(null);}}, [cwd,+ onOpenChange,onPrepared,parsedReference,preparePullRequestThreadMutation,@@ -135,10 +151,10 @@ export function ComposerPullRequestCommandMenu({!referenceDirty? null: reference.trim().length === 0- ? "Paste a GitHub pull request URL or enter 123 / #123."- : parsedReference === null- ? "Use a GitHub pull request URL, 123, or #123."- : null;+ ? "Paste a GitHub pull request URL or enter 123 / #123."+ : parsedReference === null+ ? "Use a GitHub pull request URL, 123, or #123."+ : null;const errorMessage =validationMessage ??(resolvedPullRequest === null && resolvePullRequestQuery.isError@@ -152,73 +168,79 @@ export function ComposerPullRequestCommandMenu({: null));return (- <div className="overflow-hidden rounded-xl border border-border/80 bg-popover/96 shadow-lg/8 backdrop-blur-xs">- <div className="space-y-4 p-3">- <div className="space-y-2">- <div className="flex items-center justify-between gap-3">- <div>- <p className="font-medium text-sm">Checkout Pull Request</p>- <p className="text-muted-foreground text-xs">- Resolve a PR, then choose Local or Worktree for the new draft thread.- </p>- </div>- </div>- <Input- autoFocus- ref={referenceInputRef}- placeholder="https://github.com/owner/repo/pull/42 or #42"- value={reference}- onChange={(event) => {- setReferenceDirty(true);- setReference(event.target.value);- }}- onKeyDown={(event) => {- if (event.key !== "Enter") {- return;- }- event.preventDefault();- if (!isResolving && !preparePullRequestThreadMutation.isPending) {- void handleConfirm("local");- }- }}- />- </div>+ <Dialog+ open={open}+ onOpenChange={(nextOpen) => {+ if (!preparePullRequestThreadMutation.isPending) {+ onOpenChange(nextOpen);+ }+ }}+ >+ <DialogPopup className="max-w-xl">+ <DialogHeader>+ <DialogTitle>Checkout Pull Request</DialogTitle>+ <DialogDescription>+ Resolve a GitHub pull request, then create the draft thread in the main repo or in a+ dedicated worktree.+ </DialogDescription>+ </DialogHeader>+ <DialogPanel className="space-y-4">+ <label className="grid gap-1.5">+ <span className="text-xs font-medium text-foreground">Pull request</span>+ <Input+ ref={referenceInputRef}+ placeholder="https://github.com/owner/repo/pull/42 or #42"+ value={reference}+ onChange={(event) => {+ setReferenceDirty(true);+ setReference(event.target.value);+ }}+ onKeyDown={(event) => {+ if (event.key !== "Enter") {+ return;+ }+ event.preventDefault();+ if (!isResolving && !preparePullRequestThreadMutation.isPending) {+ void handleConfirm("local");+ }+ }}+ />+ </label>- {resolvedPullRequest ? (- <div className="rounded-xl border border-border/70 bg-muted/24 p-3">- <div className="flex items-start justify-between gap-3">- <div className="min-w-0">- <p className="truncate font-medium text-sm">{resolvedPullRequest.title}</p>- <p className="truncate text-muted-foreground text-xs">- #{resolvedPullRequest.number} · {resolvedPullRequest.headBranch} to{" "}- {resolvedPullRequest.baseBranch}- </p>+ {resolvedPullRequest ? (+ <div className="rounded-xl border border-border/70 bg-muted/24 p-3">+ <div className="flex items-start justify-between gap-3">+ <div className="min-w-0">+ <p className="truncate font-medium text-sm">{resolvedPullRequest.title}</p>+ <p className="truncate text-muted-foreground text-xs">+ #{resolvedPullRequest.number} · {resolvedPullRequest.headBranch} to{" "}+ {resolvedPullRequest.baseBranch}+ </p>+ </div>+ <span className={cn("shrink-0 text-xs capitalize", statusTone)}>+ {resolvedPullRequest.state}+ </span></div>- <span className={cn("shrink-0 text-xs capitalize", statusTone)}>- {resolvedPullRequest.state}- </span></div>- </div>- ) : null}-- {isResolving ? (- <div className="flex items-center gap-2 text-muted-foreground text-xs">- <Spinner className="size-3.5" />- Resolving pull request...- </div>- ) : null}+ ) : null}- {errorMessage ? <p className="text-destructive text-xs">{errorMessage}</p> : null}- </div>+ {isResolving ? (+ <div className="flex items-center gap-2 text-muted-foreground text-xs">+ <Spinner className="size-3.5" />+ Resolving pull request...+ </div>+ ) : null}- <div className="flex items-center justify-between gap-2 border-t px-3 py-2">- <p className="text-muted-foreground text-xs">- {resolvedPullRequest- ? "Create the draft thread in the main repo or in a dedicated worktree."- : "Resolve the pull request first."}- </p>- <div className="flex items-center gap-2">- <Button type="button" variant="ghost" size="sm" onClick={onCancel}>+ {errorMessage ? <p className="text-destructive text-xs">{errorMessage}</p> : null}+ </DialogPanel>+ <DialogFooter>+ <Button+ type="button"+ variant="outline"+ size="sm"+ onClick={() => onOpenChange(false)}+ disabled={preparePullRequestThreadMutation.isPending}+ >Cancel</Button><Button@@ -252,8 +274,8 @@ export function ComposerPullRequestCommandMenu({>{preparingMode === "worktree" ? "Preparing worktree..." : "Worktree"}</Button>- </div>- </div>- </div>+ </DialogFooter>+ </DialogPopup>+ </Dialog>);}diff --git a/apps/web/src/composer-logic.test.ts b/apps/web/src/composer-logic.test.tsindex ef490f6e9..4e4bd145d 100644--- a/apps/web/src/composer-logic.test.ts+++ b/apps/web/src/composer-logic.test.ts@@ -134,11 +134,11 @@ describe("parseStandaloneComposerSlashCommand", () => {expect(parseStandaloneComposerSlashCommand("/default")).toBe("default");});- it("parses standalone /checkout-pr command", () => {- expect(parseStandaloneComposerSlashCommand(" /checkout-pr ")).toBe("checkout-pr");- });-it("ignores slash commands with extra message text", () => {expect(parseStandaloneComposerSlashCommand("/plan explain this")).toBeNull();});++ it("ignores removed /checkout-pr command", () => {+ expect(parseStandaloneComposerSlashCommand(" /checkout-pr ")).toBeNull();+ });});diff --git a/apps/web/src/composer-logic.ts b/apps/web/src/composer-logic.tsindex cde009708..9bb30132a 100644--- a/apps/web/src/composer-logic.ts+++ b/apps/web/src/composer-logic.ts@@ -1,7 +1,7 @@import { splitPromptIntoComposerSegments } from "./composer-editor-mentions";export type ComposerTriggerKind = "path" | "slash-command" | "slash-model";-export type ComposerSlashCommand = "model" | "plan" | "default" | "checkout-pr";+export type ComposerSlashCommand = "model" | "plan" | "default";export interface ComposerTrigger {kind: ComposerTriggerKind;@@ -14,7 +14,6 @@ const SLASH_COMMANDS: readonly ComposerSlashCommand[] = ["model","plan","default",- "checkout-pr",];function clampCursor(text: string, cursor: number): number {@@ -169,13 +168,12 @@ export function parseStandaloneComposerSlashCommand(text: string): Exclude<ComposerSlashCommand,"model"> | null {- const match = /^\/(plan|default|checkout-pr)\s*$/i.exec(text.trim());+ const match = /^\/(plan|default)\s*$/i.exec(text.trim());if (!match) {return null;}const command = match[1]?.toLowerCase();if (command === "plan") return "plan";- if (command === "checkout-pr") return "checkout-pr";return "default";}