Open History to see the last commit
1import type {
2 EditorId,
3 EnvironmentId,
4 ProjectScript,
5 ResolvedKeybindingsConfig,
6 ThreadId,
7} from "@t3tools/contracts";
8import { AlertTriangleIcon, XIcon } from "lucide-react";
9
10import type { DraftId } from "../../composerDraftStore";
11import { useT3ProjectFileScripts } from "../../hooks/useT3ProjectFileScripts";
12import {
13 shouldShowEnvironmentIndicator,
14 type EnvMode,
15 type EnvironmentOption,
16} from "../BranchToolbar.logic";
17import { BranchToolbar } from "../BranchToolbar";
18import { BranchToolbarEnvironmentSelector } from "../BranchToolbarEnvironmentSelector";
19import GitActionsControl from "../GitActionsControl";
20import ProjectScriptsControl, {
21 type NewProjectScriptInput,
22 type ProjectScriptActionResult,
23} from "../ProjectScriptsControl";
24import { Button } from "../ui/button";
25import type { ComponentProps } from "react";
26import { ThreadDetailsCard } from "./ThreadDetailsCard";
27import { OpenInPicker } from "./OpenInPicker";
28import { ThreadDetailsSection } from "./ThreadDetailsSection";
29import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel";
30import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
31import { ThreadWorkflowsPanel } from "./ThreadWorkflowsPanel";
32
33interface VersionMismatchIssue {
34 readonly clientVersion: string;
35 readonly serverVersion: string;
36 readonly serverLabel: string;
37}
38
39export interface ThreadDetailsPanelProps extends Pick<
40 ComponentProps<typeof ThreadDetailsCard>,
41 "anchor" | "handle" | "onPresentationChange"
42> {
43 forceNewWorktree?: boolean;
44 environmentId: EnvironmentId;
45 threadId: ThreadId;
46 draftId?: DraftId;
47 activeProjectName: string | undefined;
48 activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;
49 preferredScriptId: string | null;
50 keybindings: ResolvedKeybindingsConfig;
51 availableEditors: ReadonlyArray<EditorId>;
52 showOpenInPicker: boolean;
53 gitCwd: string | null;
54 isGitRepo: boolean;
55 envLocked: boolean;
56 availableEnvironments: readonly EnvironmentOption[];
57 autoEnvironmentLabel?: string | undefined;
58 onAutoEnvironment?: (() => void) | undefined;
59 onEnvironmentChange: (environmentId: EnvironmentId) => void;
60 onEnvModeChange: (mode: EnvMode) => void;
61 /** The thread's env mode as ChatView resolves it. */
62 envMode: EnvMode;
63 activeThreadBranchOverride?: string | null;
64 onActiveThreadBranchOverrideChange?: (branch: string | null) => void;
65 startFromOrigin: boolean;
66 onStartFromOriginChange: (startFromOrigin: boolean) => void;
67 onCheckoutPullRequestRequest?: (reference: string) => void;
68 onComposerFocusRequest: () => void;
69 onOpenChanges?: () => void;
70 versionMismatch: VersionMismatchIssue | null;
71 onDismissVersionMismatch: () => void;
72 onRunProjectScript: (script: ProjectScript) => void;
73 onAddProjectScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
74 onUpdateProjectScript: (
75 scriptId: string,
76 input: NewProjectScriptInput,
77 ) => Promise<ProjectScriptActionResult>;
78 onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
79}
80
81export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
82 const fileScripts = useT3ProjectFileScripts(
83 props.environmentId,
84 props.activeProjectScripts ? props.gitCwd : null,
85 );
86 // Same rule as the composer strip: a lone remote machine still gets a row,
87 // shown as a static label because there is nothing to pick.
88 const canPickEnvironment = props.availableEnvironments.length > 1;
89 const showEnvironment = shouldShowEnvironmentIndicator({
90 activeEnvironment:
91 props.availableEnvironments.find((env) => env.environmentId === props.environmentId) ?? null,
92 canPickEnvironment,
93 });
94 const branchToolbarProps = {
95 showGitControls: props.isGitRepo,
96 environmentId: props.environmentId,
97 threadId: props.threadId,
98 ...(props.draftId ? { draftId: props.draftId } : {}),
99 onEnvModeChange: props.onEnvModeChange,
100 startFromOrigin: props.startFromOrigin,
101 onStartFromOriginChange: props.onStartFromOriginChange,
102 envMode: props.envMode,
103 ...(props.activeThreadBranchOverride !== undefined
104 ? { activeThreadBranchOverride: props.activeThreadBranchOverride }
105 : {}),
106 ...(props.onActiveThreadBranchOverrideChange
107 ? { onActiveThreadBranchOverrideChange: props.onActiveThreadBranchOverrideChange }
108 : {}),
109 envLocked: props.envLocked,
110 forceNewWorktree: props.forceNewWorktree ?? false,
111 onComposerFocusRequest: props.onComposerFocusRequest,
112 ...(props.onCheckoutPullRequestRequest
113 ? { onCheckoutPullRequestRequest: props.onCheckoutPullRequestRequest }
114 : {}),
115 };
116
117 return (
118 <ThreadDetailsCard
119 threadRef={{ environmentId: props.environmentId, threadId: props.threadId }}
120 anchor={props.anchor}
121 handle={props.handle}
122 onPresentationChange={props.onPresentationChange}
123 >
124 {(density) => (
125 <>
126 <ThreadDetailsSection
127 headingId="thread-details-workspace-heading"
128 title="Workspace"
129 separated={false}
130 showHeading={false}
131 >
132 {props.versionMismatch ? (
133 <div className="mx-1 mb-2 flex gap-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
134 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
135 <div className="min-w-0 flex-1">
136 <p className="text-xs font-medium">Client and server versions differ</p>
137 <p className="mt-1 text-2xs leading-relaxed text-muted-foreground">
138 Client {props.versionMismatch.clientVersion} ·{" "}
139 {props.versionMismatch.serverLabel} {props.versionMismatch.serverVersion}
140 </p>
141 </div>
142 <Button
143 size="icon-xs"
144 variant="ghost"
145 aria-label="Dismiss version mismatch warning"
146 onClick={props.onDismissVersionMismatch}
147 >
148 <XIcon className="size-3.5" />
149 </Button>
150 </div>
151 ) : null}
152
153 <div className="flex flex-col">
154 {density === "full" && showEnvironment ? (
155 <BranchToolbarEnvironmentSelector
156 displayMode="panel"
157 autoEnvironmentLabel={props.autoEnvironmentLabel}
158 onAutoEnvironment={props.onAutoEnvironment}
159 envLocked={props.envLocked}
160 environmentId={props.environmentId}
161 availableEnvironments={props.availableEnvironments}
162 {...(canPickEnvironment
163 ? { onEnvironmentChange: props.onEnvironmentChange }
164 : {})}
165 />
166 ) : null}
167
168 {density === "full" ? (
169 <BranchToolbar layout="panel" panelSection="workspace" {...branchToolbarProps} />
170 ) : null}
171
172 {density !== "essential" && props.showOpenInPicker ? (
173 <OpenInPicker
174 keybindings={props.keybindings}
175 environmentId={props.environmentId}
176 availableEditors={props.availableEditors}
177 openInCwd={props.gitCwd}
178 displayMode="panel"
179 />
180 ) : null}
181
182 {props.activeProjectScripts ? (
183 <ProjectScriptsControl
184 environmentId={props.environmentId}
185 displayMode="panel"
186 scripts={props.activeProjectScripts}
187 fileScripts={fileScripts}
188 preferredScriptId={props.preferredScriptId}
189 onRunScript={props.onRunProjectScript}
190 onAddScript={props.onAddProjectScript}
191 onUpdateScript={props.onUpdateProjectScript}
192 onDeleteScript={props.onDeleteProjectScript}
193 />
194 ) : null}
195 </div>
196 </ThreadDetailsSection>
197
198 {props.gitCwd ? (
199 <ThreadDetailsSection
200 headingId="thread-details-version-control-heading"
201 title="Version Control"
202 showHeading={false}
203 separated={density === "full"}
204 >
205 <div className="flex flex-col">
206 {props.isGitRepo ? (
207 <BranchToolbar layout="panel" panelSection="branch" {...branchToolbarProps} />
208 ) : null}
209 {props.activeProjectName ? (
210 <GitActionsControl
211 displayMode="panel"
212 compact={density !== "full"}
213 gitCwd={props.gitCwd}
214 activeThreadRef={{
215 environmentId: props.environmentId,
216 threadId: props.threadId,
217 }}
218 {...(props.draftId ? { draftId: props.draftId } : {})}
219 {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}
220 />
221 ) : null}
222 </div>
223 </ThreadDetailsSection>
224 ) : null}
225
226 {density === "full" && !props.draftId ? (
227 <ThreadAutomationsPanel environmentId={props.environmentId} threadId={props.threadId} />
228 ) : null}
229
230 {density === "full" && !props.draftId ? (
231 <ThreadRelationshipsPanel
232 environmentId={props.environmentId}
233 threadId={props.threadId}
234 />
235 ) : null}
236
237 {density === "full" && !props.draftId ? (
238 <ThreadWorkflowsPanel environmentId={props.environmentId} threadId={props.threadId} />
239 ) : null}
240 </>
241 )}
242 </ThreadDetailsCard>
243 );
244}