Skip to content

Commit 0e24917

Browse files
fix(tim-compat): product-merge VCS pingdotgg#4727 with fork failureKind; green tip
Bring Tim layer tip to typecheck green by joining main ref-refresh VCS client state with fork failureKind/worktree-cleanup contracts, restoring filterBrowseEntries/reuse-base-branch surfaces Tim dropped, and fixing ChatView/Board call-site type errors left by incomplete Tim joins.
1 parent 15a7d2a commit 0e24917

10 files changed

Lines changed: 779 additions & 258 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 472 additions & 93 deletions
Large diffs are not rendered by default.

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
import { dedupeRemoteBranchesWithLocalMatches, normalizeGitRemoteUrl } from "@t3tools/shared/git";
2929
import { compactTraceAttributes } from "@t3tools/shared/observability";
3030
import { decodeJsonResult } from "@t3tools/shared/schemaJson";
31-
import { DirenvEnvironment } from "../provider/DirenvEnvironment.ts";
3231
import { gitCommandDuration, gitCommandsTotal, withMetrics } from "../observability/Metrics.ts";
3332
import * as GitVcsDriver from "./GitVcsDriver.ts";
3433
import {
@@ -94,6 +93,31 @@ const COMMIT_SIGNING_FAILURE_PATTERNS = [
9493
export function isCommitSigningFailureStderr(stderr: string): boolean {
9594
return COMMIT_SIGNING_FAILURE_PATTERNS.some((pattern) => pattern.test(stderr));
9695
}
96+
97+
/** Longer than any real git error line, short enough to keep logs readable. */
98+
const GIT_STDERR_LOG_LIMIT = 2000;
99+
100+
/**
101+
* Strip credentials from git output so it can be logged.
102+
*
103+
* git echoes the remote URL it used, and those URLs routinely carry secrets
104+
* (`https://x-access-token:[email protected]/...`), so raw stderr must never
105+
* reach a log. Redacts the userinfo component of any URL plus bare tokens that
106+
* commonly appear on their own.
107+
*/
108+
export function redactGitOutput(stderr: string): string {
109+
return (
110+
stderr
111+
.slice(0, GIT_STDERR_LOG_LIMIT)
112+
.replace(/([a-zA-Z][\w+.-]*:\/\/)[^/@\s]*@/g, "$1<redacted>@")
113+
.replace(/\b(gh[pousr]_|github_pat_|glpat-)[A-Za-z0-9_-]+/g, "$1<redacted>")
114+
// Take the whole value, not just the scheme word: `Authorization: Bearer X`
115+
// must not redact `Bearer` and leave `X` behind.
116+
.replace(/\b(Authorization)\s*[:=]\s*.*/gi, "$1: <redacted>")
117+
.replace(/\b(Bearer|token)\s*[:=]?\s+\S+/gi, "$1 <redacted>")
118+
);
119+
}
120+
97121
const NON_REPOSITORY_STATUS_DETAILS = Object.freeze<GitVcsDriver.GitStatusDetails>({
98122
isRepo: false,
99123
hasOriginRemote: false,
@@ -516,15 +540,16 @@ const createTrace2Monitor = Effect.fn("createTrace2Monitor")(function* (
516540
return;
517541
}
518542

543+
if (traceRecord.success.child_class !== "hook") {
544+
return;
545+
}
546+
519547
const event = traceRecord.success.event;
520548
const childKey = trace2ChildKey(traceRecord.success);
521549
if (childKey === null) {
522550
return;
523551
}
524552
const started = hookStartByChildKey.get(childKey);
525-
if (traceRecord.success.child_class !== "hook" && started === undefined) {
526-
return;
527-
}
528553
const hookNameFromEvent =
529554
typeof traceRecord.success.hook_name === "string" ? traceRecord.success.hook_name.trim() : "";
530555
const hookName = hookNameFromEvent.length > 0 ? hookNameFromEvent : (started?.hookName ?? "");
@@ -546,7 +571,7 @@ const createTrace2Monitor = Effect.fn("createTrace2Monitor")(function* (
546571

547572
if (event === "child_exit") {
548573
hookStartByChildKey.delete(childKey);
549-
const code = traceRecord.success.code ?? traceRecord.success.exitCode;
574+
const code = traceRecord.success.exitCode;
550575
const exitCode = typeof code === "number" && Number.isInteger(code) ? code : null;
551576
const now = yield* DateTime.now;
552577
const durationMs = started
@@ -718,17 +743,6 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
718743
const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
719744
const { worktreesDir } = yield* ServerConfig;
720745
const crypto = yield* Crypto.Crypto;
721-
const direnvEnvironment = yield* DirenvEnvironment;
722-
723-
const approveWorktreeEnvironment = (cwd: string) =>
724-
direnvEnvironment.allow({ cwd, environment: process.env }).pipe(
725-
Effect.catch((error) =>
726-
Effect.logWarning("Failed to approve direnv for a newly created worktree.", {
727-
cwd,
728-
detail: error.message,
729-
}),
730-
),
731-
);
732746

733747
const executeRaw: GitVcsDriver.GitVcsDriver["Service"]["execute"] = Effect.fnUntraced(
734748
function* (input) {
@@ -2531,8 +2545,6 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
25312545
fallbackErrorDetail: "git worktree add failed",
25322546
});
25332547

2534-
yield* approveWorktreeEnvironment(worktreePath);
2535-
25362548
if (input.newRefName && input.baseRefName) {
25372549
const remoteNames = yield* listRemoteNames(input.cwd).pipe(Effect.orElseSucceed(() => []));
25382550
const parsedBaseRef = parseRemoteRefWithRemoteNames(
@@ -2656,7 +2668,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
26562668
}
26572669
args.push(input.path);
26582670
yield* executeGit("GitVcsDriver.removeWorktree", input.cwd, args, {
2659-
timeoutMs: 30_000,
2671+
timeoutMs: 15_000,
26602672
fallbackErrorDetail: "git worktree remove failed",
26612673
});
26622674
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,19 @@ describe("resolveBranchTriggerLabel", () => {
212212
).toBe("From main");
213213
});
214214

215+
it("shows the bare branch name when reusing the selected worktree base branch", () => {
216+
expect(
217+
resolveBranchTriggerLabel({
218+
activeWorktreePath: null,
219+
effectiveEnvMode: "worktree",
220+
resolvedActiveBranch: "main",
221+
resolvedActiveBranchIsRemote: false,
222+
startFromOrigin: true,
223+
reuseBaseBranch: true,
224+
}),
225+
).toBe("main");
226+
});
227+
215228
it("does not duplicate the origin prefix for an explicit remote ref", () => {
216229
expect(
217230
resolveBranchTriggerLabel({

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface EnvironmentOption {
1515

1616
export const EnvMode = Schema.Literals(["local", "worktree"]);
1717
export type EnvMode = typeof EnvMode.Type;
18+
export type WorkspaceTarget = EnvMode | "current-worktree";
1819

1920
const GENERIC_LOCAL_ENVIRONMENT_LABELS = new Set(["local", "local environment"]);
2021

@@ -62,6 +63,16 @@ export function resolveCurrentWorkspaceLabel(activeWorktreePath: string | null):
6263
return activeWorktreePath ? "Current worktree" : resolveEnvModeLabel("local");
6364
}
6465

66+
export function resolveWorkspaceTarget(input: {
67+
effectiveEnvMode: EnvMode;
68+
activeWorktreePath: string | null;
69+
}): WorkspaceTarget {
70+
if (input.effectiveEnvMode === "worktree") {
71+
return "worktree";
72+
}
73+
return input.activeWorktreePath ? "current-worktree" : "local";
74+
}
75+
6576
export function resolveLockedWorkspaceLabel(activeWorktreePath: string | null): string {
6677
return activeWorktreePath ? "Worktree" : "Local checkout";
6778
}
@@ -162,18 +173,25 @@ export function resolveBranchTriggerLabel(input: {
162173
resolvedActiveBranch: string | null;
163174
resolvedActiveBranchIsRemote: boolean | null;
164175
startFromOrigin: boolean;
176+
reuseBaseBranch?: boolean;
165177
}): string {
166178
const {
167179
activeWorktreePath,
168180
effectiveEnvMode,
169181
resolvedActiveBranch,
170182
resolvedActiveBranchIsRemote,
171183
startFromOrigin,
184+
reuseBaseBranch = false,
172185
} = input;
173186
if (!resolvedActiveBranch) {
174187
return "Select ref";
175188
}
189+
// Reused base branch is checked out as-is (Tim #15); otherwise "From X" for
190+
// new worktree branches, with optional origin/ prefix (upstream #4680).
176191
if (effectiveEnvMode === "worktree" && !activeWorktreePath) {
192+
if (reuseBaseBranch) {
193+
return resolvedActiveBranch;
194+
}
177195
const baseRef =
178196
startFromOrigin && resolvedActiveBranchIsRemote === false
179197
? `origin/${resolvedActiveBranch}`

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

Lines changed: 31 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
2424
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
2525
import { readLocalApi } from "../localApi";
2626
import { useOpenPrLink } from "../lib/openPullRequestLink";
27+
import { shouldLoadNextBranchPageAfterScroll } from "../state/paginatedBranches";
2728
import { usePaginatedBranches } from "../state/queries";
2829
import { useProject, useThread } from "../state/entities";
2930
import { useEnvironmentQuery } from "../state/query";
@@ -35,6 +36,7 @@ import { parsePullRequestReference } from "../pullRequestReference";
3536
import { getSourceControlPresentation } from "../sourceControlPresentation";
3637
import {
3738
deriveLocalBranchNameFromRemoteRef,
39+
resolveBranchTriggerLabel,
3840
resolveBranchToolbarPrBranch,
3941
resolveBranchSelectionTarget,
4042
resolveBranchToolbarValue,
@@ -83,40 +85,6 @@ function toBranchActionErrorMessage(error: unknown): string {
8385
return error instanceof Error ? error.message : "An error occurred.";
8486
}
8587

86-
function getBranchTriggerLabel(input: {
87-
activeWorktreePath: string | null;
88-
effectiveEnvMode: "local" | "worktree";
89-
resolvedActiveBranch: string | null;
90-
resolvedActiveBranchIsRemote: boolean | null;
91-
startFromOrigin: boolean;
92-
reuseBaseBranch: boolean;
93-
}): string {
94-
const {
95-
activeWorktreePath,
96-
effectiveEnvMode,
97-
resolvedActiveBranch,
98-
resolvedActiveBranchIsRemote,
99-
startFromOrigin,
100-
reuseBaseBranch,
101-
} = input;
102-
if (!resolvedActiveBranch) {
103-
return "Select ref";
104-
}
105-
// Reused base branch is checked out as-is (Tim #15); otherwise "From X" for
106-
// new worktree branches, with optional origin/ prefix (upstream #4680).
107-
if (effectiveEnvMode === "worktree" && !activeWorktreePath) {
108-
if (reuseBaseBranch) {
109-
return resolvedActiveBranch;
110-
}
111-
const baseRef =
112-
startFromOrigin && resolvedActiveBranchIsRemote === false
113-
? `origin/${resolvedActiveBranch}`
114-
: resolvedActiveBranch;
115-
return `From ${baseRef}`;
116-
}
117-
return resolvedActiveBranch;
118-
}
119-
12088
export function BranchToolbarBranchSelector({
12189
className,
12290
environmentId,
@@ -268,7 +236,7 @@ export function BranchToolbarBranchSelector({
268236
const refs = branchRefState.refs;
269237
const hasNextPage =
270238
branchRefState.data?.nextCursor !== null && branchRefState.data?.nextCursor !== undefined;
271-
const isFetchingNextPage = branchRefState.isPending && branchRefState.data !== null;
239+
const isFetchingNextPage = branchRefState.isFetchingNextPage;
272240
const isInitialBranchesLoadPending = branchRefState.isPending && branchRefState.data === null;
273241
const currentGitBranch =
274242
branchStatusQuery.data?.refName ?? refs.find((refName) => refName.current)?.name ?? null;
@@ -543,19 +511,16 @@ export function BranchToolbarBranchSelector({
543511
// ---------------------------------------------------------------------------
544512
// Combobox / list plumbing
545513
// ---------------------------------------------------------------------------
546-
const handleOpenChange = useCallback(
547-
(open: boolean) => {
548-
setIsBranchMenuOpen(open);
549-
if (!open) {
550-
setBranchQuery("");
551-
return;
552-
}
553-
branchRefState.refresh();
554-
},
555-
[branchRefState.refresh],
556-
);
557-
558514
const branchListScrollElementRef = useRef<HTMLElement | null>(null);
515+
const previousBranchListScrollTopRef = useRef<number | null>(null);
516+
const handleOpenChange = useCallback((open: boolean) => {
517+
previousBranchListScrollTopRef.current = null;
518+
setIsBranchMenuOpen(open);
519+
if (!open) {
520+
setBranchQuery("");
521+
}
522+
}, []);
523+
559524
const [showTopBranchScrollFade, setShowTopBranchScrollFade] = useState(false);
560525
const [showBottomBranchScrollFade, setShowBottomBranchScrollFade] = useState(false);
561526
const fetchNextBranchPage = useCallback(() => {
@@ -566,18 +531,24 @@ export function BranchToolbarBranchSelector({
566531
branchRefState.loadNext();
567532
}, [branchRefState.loadNext, hasNextPage, isFetchingNextPage]);
568533
const maybeFetchNextBranchPage = useCallback(() => {
569-
if (!isBranchMenuOpen || !hasNextPage || isFetchingNextPage) {
570-
return;
571-
}
572-
573534
const scrollElement = branchListScrollElementRef.current;
574535
if (!scrollElement) {
575536
return;
576537
}
577538

578-
const distanceFromBottom =
579-
scrollElement.scrollHeight - scrollElement.scrollTop - scrollElement.clientHeight;
580-
if (distanceFromBottom > 96) {
539+
const previousScrollTop = previousBranchListScrollTopRef.current;
540+
previousBranchListScrollTopRef.current = scrollElement.scrollTop;
541+
if (
542+
!isBranchMenuOpen ||
543+
!hasNextPage ||
544+
isFetchingNextPage ||
545+
!shouldLoadNextBranchPageAfterScroll({
546+
previousScrollTop,
547+
scrollTop: scrollElement.scrollTop,
548+
scrollHeight: scrollElement.scrollHeight,
549+
clientHeight: scrollElement.clientHeight,
550+
})
551+
) {
581552
return;
582553
}
583554

@@ -627,11 +598,7 @@ export function BranchToolbarBranchSelector({
627598
void branchListRef.current?.scrollToOffset?.({ offset: 0, animated: false });
628599
}, [deferredTrimmedBranchQuery, isBranchMenuOpen]);
629600

630-
useEffect(() => {
631-
maybeFetchNextBranchPage();
632-
}, [refs.length, maybeFetchNextBranchPage]);
633-
634-
const triggerLabel = getBranchTriggerLabel({
601+
const triggerLabel = resolveBranchTriggerLabel({
635602
activeWorktreePath,
636603
effectiveEnvMode,
637604
resolvedActiveBranch,
@@ -784,7 +751,7 @@ export function BranchToolbarBranchSelector({
784751
>
785752
<ComboboxTrigger
786753
render={<Button variant="ghost" size="xs" />}
787-
className="min-w-0 max-w-full shrink text-muted-foreground/70 hover:text-foreground/80"
754+
className="min-w-0 max-w-full text-muted-foreground/70 hover:text-foreground/80"
788755
disabled={isInitialBranchesLoadPending || isBranchActionPending}
789756
>
790757
<GitBranchIcon className="size-3 shrink-0 opacity-70" />
@@ -830,14 +797,10 @@ export function BranchToolbarBranchSelector({
830797
renderItem={({ item, index }) => renderPickerItem(item, index)}
831798
estimatedItemSize={28}
832799
drawDistance={336}
833-
onEndReached={() => {
834-
if (hasNextPage && !isFetchingNextPage) {
835-
fetchNextBranchPage();
836-
}
837-
}}
838800
onLayout={() => {
839801
updateBranchListScrollFades();
840-
maybeFetchNextBranchPage();
802+
previousBranchListScrollTopRef.current =
803+
branchListScrollElementRef.current?.scrollTop ?? null;
841804
}}
842805
onScroll={() => {
843806
updateBranchListScrollFades();
@@ -906,9 +869,8 @@ export function BranchToolbarBranchSelector({
906869
}
907870
/>
908871
<TooltipPopup side="top" className="max-w-72 whitespace-normal leading-tight">
909-
{reuseBaseBranch
910-
? "Not available when reusing the selected branch."
911-
: "Creates the worktree from the latest matching branch on origin instead of your local branch."}
872+
Creates the worktree from the latest matching branch on origin instead of your
873+
local branch.
912874
</TooltipPopup>
913875
</Tooltip>
914876
</div>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ import { getProviderModelCapabilities, resolveSelectableProvider } from "../prov
169169
import { NO_PROVIDER_MODEL_SELECTION } from "../providerInstances";
170170
import { useClientSettings, useEnvironmentSettings } from "../hooks/useSettings";
171171
import { useNowMinute } from "../hooks/useNowMinute";
172-
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
173172
import { resolveAppModelSelectionForInstance } from "../modelSelection";
174173
import { getTerminalFocusOwner } from "../lib/terminalFocus";
175174
import { resolveNewDraftStartFromOrigin } from "../lib/chatThreadActions";
@@ -1205,7 +1204,6 @@ function ChatViewContent(props: ChatViewProps) {
12051204
const timestampFormat = settings.timestampFormat;
12061205
const autoOpenPlanSidebar = settings.autoOpenPlanSidebar;
12071206
const navigate = useNavigate();
1208-
const handleNewThread = useNewThreadHandler();
12091207
const { resolvedTheme } = useTheme();
12101208
// Granular store selectors — avoid subscribing to prompt changes.
12111209
const composerRuntimeMode = useComposerDraftStore(

0 commit comments

Comments
 (0)