Skip to content

Commit 70ef0e6

Browse files
committed
fix: remove redundant targetProjectCwd reassignment and replace fragile setup terminal ID heuristic
- Remove dead reassignment of targetProjectCwd in bootstrap worktree preparation (ws.ts:278) — the value was already set at initialization. - Extract SETUP_TERMINAL_ID_PREFIX constant into @t3tools/contracts so the setup terminal naming convention is shared between server and client instead of duplicated as magic strings. - Remove the fragile effectiveWorktreePath fallback in PersistentThreadTerminalDrawer that inferred worktree path from launchContext.cwd when the active terminal started with 'setup-'. The fallback could return the wrong path when the launch context originated from a different terminal. The thread-level worktreePath is the correct fallback and was already in place.
1 parent a5a9521 commit 70ef0e6

File tree

5 files changed

+6
-8
lines changed

5 files changed

+6
-8
lines changed

apps/server/src/project/Layers/ProjectSetupScriptRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SETUP_TERMINAL_ID_PREFIX } from "@t3tools/contracts";
12
import { projectScriptRuntimeEnv, setupProjectScript } from "@t3tools/shared/projectScripts";
23
import { Effect, Layer } from "effect";
34

@@ -35,7 +36,7 @@ const makeProjectSetupScriptRunner = Effect.gen(function* () {
3536
} as const;
3637
}
3738

38-
const terminalId = input.preferredTerminalId ?? `setup-${script.id}`;
39+
const terminalId = input.preferredTerminalId ?? `${SETUP_TERMINAL_ID_PREFIX}${script.id}`;
3940
const cwd = input.worktreePath;
4041
const env = projectScriptRuntimeEnv({
4142
project: { cwd: project.workspaceRoot },

apps/server/src/ws.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ const WsRpcLayer = WsRpcGroup.toLayer(
275275
newBranch: bootstrap.prepareWorktree.branch,
276276
path: null,
277277
});
278-
targetProjectCwd = bootstrap.prepareWorktree.projectCwd;
279278
targetWorktreePath = worktree.worktree.path;
280279
yield* orchestrationEngine.dispatch({
281280
type: "thread.meta.update",

apps/web/src/components/ChatView.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,8 @@ function PersistentThreadTerminalDrawer({
446446
if (launchContext?.worktreePath) {
447447
return launchContext.worktreePath;
448448
}
449-
if (launchContext && terminalState.activeTerminalId.startsWith("setup-")) {
450-
return launchContext.cwd;
451-
}
452449
return worktreePath;
453-
}, [launchContext, terminalState.activeTerminalId, worktreePath]);
450+
}, [launchContext, worktreePath]);
454451
const cwd = useMemo(
455452
() =>
456453
launchContext?.cwd ??

apps/web/src/terminalStateStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* API constrained to store actions/selectors.
66
*/
77

8-
import { ThreadId, type TerminalEvent } from "@t3tools/contracts";
8+
import { SETUP_TERMINAL_ID_PREFIX, ThreadId, type TerminalEvent } from "@t3tools/contracts";
99
import { create } from "zustand";
1010
import { createJSONStorage, persist } from "zustand/middleware";
1111
import { resolveStorage } from "./lib/storage";
@@ -281,7 +281,7 @@ function launchContextFromStartEvent(
281281
): ThreadTerminalLaunchContext {
282282
return {
283283
cwd: event.snapshot.cwd,
284-
worktreePath: event.terminalId.startsWith("setup-") ? event.snapshot.cwd : null,
284+
worktreePath: event.terminalId.startsWith(SETUP_TERMINAL_ID_PREFIX) ? event.snapshot.cwd : null,
285285
};
286286
}
287287

packages/contracts/src/terminal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Schema } from "effect";
22
import { TrimmedNonEmptyString } from "./baseSchemas";
33

44
export const DEFAULT_TERMINAL_ID = "default";
5+
export const SETUP_TERMINAL_ID_PREFIX = "setup-";
56

67
const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
78
const TerminalColsSchema = Schema.Int.check(Schema.isGreaterThanOrEqualTo(20)).check(

0 commit comments

Comments
 (0)