Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { usePullRequestCheckoutState } from "./pullRequest/pullRequestCheckoutState";
import { ChildThreadApprovals } from "./chat/ChildThreadApprovals";
import { workspaceAreaProps } from "../lib/workspaceFocus";
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
Expand Down Expand Up @@ -477,6 +478,9 @@ export default function ChatView(props: ChatViewProps) {
? store.getDraftSession(draftId)
: null,
);
const isPreparingPullRequestCheckout = usePullRequestCheckoutState(
(state) => draftId !== null && state.draftIds.has(draftId),
);
const serverThreadShell = useQuietThreadShell(routeThreadRef);
const routeThreadDetailRef = resolveThreadDetailRef(routeThreadRef, {
shellExists: serverThreadShell !== null,
Expand Down Expand Up @@ -3598,6 +3602,7 @@ export default function ChatView(props: ChatViewProps) {
canSteer={!compactionBlocksSteer}
canInterrupt={canInterruptRunningThread}
isSendBusy={
isPreparingPullRequestCheckout ||
(isSendBusy && !sendQueuesBehindSetup) ||
(setupQueueSendThreadKey !== null &&
setupQueueSendThreadKey === activeThreadKey) ||
Expand All @@ -3607,19 +3612,21 @@ export default function ChatView(props: ChatViewProps) {
canResume={resumableRunId !== null || hasHeldQueuedRuns}
isRevertingCheckpoint={isRevertingCheckpoint}
sendDisabledReason={
!canOperateThread
? "This connection cannot change threads."
: isEnvironmentChanging
? "Preparing machine"
: isRevertingCheckpoint
? "Rewinding conversation"
: feedbackUploading
? "Sending feedback"
: threadDetailLoading
? "Messages loading"
: worktreeSetupBlocksSend
? "Preparing worktree"
: projectCloneSendBlockReason
isPreparingPullRequestCheckout
? "Preparing pull request checkout"
: !canOperateThread
? "This connection cannot change threads."
: isEnvironmentChanging
? "Preparing machine"
: isRevertingCheckpoint
? "Rewinding conversation"
: feedbackUploading
? "Sending feedback"
: threadDetailLoading
? "Messages loading"
: worktreeSetupBlocksSend
? "Preparing worktree"
: projectCloneSendBlockReason
}
isPreparingWorktree={isPreparingWorktree && !sendQueuesBehindSetup}
bannerItems={
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/chat/useComposerSend.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { usePullRequestCheckoutState } from "../pullRequest/pullRequestCheckoutState";
import { isClearComposerCommand, parseSideChatCommand } from "@t3tools/shared/composerTrigger";
import { armFreshSession, disarmFreshSession, readFreshSessionArm } from "./freshSessionArms";
import {
Expand Down Expand Up @@ -425,6 +426,7 @@ export function useComposerSend(input: ComposerSendInput) {
);
};
if (
(draftId !== null && usePullRequestCheckoutState.getState().draftIds.has(draftId)) ||
!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope) ||
!activeThread ||
(isSendBusy && !sendQueuesBehindSetup) ||
Expand Down
121 changes: 29 additions & 92 deletions apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { normalizeThreadPullRequestKey } from "@t3tools/client-runtime/thread-pu
import { useAtomValue } from "@effect/atom-react";
import { usePullRequestStack } from "~/state/usePullRequestStack";
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
import {
isAtomCommandInterrupted,
squashAtomCommandFailure,
} from "@t3tools/client-runtime/state/runtime";
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
import {
AuthOrchestrationOperateScope,
AuthSourceControlWriteScope,
Expand Down Expand Up @@ -56,10 +53,10 @@ import { isCommandPaletteOpen } from "~/commandPaletteBus";
import { resolveShortcutCommand, type ShortcutMatchContext } from "~/keybindings";
import { primaryServerKeybindingsAtom } from "~/state/server";
import {
runPullRequestCheckoutHandoff,
usePullRequestDefaultMergeMethodResolver,
writeHandoffToComposer,
} from "./usePullRequestActions";
import { offHeadPullRequestCheckoutToast } from "./pullRequestCheckoutToast";
import { usePreparePullRequestThreadAction } from "~/state/sourceControlActions";
import { cn } from "~/lib/utils";
import { readLocalApi } from "~/localApi";
Expand Down Expand Up @@ -137,7 +134,6 @@ import {
pullRequestFindingKey,
pullRequestHandoffLabels,
PULL_REQUEST_MERGE_METHOD_LABELS,
checkoutFailureDescription,
readableFailure,
resolvePullRequestReferenceHost,
resolvePullRequestPrimaryControl,
Expand Down Expand Up @@ -971,99 +967,40 @@ export function PullRequestDetailPanel({
return;
}
setHandoff(kind);
const toastId = toastManager.add({
type: "loading",
title: `Preparing the ${terminology.singular} checkout...`,
});
const projectRef = scopeProjectRef(
actingEnvironmentId,
acting?.projectId ?? handoffSummary.projectId,
);
// Checkout setup requires the thread to exist first.
const opened = await newThread(projectRef).then(
(session) => session,
() => null,
);
if (opened === null) {
setHandoff(null);
toastManager.update(toastId, {
type: "error",
title: "Could not open a thread for the checkout",
description: "Try again from the project, or open a thread first.",
});
return;
}
const prepared = await prepareThread.run({
reference: handoffSummary.url,
await runPullRequestCheckoutHandoff({
terminology,
mode,
threadId: opened.threadId,
});
if (prepared._tag === "Failure") {
setHandoff(null);
toastManager.update(toastId, {
type: "error",
title: `Could not prepare the ${terminology.singular} checkout`,
description: checkoutFailureDescription(
isAtomCommandInterrupted(prepared) ? undefined : squashAtomCommandFailure(prepared),
task,
clearHandoff: () => setHandoff(null),
// Checkout setup requires the thread to exist first.
openThread: () =>
newThread(projectRef).then(
(session) => session,
() => null,
),
});
return;
}
const pointed = await newThread(projectRef, {
branch: prepared.value.branch,
worktreePath: prepared.value.worktreePath,
envMode: prepared.value.worktreePath === null ? "local" : "worktree",
}).then(
(session) => session,
() => null,
);
if (pointed === null) {
setHandoff(null);
// Sending after failed rebinding would use the previous checkout.
toastManager.update(toastId, {
type: "error",
title: "Checked out, but the thread stayed where it was",
description: `The checkout is ready on \`${prepared.value.branch}\`. Point a thread at it from the branch picker, then ask again.`,
});
return;
}
// The draft carries the pull request until its first send makes it a thread, which links it.
useComposerDraftStore.getState().setDraftThreadContext(pointed.draftId, {
checkoutPullRequest: {
url: prepared.value.pullRequest.url,
branch: prepared.value.branch,
},
prepare: (threadId) =>
prepareThread.run({
reference: handoffSummary.url,
mode,
threadId,
}),
// Rebind the opened draft: newThread would open a second empty draft once the prompt is seeded.
pointThread: async (prepared, opened) =>
useComposerDraftStore.getState().setDraftThreadContext(opened.draftId, {
branch: prepared.branch,
worktreePath: prepared.worktreePath,
envMode: prepared.worktreePath === null ? "local" : "worktree",
// Draft carries the PR until its first send makes it a thread, which links it.
checkoutPullRequest: {
url: prepared.pullRequest.url,
branch: prepared.branch,
},
}),
});
setHandoff(null);
if (task === null) {
toastManager.update(
toastId,
prepared.value.isOnPullRequestHead
? {
type: "success",
title: mode === "local" ? "Checked out here" : "Checked out",
description:
mode === "local"
? `This repository is on the ${terminology.singular}'s branch, with a thread open on it.`
: `The ${terminology.singular} is in its own worktree, with a thread open on it.`,
}
: offHeadPullRequestCheckoutToast(terminology),
);
return;
}
// The task goes on the checkout draft: if the user typed into `opened` while the
// checkout ran, that is no longer the draft the user is looking at.
await openThreadWithTask(projectRef, task, pointed);
toastManager.update(
toastId,
prepared.value.isOnPullRequestHead
? {
type: "success",
title: "Checkout ready",
description: "The task is in the composer. Read it over, then send.",
}
: offHeadPullRequestCheckoutToast(terminology),
);
};

const askAboutPullRequest = () => {
Expand Down
14 changes: 14 additions & 0 deletions apps/web/src/components/pullRequest/pullRequestCheckoutState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { create } from "zustand";
import type { DraftId } from "~/composerDraftStore";

export const usePullRequestCheckoutState = create(() => ({ draftIds: new Map<DraftId, symbol>() }));

export function setPullRequestCheckoutPending(draftId: DraftId, pending: boolean, owner: symbol) {
usePullRequestCheckoutState.setState((state) => {
if (!pending && state.draftIds.get(draftId) !== owner) return state;
const draftIds = new Map(state.draftIds);
if (pending) draftIds.set(draftId, owner);
else draftIds.delete(draftId);
return { draftIds };
});
}
Loading
Loading