GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(web): move worktree setup progress out of ChatView · pingdotgg/t3code@e2182f9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components
    • ChatView.tsx
    • chat
      • useWorktreeSetup.ts
  • vite.config.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.tsx
+36-119Lines changed: 36 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {
55
resolveBackgroundDraftWorkspaceOptions,
66
resolveDraftHeroState,
77
shouldDockDraftHeroForSubmission,
8-
resolveVisibleWorktreeSetup,
9-
resolveWorktreeSetupProgress,
108
} from "./ChatView.logic";
119
import * as DateTime from "effect/DateTime";
1210
import { restorePlanFollowUpComposer } from "./ChatView.logic";
@@ -37,6 +35,7 @@ import type { UsageLimitSourceSnapshots } from "@t3tools/contracts";
3735
import { isUsageLimitsCommand } from "@t3tools/shared/usageLimits";
3836
import { feedbackBannerItem } from "./chat/ComposerFeedback";
3937
import { useUsageLimitsPanel } from "./chat/useUsageLimitsPanel";
38+
import { useWorktreeSetup } from "./chat/useWorktreeSetup";
4039
import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
4140
import * as Schema from "effect/Schema";
4241
import {
@@ -71,7 +70,6 @@ import {
7170
resolveEnvironmentMachineKind,
7271
resolveProjectProviderInstanceEnabled,
7372
RuntimeMode,
74-
type WorktreeSetupSnapshot,
7573
} from "@t3tools/contracts";
7674
import { type EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection";
7775
import { deriveThreadTitleSeed } from "@t3tools/client-runtime/operations";
@@ -389,7 +387,6 @@ import {
389387
serverEnvironment,
390388
} from "../state/server";
391389
import { threadEnvironment } from "../state/threads";
392-
import { workspacePreparationRetryRunIds } from "@t3tools/client-runtime/state/turn-item-presentation";
393390
import { resolveProviderSkillsForCwd } from "@t3tools/client-runtime/providerSkills";
394391
import { vcsEnvironment } from "../state/vcs";
395392
import { sourceControlEnvironment } from "../state/sourceControl";
@@ -421,7 +418,7 @@ import type { AssistantCitationRequest } from "./chat/AssistantCitationSource";
421418
import { MessagesTimeline, type MessagesTimelineHistoryControls } from "./chat/MessagesTimeline";
422419
import { ProviderSubagentBar } from "./chat/ProviderSubagentBar";
423420
import { getTriggerDisplayModelName } from "./chat/providerIconUtils";
424-
import { resolveTimelineIsAtEnd, worktreeSetupAgentStarted } from "./chat/MessagesTimeline.logic";
421+
import { resolveTimelineIsAtEnd } from "./chat/MessagesTimeline.logic";
425422
import {
426423
overlayComposerIsResting,
427424
resolveComposerTimelineInset,
@@ -901,8 +898,12 @@ function releaseChatTimelineAnchor<T extends { readonly messageId: MessageId | n
901898
return current.messageId === null ? current : { ...current, messageId: null };
902899
}
903900

904-
const retryingWorkspacePreparationRunIds = new Set<RunId>();
901+
// The factories below build functions ChatView calls during render, or hands
902+
// to ChatComposer, which can call them after an await. They live outside the
903+
// component so each closure keeps only its inputs, not a whole render scope
904+
// (see useStableCallback), while still acting on the render that made them.
905905

906+
/** Records a thread error in local state, keyed by the route the making render saw. */
906907
function makeThreadErrorSetter(input: {
907908
readonly routeThreadRef: ScopedThreadRef;
908909
readonly routeThreadKey: string;
@@ -1235,15 +1236,10 @@ export default function ChatView(props: ChatViewProps) {
12351236
return () => revokeBlobPreviewUrl(src);
12361237
}, [expandedImage]);
12371238
const [optimisticUserMessages, setOptimisticUserMessages] = useState<ChatMessage[]>([]);
1238-
// Last live snapshot from the setup stream. The server drops a finished
1239-
// snapshot after a grace period and emits null; holding it here bridges the
1240-
// gap until the settled activity arrives on the thread projection.
1241-
const [worktreeSetupRef, setWorktreeSetupRef] = useState<{
1242-
environmentId: EnvironmentId;
1243-
threadId: ThreadId;
1244-
ownerKey: string;
1245-
} | null>(null);
1246-
const [heldWorktreeSetup, setHeldWorktreeSetup] = useState<WorktreeSetupSnapshot | null>(null);
1239+
// Set by "Work locally": the draft whose restored message should be resent
1240+
// once the cancelled dispatch has settled and the draft is in local mode.
1241+
// Keyed by draft id so a bootstrap rotating the thread id keeps it, while
1242+
// moving to another draft drops it without an effect.
12471243
const [workLocallyResendDraftId, setWorkLocallyResendDraftId] = useState<DraftId | null>(null);
12481244
useEffect(() => {
12491245
if (workLocallyResendDraftId !== null && workLocallyResendDraftId !== draftId) {
@@ -3028,98 +3024,29 @@ export default function ChatView(props: ChatViewProps) {
30283024
activeThreadKey,
30293025
);
30303026
const displayedThreadRef = parseScopedThreadKey(displayedTimelineKey);
3031-
const worktreeSetupOwnerKey = draftId ?? routeThreadKey;
3032-
const worktreeSetupActive =
3033-
worktreeSetupRef !== null && worktreeSetupRef.ownerKey === worktreeSetupOwnerKey;
3034-
const setupTarget = worktreeSetupActive ? worktreeSetupRef : routeThreadRef;
3035-
const worktreeSetupQuery = useEnvironmentQuery(
3036-
worktreeSetupActive ||
3037-
(activeThread?.id === routeThreadRef.threadId &&
3038-
(isLocallyPreparingWorktree || activeRunPreparing || activeThread.worktreePath !== null))
3039-
? vcsEnvironment.worktreeSetup({
3040-
environmentId: setupTarget.environmentId,
3041-
input: { threadId: setupTarget.threadId },
3042-
})
3043-
: null,
3044-
);
3045-
const latestWorktreeSetup = worktreeSetupQuery.data;
3046-
useEffect(() => {
3047-
if (!latestWorktreeSetup) return;
3048-
setHeldWorktreeSetup((current) =>
3049-
current?.threadId === latestWorktreeSetup.threadId &&
3050-
current.sequence > latestWorktreeSetup.sequence
3051-
? current
3052-
: latestWorktreeSetup,
3053-
);
3054-
}, [latestWorktreeSetup]);
3055-
useEffect(() => {
3056-
setHeldWorktreeSetup(null);
3057-
}, [routeThreadKey]);
3058-
const { snapshot: liveWorktreeSetup, isPreparingWorktree } = resolveWorktreeSetupProgress({
3059-
threadId: setupTarget.threadId,
3027+
const {
3028+
worktreeSetup,
3029+
isPreparingWorktree,
3030+
blocksSend: worktreeSetupBlocksSend,
3031+
retryableRunIds: retryableWorkspacePreparationRunIds,
3032+
begin: beginWorktreeSetup,
3033+
cancel: cancelWorktreeSetup,
3034+
retryPreparation: onRetryWorkspacePreparationStable,
3035+
openSetupTerminal: onOpenWorktreeSetupTerminal,
3036+
} = useWorktreeSetup({
3037+
routeThreadRef,
3038+
ownerKey: draftId ?? routeThreadKey,
3039+
activeThread,
3040+
threadRef: activeThreadRef,
3041+
serverProjection,
3042+
activityRun: activeActivityRun,
30603043
localPreparing: isLocallyPreparingWorktree,
3061-
runStatus: activeActivityRun?.status,
3062-
latest: latestWorktreeSetup,
3063-
held: heldWorktreeSetup,
3064-
});
3065-
const worktreeSetup = resolveVisibleWorktreeSetup({
3066-
live: liveWorktreeSetup,
3067-
recorded: null,
3068-
turnStarted: activeActivityRun?.startedAt != null,
3044+
sendQueuesBehindSetup,
3045+
// Counts the optimistic send too, so the row retires the moment the
3046+
// follow-up is on screen rather than when the server echoes it back.
30693047
followUpSent: timelineMessages.filter((message) => message.role === "user").length > 1,
30703048
});
3071-
// Sends wait for the agent handoff, not for the setup script: an async script
3072-
// keeps the snapshot running while the agent already works, and a follow-up
3073-
// must not be held behind a slow install.
3074-
const worktreeSetupBlocksSend =
3075-
!sendQueuesBehindSetup &&
3076-
(worktreeSetup !== null
3077-
? worktreeSetup.phase === "running" && !worktreeSetupAgentStarted(worktreeSetup)
3078-
: isPreparingWorktree);
3079-
const cancelWorktreeSetup = useAtomCommand(vcsEnvironment.cancelWorktreeSetup, {
3080-
reportFailure: false,
3081-
});
3082-
const retryWorkspacePreparation = useAtomCommand(threadEnvironment.retryWorkspacePreparation);
3083-
const retryableRunIdsKey = useMemo(
3084-
() =>
3085-
[
3086-
...workspacePreparationRetryRunIds(
3087-
serverProjection?.runs ?? [],
3088-
serverProjection?.turnItems ?? [],
3089-
),
3090-
].join("\n"),
3091-
[serverProjection?.runs, serverProjection?.turnItems],
3092-
);
3093-
const retryableWorkspacePreparationRunIds = useMemo(
3094-
() => new Set(retryableRunIdsKey === "" ? [] : (retryableRunIdsKey.split("\n") as RunId[])),
3095-
[retryableRunIdsKey],
3096-
);
3097-
const onRetryWorkspacePreparation = (runId: RunId) => {
3098-
if (!activeThreadRef || retryingWorkspacePreparationRunIds.has(runId)) return;
3099-
retryingWorkspacePreparationRunIds.add(runId);
3100-
void retryWorkspacePreparation({
3101-
environmentId: activeThreadRef.environmentId,
3102-
input: { threadId: activeThreadRef.threadId, runId },
3103-
}).finally(() => retryingWorkspacePreparationRunIds.delete(runId));
3104-
};
3105-
const onRetryWorkspacePreparationStable = useStableCallback(onRetryWorkspacePreparation);
3106-
const onCancelWorktreeSetup = () => {
3107-
if (!worktreeSetup || worktreeSetup.phase !== "running") return;
3108-
void cancelWorktreeSetup({
3109-
environmentId: setupTarget.environmentId,
3110-
input: { threadId: worktreeSetup.threadId },
3111-
});
3112-
};
3113-
const onCancelWorktreeSetupStable = useStableCallback(onCancelWorktreeSetup);
3114-
const onOpenWorktreeSetupTerminal = useMemo(() => {
3115-
if (!worktreeSetup || !activeThreadRef || worktreeSetup.threadId !== activeThreadRef.threadId) {
3116-
return null;
3117-
}
3118-
const setupThreadRef = activeThreadRef;
3119-
return (terminalId: string) => {
3120-
storeEnsureTerminal(setupThreadRef, terminalId, { open: true, active: true });
3121-
};
3122-
}, [activeThreadRef, storeEnsureTerminal, worktreeSetup]);
3049+
const onCancelWorktreeSetupStable = useStableCallback(() => void cancelWorktreeSetup());
31233050
const [dockedDraftHeroThreadKey, setDockedDraftHeroThreadKey] = useState<string | null>(null);
31243051
const draftHeroDockRequested =
31253052
activeThreadKey !== null && dockedDraftHeroThreadKey === activeThreadKey;
@@ -7353,13 +7280,9 @@ export default function ChatView(props: ChatViewProps) {
73537280
? "foreground"
73547281
: submissionIntent,
73557282
});
7356-
setWorktreeSetupRef(
7283+
beginWorktreeSetup(
73577284
multipleModelSelections === null && baseBranchForWorktree
7358-
? {
7359-
environmentId: activeThread.environmentId,
7360-
threadId: threadIdForSend,
7361-
ownerKey: worktreeSetupOwnerKey,
7362-
}
7285+
? { environmentId: activeThread.environmentId, threadId: threadIdForSend }
73637286
: null,
73647287
);
73657288
}
@@ -8432,15 +8355,9 @@ export default function ChatView(props: ChatViewProps) {
84328355
if (!worktreeSetup || worktreeSetup.phase !== "running" || !draftId) {
84338356
return;
84348357
}
8435-
const target = {
8436-
environmentId: setupTarget.environmentId,
8437-
input: { threadId: worktreeSetup.threadId },
8438-
};
8439-
void (async () => {
8440-
const result = await cancelWorktreeSetup(target);
8441-
if (result._tag !== "Success" || !result.value.cancelled) return;
8442-
setWorkLocallyResendDraftId(draftId);
8443-
})();
8358+
void cancelWorktreeSetup().then((cancelled) => {
8359+
if (cancelled) setWorkLocallyResendDraftId(draftId);
8360+
});
84448361
};
84458362
const onWorktreeSetupWorkLocallyStable = useStableCallback(onWorktreeSetupWorkLocally);
84468363
const onSendRef = useRef(onSend);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.