Add JJ VCS driver support
- Detect and route jj repositories alongside git - Thread VCS kind through status and UI labels - Add jj driver contract coverage and shared freshness helper
This commit is contained in:
1 parent
128b432bee
commit
c31becadc7
30 files changed
+838
-44
No files matched your search
@@ -23,6 +23,7 @@ import { cn } from "../lib/utils";
|
||||
import { parsePullRequestReference } from "../pullRequestReference";
|
||||
import { useStore } from "../store";
|
||||
import { createProjectSelectorByRef, createThreadSelectorByRef } from "../storeSelectors";
|
||||
import { resolveVcsTerms } from "../vcsPresentation";
|
||||
import {
|
||||
deriveLocalBranchNameFromRemoteRef,
|
||||
resolveBranchSelectionTarget,
|
||||
@@ -66,10 +67,11 @@ function getBranchTriggerLabel(input: {
|
||||
activeWorktreePath: string | null;
|
||||
effectiveEnvMode: "local" | "worktree";
|
||||
resolvedActiveBranch: string | null;
|
||||
refNoun: string;
|
||||
}): string {
|
||||
const { activeWorktreePath, effectiveEnvMode, resolvedActiveBranch } = input;
|
||||
const { activeWorktreePath, effectiveEnvMode, resolvedActiveBranch, refNoun } = input;
|
||||
if (!resolvedActiveBranch) {
|
||||
return "Select ref";
|
||||
return `Select ${refNoun}`;
|
||||
}
|
||||
if (effectiveEnvMode === "worktree" && !activeWorktreePath) {
|
||||
return `From ${resolvedActiveBranch}`;
|
||||
@@ -201,6 +203,7 @@ export function BranchToolbarBranchSelector({
|
||||
const deferredBranchQuery = useDeferredValue(branchQuery);
|
||||
|
||||
const branchStatusQuery = useGitStatus({ environmentId, cwd: branchCwd });
|
||||
const vcsTerms = resolveVcsTerms(branchStatusQuery.data?.kind);
|
||||
const trimmedBranchQuery = branchQuery.trim();
|
||||
const deferredTrimmedBranchQuery = deferredBranchQuery.trim();
|
||||
|
||||
@@ -289,11 +292,11 @@ export function BranchToolbarBranchSelector({
|
||||
const shouldVirtualizeBranchList = filteredBranchPickerItems.length > 40;
|
||||
const totalBranchCount = branchesSearchData?.pages[0]?.totalCount ?? 0;
|
||||
const branchStatusText = isBranchesSearchPending
|
||||
? "Loading refs..."
|
||||
? `Loading ${vcsTerms.refNounPlural}...`
|
||||
: isFetchingNextPage
|
||||
? "Loading more refs..."
|
||||
? `Loading more ${vcsTerms.refNounPlural}...`
|
||||
: hasNextPage
|
||||
? `Showing ${refs.length} of ${totalBranchCount} refs`
|
||||
? `Showing ${refs.length} of ${totalBranchCount} ${vcsTerms.refNounPlural}`
|
||||
: null;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -357,7 +360,7 @@ export function BranchToolbarBranchSelector({
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to switch ref.",
|
||||
title: `Failed to switch ${vcsTerms.refNoun}.`,
|
||||
description: toBranchActionErrorMessage(error),
|
||||
}),
|
||||
);
|
||||
@@ -389,7 +392,7 @@ export function BranchToolbarBranchSelector({
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to create and switch ref.",
|
||||
title: `Failed to create and switch ${vcsTerms.refNoun}.`,
|
||||
description: toBranchActionErrorMessage(error),
|
||||
}),
|
||||
);
|
||||
@@ -488,6 +491,7 @@ export function BranchToolbarBranchSelector({
|
||||
activeWorktreePath,
|
||||
effectiveEnvMode,
|
||||
resolvedActiveBranch,
|
||||
refNoun: vcsTerms.refNoun,
|
||||
});
|
||||
|
||||
function renderPickerItem(itemValue: string, index: number) {
|
||||
@@ -524,7 +528,9 @@ export function BranchToolbarBranchSelector({
|
||||
value={itemValue}
|
||||
onClick={() => createRef(trimmedBranchQuery)}
|
||||
>
|
||||
<span className="truncate">Create new ref "{trimmedBranchQuery}"</span>
|
||||
<span className="truncate">
|
||||
Create new {vcsTerms.refNoun} "{trimmedBranchQuery}"
|
||||
</span>
|
||||
</ComboboxItem>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1458,7 +1458,8 @@ export default function ChatView(props: ChatViewProps) {
|
||||
? terminalLaunchContext
|
||||
: (storeServerTerminalLaunchContext ?? null);
|
||||
// Default true while loading to avoid toolbar flicker.
|
||||
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
|
||||
const vcsKind = gitStatusQuery.data?.kind ?? null;
|
||||
const isVcsRepo = gitStatusQuery.data?.isRepo ?? true;
|
||||
const terminalShortcutLabelOptions = useMemo(
|
||||
() => ({
|
||||
context: {
|
||||
@@ -2136,7 +2137,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
: (activeThread?.branch ?? null);
|
||||
const sendEnvMode = resolveSendEnvMode({
|
||||
requestedEnvMode: envMode,
|
||||
isGitRepo,
|
||||
isGitRepo: isVcsRepo,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
@@ -3297,7 +3298,8 @@ export default function ChatView(props: ChatViewProps) {
|
||||
{...(routeKind === "draft" && draftId ? { draftId } : {})}
|
||||
activeThreadTitle={activeThread.title}
|
||||
activeProjectName={activeProject?.name}
|
||||
isGitRepo={isGitRepo}
|
||||
isVcsRepo={isVcsRepo}
|
||||
vcsKind={vcsKind}
|
||||
openInCwd={gitCwd}
|
||||
activeProjectScripts={activeProject?.scripts}
|
||||
preferredScriptId={
|
||||
@@ -3377,7 +3379,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
<div
|
||||
className={cn(
|
||||
"pl-[calc(env(safe-area-inset-left)+0.75rem)] pr-[calc(env(safe-area-inset-right)+0.75rem)] pt-1.5 sm:pl-[calc(env(safe-area-inset-left)+1.25rem)] sm:pr-[calc(env(safe-area-inset-right)+1.25rem)] sm:pt-2",
|
||||
isGitRepo
|
||||
isVcsRepo
|
||||
? "pb-[calc(env(safe-area-inset-bottom)+0.25rem)]"
|
||||
: "pb-[calc(env(safe-area-inset-bottom)+0.75rem)] sm:pb-[calc(env(safe-area-inset-bottom)+1rem)]",
|
||||
)}
|
||||
@@ -3450,7 +3452,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
setThreadError={setThreadError}
|
||||
onExpandImage={onExpandTimelineImage}
|
||||
/>
|
||||
{isGitRepo && (
|
||||
{isVcsRepo && (
|
||||
<BranchToolbar
|
||||
environmentId={activeThread.environmentId}
|
||||
threadId={activeThread.id}
|
||||
|
||||
@@ -35,6 +35,7 @@ import { createThreadSelectorByRef } from "../storeSelectors";
|
||||
import { buildThreadRouteParams, resolveThreadRouteRef } from "../threadRoutes";
|
||||
import { useSettings } from "../hooks/useSettings";
|
||||
import { formatShortTimestamp } from "../timestampFormat";
|
||||
import { resolveVcsTerms } from "../vcsPresentation";
|
||||
import { DiffPanelLoadingState, DiffPanelShell, type DiffPanelMode } from "./DiffPanelShell";
|
||||
import { ToggleGroup, Toggle } from "./ui/toggle-group";
|
||||
|
||||
@@ -201,7 +202,8 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
||||
environmentId: activeThread?.environmentId ?? null,
|
||||
cwd: activeCwd ?? null,
|
||||
});
|
||||
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
|
||||
const isVcsRepo = gitStatusQuery.data?.isRepo ?? true;
|
||||
const vcsTerms = resolveVcsTerms(gitStatusQuery.data?.kind);
|
||||
const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
|
||||
useTurnDiffSummaries(activeThread);
|
||||
const orderedTurnDiffSummaries = useMemo(
|
||||
@@ -278,7 +280,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
||||
fromTurnCount: activeCheckpointRange?.fromTurnCount ?? null,
|
||||
toTurnCount: activeCheckpointRange?.toTurnCount ?? null,
|
||||
cacheScope: selectedTurn ? `turn:${selectedTurn.turnId}` : conversationCacheScope,
|
||||
enabled: isGitRepo,
|
||||
enabled: isVcsRepo,
|
||||
}),
|
||||
);
|
||||
const selectedTurnCheckpointDiff = selectedTurn
|
||||
@@ -561,9 +563,9 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
||||
<div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
|
||||
Select a thread to inspect turn diffs.
|
||||
</div>
|
||||
) : !isGitRepo ? (
|
||||
) : !isVcsRepo ? (
|
||||
<div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
|
||||
Turn diffs are unavailable because this project is not a git repository.
|
||||
Turn diffs are unavailable because this project is not a {vcsTerms.repositoryNoun}.
|
||||
</div>
|
||||
) : orderedTurnDiffSummaries.length === 0 ? (
|
||||
<div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
|
||||
|
||||
@@ -113,6 +113,7 @@ vi.mock("~/lib/gitStatusState", () => ({
|
||||
resetGitStatusStateForTests: () => undefined,
|
||||
useGitStatus: vi.fn(() => ({
|
||||
data: {
|
||||
kind: "git",
|
||||
isRepo: true,
|
||||
sourceControlProvider: {
|
||||
kind: "github",
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
|
||||
function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
|
||||
return {
|
||||
kind: "git",
|
||||
isRepo: true,
|
||||
hasPrimaryRemote: true,
|
||||
isDefaultRef: false,
|
||||
|
||||
@@ -54,6 +54,7 @@ import { readEnvironmentApi } from "~/environmentApi";
|
||||
import { readLocalApi } from "~/localApi";
|
||||
import { useStore } from "~/store";
|
||||
import { createThreadSelectorByRef } from "~/storeSelectors";
|
||||
import { resolveVcsActionPresentation, resolveVcsTerms } from "~/vcsPresentation";
|
||||
|
||||
interface GitActionsControlProps {
|
||||
gitCwd: string | null;
|
||||
@@ -324,8 +325,12 @@ export default function GitActionsControl({
|
||||
});
|
||||
// Default to true while loading so we don't flash init controls.
|
||||
const isRepo = gitStatus?.isRepo ?? true;
|
||||
const vcsKind = gitStatus?.kind ?? null;
|
||||
const vcsTerms = resolveVcsTerms(vcsKind);
|
||||
const vcsActionPresentation = resolveVcsActionPresentation(vcsKind);
|
||||
const supportsGitWorkflowActions = !isRepo || vcsActionPresentation.supportsGitWorkflowActions;
|
||||
const hasPrimaryRemote = gitStatus?.hasPrimaryRemote ?? false;
|
||||
const gitStatusForActions = gitStatus;
|
||||
const gitStatusForActions = supportsGitWorkflowActions ? gitStatus : null;
|
||||
|
||||
const allFiles = gitStatusForActions?.workingTree.files ?? [];
|
||||
const selectedFiles = allFiles.filter((f) => !excludedFiles.has(f.path));
|
||||
@@ -874,6 +879,25 @@ export default function GitActionsControl({
|
||||
>
|
||||
{initMutation.isPending ? "Initializing..." : "Initialize Git"}
|
||||
</Button>
|
||||
) : !supportsGitWorkflowActions ? (
|
||||
<Popover>
|
||||
<PopoverTrigger
|
||||
openOnHover
|
||||
render={
|
||||
<Button
|
||||
aria-disabled="true"
|
||||
className="cursor-not-allowed opacity-70"
|
||||
size="xs"
|
||||
variant="outline"
|
||||
/>
|
||||
}
|
||||
>
|
||||
{vcsTerms.systemName} {vcsTerms.repositoryNoun}
|
||||
</PopoverTrigger>
|
||||
<PopoverPopup tooltipStyle side="bottom" align="end">
|
||||
{vcsActionPresentation.unsupportedGitWorkflowDescription}
|
||||
</PopoverPopup>
|
||||
</Popover>
|
||||
) : (
|
||||
<Group aria-label="Git actions" className="shrink-0">
|
||||
{quickActionDisabledReason ? (
|
||||
|
||||
@@ -17,6 +17,8 @@ import { Toggle } from "../ui/toggle";
|
||||
import { SidebarTrigger } from "../ui/sidebar";
|
||||
import { OpenInPicker } from "./OpenInPicker";
|
||||
import { usePrimaryEnvironmentId } from "../../environments/primary";
|
||||
import { resolveVcsTerms } from "../../vcsPresentation";
|
||||
import type { VcsDriverKind } from "@t3tools/contracts";
|
||||
|
||||
interface ChatHeaderProps {
|
||||
activeThreadEnvironmentId: EnvironmentId;
|
||||
@@ -24,7 +26,8 @@ interface ChatHeaderProps {
|
||||
draftId?: DraftId;
|
||||
activeThreadTitle: string;
|
||||
activeProjectName: string | undefined;
|
||||
isGitRepo: boolean;
|
||||
isVcsRepo: boolean;
|
||||
vcsKind: VcsDriverKind | null;
|
||||
openInCwd: string | null;
|
||||
activeProjectScripts: ProjectScript[] | undefined;
|
||||
preferredScriptId: string | null;
|
||||
@@ -50,7 +53,8 @@ export const ChatHeader = memo(function ChatHeader({
|
||||
draftId,
|
||||
activeThreadTitle,
|
||||
activeProjectName,
|
||||
isGitRepo,
|
||||
isVcsRepo,
|
||||
vcsKind,
|
||||
openInCwd,
|
||||
activeProjectScripts,
|
||||
preferredScriptId,
|
||||
@@ -72,6 +76,7 @@ export const ChatHeader = memo(function ChatHeader({
|
||||
const primaryEnvironmentId = usePrimaryEnvironmentId();
|
||||
const isRemoteEnvironment =
|
||||
primaryEnvironmentId !== null && activeThreadEnvironmentId !== primaryEnvironmentId;
|
||||
const vcsTerms = resolveVcsTerms(vcsKind);
|
||||
|
||||
return (
|
||||
<div className="@container/header-actions flex min-w-0 flex-1 items-center gap-2">
|
||||
@@ -88,9 +93,9 @@ export const ChatHeader = memo(function ChatHeader({
|
||||
<span className="min-w-0 truncate">{activeProjectName}</span>
|
||||
</Badge>
|
||||
)}
|
||||
{activeProjectName && !isGitRepo && (
|
||||
{activeProjectName && !isVcsRepo && (
|
||||
<Badge variant="outline" className="shrink-0 text-[10px] text-amber-700">
|
||||
No Git
|
||||
No repository
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
@@ -154,15 +159,15 @@ export const ChatHeader = memo(function ChatHeader({
|
||||
aria-label="Toggle diff panel"
|
||||
variant="outline"
|
||||
size="xs"
|
||||
disabled={!isGitRepo && !diffOpen}
|
||||
disabled={!isVcsRepo && !diffOpen}
|
||||
>
|
||||
<DiffIcon className="size-3" />
|
||||
</Toggle>
|
||||
}
|
||||
/>
|
||||
<TooltipPopup side="bottom">
|
||||
{!isGitRepo && !diffOpen
|
||||
? "Diff panel is unavailable because this project is not a git repository."
|
||||
{!isVcsRepo && !diffOpen
|
||||
? `Diff panel is unavailable because this project is not a supported ${vcsTerms.repositoryNoun}.`
|
||||
: diffToggleShortcutLabel
|
||||
? `Toggle diff panel (${diffToggleShortcutLabel})`
|
||||
: "Toggle diff panel"}
|
||||
|
||||
@@ -40,6 +40,7 @@ const TARGET = { environmentId: ENVIRONMENT_ID, cwd: "/repo" } as const;
|
||||
const FRESH_TARGET = { environmentId: ENVIRONMENT_ID, cwd: "/fresh" } as const;
|
||||
|
||||
const BASE_STATUS: VcsStatusResult = {
|
||||
kind: "git",
|
||||
isRepo: true,
|
||||
hasPrimaryRemote: true,
|
||||
isDefaultRef: false,
|
||||
|
||||
@@ -64,7 +64,7 @@ function normalizeCheckpointErrorMessage(error: unknown): string {
|
||||
|
||||
const lower = message.toLowerCase();
|
||||
if (lower.includes("not a git repository")) {
|
||||
return "Turn diffs are unavailable because this project is not a git repository.";
|
||||
return "Turn diffs are unavailable because this project is not a repository.";
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -262,6 +262,7 @@ const baseServerConfig: ServerConfig = {
|
||||
};
|
||||
|
||||
const baseGitStatus: VcsStatusResult = {
|
||||
kind: "git",
|
||||
isRepo: true,
|
||||
hasPrimaryRemote: true,
|
||||
isDefaultRef: false,
|
||||
|
||||
@@ -19,6 +19,7 @@ import { createWsRpcClient } from "./wsRpcClient";
|
||||
import { type WsTransport } from "./wsTransport";
|
||||
|
||||
const baseLocalStatus: VcsStatusLocalResult = {
|
||||
kind: "git",
|
||||
isRepo: true,
|
||||
hasPrimaryRemote: true,
|
||||
isDefaultRef: false,
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import type { VcsDriverKind } from "@t3tools/contracts";
|
||||
|
||||
export interface VcsTerms {
|
||||
readonly systemName: string;
|
||||
readonly repositoryNoun: string;
|
||||
readonly refNoun: string;
|
||||
readonly refNounPlural: string;
|
||||
readonly currentRefFallback: string;
|
||||
}
|
||||
|
||||
export interface VcsActionPresentation {
|
||||
readonly supportsGitWorkflowActions: boolean;
|
||||
readonly unsupportedGitWorkflowDescription: string;
|
||||
}
|
||||
|
||||
const gitLikeTerms: VcsTerms = {
|
||||
systemName: "Git",
|
||||
repositoryNoun: "repository",
|
||||
refNoun: "branch",
|
||||
refNounPlural: "branches",
|
||||
currentRefFallback: "checkout",
|
||||
};
|
||||
|
||||
const unknownTerms: VcsTerms = {
|
||||
systemName: "VCS",
|
||||
repositoryNoun: "repository",
|
||||
refNoun: "ref",
|
||||
refNounPlural: "refs",
|
||||
currentRefFallback: "checkout",
|
||||
};
|
||||
|
||||
export function resolveVcsTerms(kind: VcsDriverKind | null | undefined): VcsTerms {
|
||||
if (kind === "jj") {
|
||||
return {
|
||||
systemName: "JJ",
|
||||
repositoryNoun: "workspace",
|
||||
refNoun: "bookmark",
|
||||
refNounPlural: "bookmarks",
|
||||
currentRefFallback: "working copy",
|
||||
};
|
||||
}
|
||||
|
||||
if (kind === "sapling") {
|
||||
return {
|
||||
...gitLikeTerms,
|
||||
systemName: "Sapling",
|
||||
};
|
||||
}
|
||||
|
||||
if (kind === "git") {
|
||||
return gitLikeTerms;
|
||||
}
|
||||
|
||||
return unknownTerms;
|
||||
}
|
||||
|
||||
export function resolveVcsActionPresentation(
|
||||
kind: VcsDriverKind | null | undefined,
|
||||
): VcsActionPresentation {
|
||||
const terms = resolveVcsTerms(kind);
|
||||
const supportsGitWorkflowActions = kind === undefined || kind === null || kind === "git";
|
||||
|
||||
return {
|
||||
supportsGitWorkflowActions,
|
||||
unsupportedGitWorkflowDescription: `Git commit, push, and PR actions are not available for this ${terms.systemName} ${terms.repositoryNoun}.`,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user