Skip to content

Commit 28abdc5

Browse files
juliusmarmingecodex
andcommitted
Map thread panel into title bar and sidebar
- Add thread-panel presentation logic for inline vs popover layouts - Move thread details controls into the chat header/sidebar flow - Add shared wait-for-atom helper and workspace display name parsing Co-authored-by: codex <[email protected]>
1 parent ef33147 commit 28abdc5

38 files changed

Lines changed: 2573 additions & 2303 deletions

‎apps/mobile/src/state/use-thread-composer-state.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ export function useThreadComposerState() {
133133
return null;
134134
}
135135

136-
return deriveActiveWorkStartedAt(
137-
selectedThread.latestRun,
138-
selectedThreadSessionActivity,
139-
null,
140-
);
136+
return deriveActiveWorkStartedAt(selectedThread.latestRun, selectedThreadSessionActivity, null);
141137
}, [selectedThreadDetail, selectedThreadSessionActivity, selectedThreadShell]);
142138

143139
const activeThreadBusy = !!selectedThread && threadRuntimeIsActive(selectedThread.runtime);

‎apps/web/src/components/BranchToolbar.logic.test.ts‎

Lines changed: 13 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import {
1313
resolveBranchToolbarPrBranch,
1414
resolveBranchToolbarValue,
1515
resolveLockedWorkspaceLabel,
16-
resolveLocalCheckoutBranchMismatch,
17-
resolvePreviousWorktreeLabel,
18-
resolvePreviousWorktreeSeed,
19-
sanitizeNewRefName,
16+
resolveWorkspaceDisplayName,
2017
shouldIncludeBranchPickerItem,
2118
shouldShowComposerContextStrip,
2219
shouldShowEnvironmentIndicator,
@@ -518,6 +515,18 @@ describe("resolveLockedWorkspaceLabel", () => {
518515
});
519516
});
520517

518+
describe("resolveWorkspaceDisplayName", () => {
519+
it("returns the final folder for POSIX and Windows paths", () => {
520+
expect(resolveWorkspaceDisplayName("/repo/.t3/worktrees/feature-a")).toBe("feature-a");
521+
expect(resolveWorkspaceDisplayName("C:\\code\\project\\feature-b\\")).toBe("feature-b");
522+
});
523+
524+
it("handles missing and root paths", () => {
525+
expect(resolveWorkspaceDisplayName(null)).toBeNull();
526+
expect(resolveWorkspaceDisplayName("/")).toBe("/");
527+
});
528+
});
529+
521530
describe("deriveLocalBranchNameFromRemoteRef", () => {
522531
it("strips the remote prefix from a remote ref", () => {
523532
expect(deriveLocalBranchNameFromRemoteRef("origin/feature/demo")).toBe("feature/demo");
@@ -744,93 +753,4 @@ describe("shouldIncludeBranchPickerItem", () => {
744753
}),
745754
).toBe(false);
746755
});
747-
748-
// Typing a spaced name must still surface the ref it would have been created
749-
// as, or the picker shows nothing at all for that query.
750-
it("surfaces an existing ref matching the sanitized query", () => {
751-
expect(
752-
shouldIncludeBranchPickerItem({
753-
itemValue: "new-branch",
754-
normalizedQuery: "new branch",
755-
createBranchItemValue: null,
756-
checkoutPullRequestItemValue: null,
757-
}),
758-
).toBe(true);
759-
});
760-
761-
// A partial query has to reach the ref it would have been created as, so
762-
// searching "hello w" still finds an existing hello-world.
763-
it("surfaces a ref from a partial query containing a space", () => {
764-
expect(
765-
shouldIncludeBranchPickerItem({
766-
itemValue: "hello-world",
767-
normalizedQuery: "hello w",
768-
createBranchItemValue: null,
769-
checkoutPullRequestItemValue: null,
770-
}),
771-
).toBe(true);
772-
});
773-
774-
it("excludes refs matching neither the raw nor the sanitized query", () => {
775-
expect(
776-
shouldIncludeBranchPickerItem({
777-
itemValue: "main",
778-
normalizedQuery: "new branch",
779-
createBranchItemValue: null,
780-
checkoutPullRequestItemValue: null,
781-
}),
782-
).toBe(false);
783-
});
784-
});
785-
786-
// Git rejects ASCII space and the ASCII control characters in ref names, so a
787-
// typed name like "new branch" can only ever fail. Replacing exactly those can
788-
// turn a failing name into a working one without touching a name git already
789-
// accepts, including one holding non-ASCII whitespace such as U+00A0.
790-
describe("sanitizeNewRefName", () => {
791-
it("replaces a space with a dash", () => {
792-
expect(sanitizeNewRefName("new branch")).toBe("new-branch");
793-
});
794-
795-
it("collapses a run of whitespace into a single dash", () => {
796-
expect(sanitizeNewRefName("new branch")).toBe("new-branch");
797-
});
798-
799-
it("trims surrounding whitespace instead of turning it into dashes", () => {
800-
expect(sanitizeNewRefName(" new branch ")).toBe("new-branch");
801-
});
802-
803-
it("replaces tabs, which git rejects just like spaces", () => {
804-
expect(sanitizeNewRefName("new\tbranch")).toBe("new-branch");
805-
});
806-
807-
// git accepts U+00A0, U+2009 and other non-ASCII whitespace in ref names, so
808-
// rewriting them would silently create a ref the user never typed.
809-
it("preserves whitespace that git accepts", () => {
810-
expect(sanitizeNewRefName("new\u00a0branch")).toBe("new\u00a0branch");
811-
expect(sanitizeNewRefName("new\u2009branch")).toBe("new\u2009branch");
812-
});
813-
814-
it("keeps slashes so nested ref names survive", () => {
815-
expect(sanitizeNewRefName("feature/new thing")).toBe("feature/new-thing");
816-
});
817-
818-
it("preserves case because git ref names are case sensitive", () => {
819-
expect(sanitizeNewRefName("Feature/New Thing")).toBe("Feature/New-Thing");
820-
});
821-
822-
it("leaves an already valid ref name untouched", () => {
823-
expect(sanitizeNewRefName("feature/login")).toBe("feature/login");
824-
});
825-
826-
it("returns an empty string for whitespace-only input", () => {
827-
expect(sanitizeNewRefName(" ")).toBe("");
828-
});
829-
830-
// Scoped deliberately to whitespace: git accepts consecutive dashes, so
831-
// collapsing them would rewrite names the user may have typed on purpose.
832-
it("does not collapse dashes the user typed", () => {
833-
expect(sanitizeNewRefName("new - branch")).toBe("new---branch");
834-
expect(sanitizeNewRefName("foo--bar")).toBe("foo--bar");
835-
});
836756
});

‎apps/web/src/components/BranchToolbar.logic.ts‎

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -108,51 +108,11 @@ export function resolveLockedWorkspaceLabel(activeWorktreePath: string | null):
108108
return activeWorktreePath ? "Worktree" : "Local checkout";
109109
}
110110

111-
export interface PreviousWorktreeSeed {
112-
branch: string | null;
113-
worktreePath: string;
114-
}
115-
116-
// The most recently touched worktree in the project that the composer isn't
117-
// already pointing at. Backs the "Previous worktree" entry in the workspace
118-
// selector so a follow-up thread can hop back into the worktree you just
119-
// worked in without hunting for its branch. Archived threads don't compete —
120-
// the rest of the UI hides them, so their worktrees shouldn't resurface here.
121-
export function resolvePreviousWorktreeSeed(input: {
122-
threads: ReadonlyArray<{
123-
branch: string | null;
124-
worktreePath: string | null;
125-
updatedAt: string;
126-
archivedAt?: string | null;
127-
}>;
128-
currentWorktreePath: string | null;
129-
}): PreviousWorktreeSeed | null {
130-
let latest: { branch: string | null; worktreePath: string; updatedAt: number } | null = null;
131-
for (const thread of input.threads) {
132-
if (
133-
!thread.worktreePath ||
134-
thread.worktreePath === input.currentWorktreePath ||
135-
(thread.archivedAt ?? null) !== null
136-
) {
137-
continue;
138-
}
139-
const updatedAt = toSortableTimestamp(thread.updatedAt);
140-
if (updatedAt === null) {
141-
continue;
142-
}
143-
if (latest === null || updatedAt > latest.updatedAt) {
144-
latest = {
145-
branch: thread.branch,
146-
worktreePath: thread.worktreePath,
147-
updatedAt,
148-
};
149-
}
150-
}
151-
return latest === null ? null : { branch: latest.branch, worktreePath: latest.worktreePath };
152-
}
153-
154-
export function resolvePreviousWorktreeLabel(seed: PreviousWorktreeSeed): string {
155-
return seed.branch ? `Previous worktree (${seed.branch})` : "Previous worktree";
111+
export function resolveWorkspaceDisplayName(path: string | null): string | null {
112+
if (!path) return null;
113+
const normalizedPath = path.replace(/[\\/]+$/, "");
114+
if (normalizedPath.length === 0) return path;
115+
return normalizedPath.split(/[\\/]/).at(-1) ?? normalizedPath;
156116
}
157117

158118
export function resolveEffectiveEnvMode(input: {

‎apps/web/src/components/BranchToolbar.tsx‎

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@ import {
77
FolderIcon,
88
ScaleIcon,
99
} from "lucide-react";
10-
import {
11-
type Ref,
12-
memo,
13-
useImperativeHandle,
14-
useCallback,
15-
useEffect,
16-
useLayoutEffect,
17-
useMemo,
18-
useRef,
19-
useState,
20-
} from "react";
10+
import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
2111

2212
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
2313
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
@@ -34,10 +24,7 @@ import {
3424
resolvePreviousWorktreeSeed,
3525
shouldShowEnvironmentIndicator,
3626
} from "./BranchToolbar.logic";
37-
import {
38-
BranchToolbarBranchSelector,
39-
type BranchToolbarBranchSelectorHandle,
40-
} from "./BranchToolbarBranchSelector";
27+
import { BranchToolbarBranchSelector } from "./BranchToolbarBranchSelector";
4128
import { BranchToolbarEnvironmentSelector } from "./BranchToolbarEnvironmentSelector";
4229
import { BranchToolbarEnvModeSelector } from "./BranchToolbarEnvModeSelector";
4330
import { PreviousWorktreeItemContent } from "./PreviousWorktreeItemContent";
@@ -61,14 +48,9 @@ import { measureRestingComposerControls } from "./chat/restingComposerControlsMe
6148
import { resolveRestingComposerControlsNaturalWidth } from "./composerFooterLayout";
6249
import { cn } from "~/lib/utils";
6350

64-
export interface BranchToolbarHandle {
65-
openBranchPicker: () => void;
66-
usePreviousWorktree: () => void;
67-
}
68-
6951
interface BranchToolbarProps {
70-
forceNewWorktree?: boolean;
71-
ref?: Ref<BranchToolbarHandle>;
52+
layout?: "composer" | "panel";
53+
panelSection?: "all" | "workspace" | "branch";
7254
environmentId: EnvironmentId;
7355
threadId: ThreadId;
7456
showGitControls: boolean;
@@ -211,10 +193,6 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
211193
render={<ComposerControl size="xs" />}
212194
className="min-w-0 max-w-[48%] flex-initial justify-start"
213195
data-composer-context-control
214-
data-composer-shortcut={[
215-
showEnvironmentPicker && !envLocked ? "composer.host" : "",
216-
!envModeLocked ? "composer.workspace" : "",
217-
].join(" ")}
218196
>
219197
{triggerContent}
220198
<ChevronDownIcon className="size-3 shrink-0 opacity-50" />
@@ -504,8 +482,8 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
504482
}
505483

506484
export const BranchToolbar = memo(function BranchToolbar({
507-
forceNewWorktree = false,
508-
ref,
485+
layout = "composer",
486+
panelSection = "all",
509487
environmentId,
510488
threadId,
511489
showGitControls,
@@ -526,7 +504,6 @@ export const BranchToolbar = memo(function BranchToolbar({
526504
composerControlsHostRef,
527505
contextStripVisible = true,
528506
}: BranchToolbarProps) {
529-
const branchSelectorRef = useRef<BranchToolbarBranchSelectorHandle>(null);
530507
const threadRef = useMemo(
531508
() => scopeThreadRef(environmentId, threadId),
532509
[environmentId, threadId],
@@ -590,25 +567,6 @@ export const BranchToolbar = memo(function BranchToolbar({
590567
});
591568
}, [activeProjectRef, draftId, previousWorktreeSeed, setDraftThreadContext, threadRef]);
592569

593-
useImperativeHandle(
594-
ref,
595-
() => ({
596-
openBranchPicker: () => branchSelectorRef.current?.open(),
597-
usePreviousWorktree: () => {
598-
if (!showGitControls || !canUsePreviousWorktree || !previousWorktreeSeed) return;
599-
onUsePreviousWorktree();
600-
onComposerFocusRequest?.();
601-
},
602-
}),
603-
[
604-
canUsePreviousWorktree,
605-
onComposerFocusRequest,
606-
onUsePreviousWorktree,
607-
previousWorktreeSeed,
608-
showGitControls,
609-
],
610-
);
611-
612570
const showEnvironmentPicker = Boolean(
613571
availableEnvironments && availableEnvironments.length > 1 && onEnvironmentChange,
614572
);
@@ -623,6 +581,40 @@ export const BranchToolbar = memo(function BranchToolbar({
623581

624582
if (!hasActiveThread || !activeProject) return null;
625583

584+
if (layout === "panel") {
585+
return (
586+
<div className="flex w-full flex-col" data-thread-panel-run-context>
587+
{panelSection !== "branch" ? (
588+
<BranchToolbarEnvModeSelector
589+
displayMode="panel"
590+
envLocked={envModeLocked}
591+
effectiveEnvMode={effectiveEnvMode}
592+
activeWorktreePath={activeWorktreePath}
593+
workspaceRoot={activeProject.workspaceRoot}
594+
onEnvModeChange={onEnvModeChange}
595+
/>
596+
) : null}
597+
{panelSection !== "workspace" ? (
598+
<BranchToolbarBranchSelector
599+
displayMode="panel"
600+
className="w-full"
601+
environmentId={environmentId}
602+
threadId={threadId}
603+
{...(draftId ? { draftId } : {})}
604+
envLocked={envLocked}
605+
{...(effectiveEnvModeOverride ? { effectiveEnvModeOverride } : {})}
606+
{...(activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : {})}
607+
{...(onActiveThreadBranchOverrideChange ? { onActiveThreadBranchOverrideChange } : {})}
608+
startFromOrigin={startFromOrigin}
609+
onStartFromOriginChange={onStartFromOriginChange}
610+
{...(onCheckoutPullRequestRequest ? { onCheckoutPullRequestRequest } : {})}
611+
{...(onComposerFocusRequest ? { onComposerFocusRequest } : {})}
612+
/>
613+
) : null}
614+
</div>
615+
);
616+
}
617+
626618
return (
627619
<ComposerSurface.ContextStrip
628620
ref={setStripElement}
@@ -713,8 +705,6 @@ export const BranchToolbar = memo(function BranchToolbar({
713705

714706
{showGitControls ? (
715707
<BranchToolbarBranchSelector
716-
forceNewWorktree={forceNewWorktree}
717-
ref={branchSelectorRef}
718708
className="min-w-0 flex-initial justify-end @3xl/composer-surface:ml-auto"
719709
environmentId={environmentId}
720710
threadId={threadId}

0 commit comments

Comments
 (0)