@devries-cameron20 / t3code-1 / commits / 833c8ab7c6
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

[codex] Remove project setup error constructor wrappers (#3329)

Co-authored-by: codex <codex@users.noreply.github.com>

Julius Marminge committed Jun 20, 2026 at 11:28 UTC 833c8ab7c66f4e976c9ae0641d5b1d2780348734
2 files changed +101 -41
apps/server/src/project/ProjectSetupScriptRunner.test.ts
+51
@@ -3,11 +3,16 @@ import { type OrchestrationProject, ProjectId } from "@t3tools/contracts";
3 import * as Effect from "effect/Effect";
4 import * as Layer from "effect/Layer";
5 import * as Option from "effect/Option";
6 +import * as Schema from "effect/Schema";
7
8 import * as ProjectionSnapshotQuery from "../orchestration/Services/ProjectionSnapshotQuery.ts";
9 import * as TerminalManager from "../terminal/Manager.ts";
10 import * as ProjectSetupScriptRunner from "./ProjectSetupScriptRunner.ts";
11
12 +const isProjectSetupScriptOperationError = Schema.is(
13 + ProjectSetupScriptRunner.ProjectSetupScriptOperationError,
14 +);
15 +
16 const makeProject = (scripts: OrchestrationProject["scripts"]): OrchestrationProject => ({
17 id: ProjectId.make("project-1"),
18 title: "Project",
@@ -145,4 +150,50 @@ describe("ProjectSetupScriptRunner", () => {
150 }).pipe(Effect.provide(testLayer(project, { open, write })));
151 },
152 );
153 +
154 + it.effect("keeps terminal failures as the exact cause of a structured operation error", () => {
155 + const rootCause = new Error("stat failed");
156 + const terminalError = new TerminalManager.TerminalCwdError({
157 + cwd: "/repo/worktrees/a",
158 + reason: "statFailed",
159 + cause: rootCause,
160 + });
161 + const project = makeProject([
162 + {
163 + id: "setup",
164 + name: "Setup",
165 + command: "bun install",
166 + icon: "configure",
167 + runOnWorktreeCreate: true,
168 + },
169 + ]);
170 +
171 + return Effect.gen(function* () {
172 + const runner = yield* ProjectSetupScriptRunner.ProjectSetupScriptRunner;
173 + const error = yield* runner
174 + .runForThread({
175 + threadId: "thread-1",
176 + projectId: "project-1",
177 + worktreePath: "/repo/worktrees/a",
178 + })
179 + .pipe(Effect.flip);
180 +
181 + expect(isProjectSetupScriptOperationError(error)).toBe(true);
182 + if (isProjectSetupScriptOperationError(error)) {
183 + expect(error.operation).toBe("openTerminal");
184 + expect(error.threadId).toBe("thread-1");
185 + expect(error.projectId).toBe("project-1");
186 + expect(error.worktreePath).toBe("/repo/worktrees/a");
187 + expect(error.cause).toBe(terminalError);
188 + expect(terminalError.cause).toBe(rootCause);
189 + }
190 + }).pipe(
191 + Effect.provide(
192 + testLayer(project, {
193 + open: () => Effect.fail(terminalError),
194 + write: () => Effect.die("unexpected write"),
195 + }),
196 + ),
197 + );
198 + });
199 });
apps/server/src/project/ProjectSetupScriptRunner.ts
+50 -41
@@ -59,7 +59,7 @@ export class ProjectSetupScriptProjectNotFoundError extends Schema.TaggedErrorCl
59 },
60 ) {
61 override get message(): string {
62 - return "Project was not found for setup script execution.";
62 + return `Project was not found for setup script execution for thread '${this.threadId}' in '${this.worktreePath}'.`;
63 }
64 }
65
@@ -78,32 +78,6 @@ export class ProjectSetupScriptRunner extends Context.Service<
78 }
79 >()("t3/project/ProjectSetupScriptRunner") {}
80
81 -const isProjectSetupScriptRunnerError = Schema.is(ProjectSetupScriptRunnerError);
82 -
83 -function operationError(
84 - input: ProjectSetupScriptRunnerInput,
85 - operation: ProjectSetupScriptOperationError["operation"],
86 - cause: unknown,
87 -): ProjectSetupScriptOperationError {
88 - return new ProjectSetupScriptOperationError({
89 - threadId: input.threadId,
90 - worktreePath: input.worktreePath,
91 - operation,
92 - cause,
93 - ...(input.projectId === undefined ? {} : { projectId: input.projectId }),
94 - ...(input.projectCwd === undefined ? {} : { projectCwd: input.projectCwd }),
95 - });
96 -}
97 -
98 -function mapRunnerError(
99 - input: ProjectSetupScriptRunnerInput,
100 - operation: ProjectSetupScriptOperationError["operation"],
101 -) {
102 - return Effect.mapError((cause: unknown) =>
103 - isProjectSetupScriptRunnerError(cause) ? cause : operationError(input, operation, cause),
104 - );
105 -}
106 -
81 export const make = Effect.gen(function* () {
82 const projectionSnapshotQuery = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;
83 const terminalManager = yield* TerminalManager.TerminalManager;
@@ -111,26 +85,43 @@ export const make = Effect.gen(function* () {
85 const runForThread: ProjectSetupScriptRunner["Service"]["runForThread"] = Effect.fn(
86 "ProjectSetupScriptRunner.runForThread",
87 )(function* (input) {
88 + const errorContext = {
89 + threadId: input.threadId,
90 + worktreePath: input.worktreePath,
91 + ...(input.projectId === undefined ? {} : { projectId: input.projectId }),
92 + ...(input.projectCwd === undefined ? {} : { projectCwd: input.projectCwd }),
93 + };
94 const projectById = input.projectId
115 - ? yield* projectionSnapshotQuery
116 - .getProjectShellById(ProjectId.make(input.projectId))
117 - .pipe(Effect.map(Option.getOrUndefined), mapRunnerError(input, "resolveProject"))
95 + ? yield* projectionSnapshotQuery.getProjectShellById(ProjectId.make(input.projectId)).pipe(
96 + Effect.map(Option.getOrUndefined),
97 + Effect.mapError(
98 + (cause) =>
99 + new ProjectSetupScriptOperationError({
100 + ...errorContext,
101 + operation: "resolveProject",
102 + cause,
103 + }),
104 + ),
105 + )
106 : null;
107 const project =
108 projectById ??
109 (input.projectCwd
122 - ? yield* projectionSnapshotQuery
123 - .getActiveProjectByWorkspaceRoot(input.projectCwd)
124 - .pipe(Effect.map(Option.getOrUndefined), mapRunnerError(input, "resolveProject"))
110 + ? yield* projectionSnapshotQuery.getActiveProjectByWorkspaceRoot(input.projectCwd).pipe(
111 + Effect.map(Option.getOrUndefined),
112 + Effect.mapError(
113 + (cause) =>
114 + new ProjectSetupScriptOperationError({
115 + ...errorContext,
116 + operation: "resolveProject",
117 + cause,
118 + }),
119 + ),
120 + )
121 : null);
122
123 if (!project) {
128 - return yield* new ProjectSetupScriptProjectNotFoundError({
129 - threadId: input.threadId,
130 - worktreePath: input.worktreePath,
131 - ...(input.projectId === undefined ? {} : { projectId: input.projectId }),
132 - ...(input.projectCwd === undefined ? {} : { projectCwd: input.projectCwd }),
133 - });
124 + return yield* new ProjectSetupScriptProjectNotFoundError(errorContext);
125 }
126
127 const script = setupProjectScript(project.scripts);
@@ -155,14 +146,32 @@ export const make = Effect.gen(function* () {
146 worktreePath: input.worktreePath,
147 env,
148 })
158 - .pipe(mapRunnerError(input, "openTerminal"));
149 + .pipe(
150 + Effect.mapError(
151 + (cause) =>
152 + new ProjectSetupScriptOperationError({
153 + ...errorContext,
154 + operation: "openTerminal",
155 + cause,
156 + }),
157 + ),
158 + );
159 yield* terminalManager
160 .write({
161 threadId: input.threadId,
162 terminalId,
163 data: `${script.command}\r`,
164 })
165 - .pipe(mapRunnerError(input, "writeCommand"));
165 + .pipe(
166 + Effect.mapError(
167 + (cause) =>
168 + new ProjectSetupScriptOperationError({
169 + ...errorContext,
170 + operation: "writeCommand",
171 + cause,
172 + }),
173 + ),
174 + );
175
176 return {
177 status: "started",