The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { ThreadId } from "@t3tools/contracts"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Option from "effect/Option"; |
| 4 | |
| 5 | import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts"; |
| 6 | import * as ProjectService from "./ProjectService.ts"; |
| 7 | |
| 8 | /** The directory a thread works in, or undefined when the thread or its project is gone. */ |
| 9 | export const threadWorkspaceRoot = Effect.fn("threadWorkspaceRoot")( |
| 10 | function* (threadId: ThreadId) { |
| 11 | const threads = yield* ThreadManagementService.ThreadManagementService; |
| 12 | const projects = yield* ProjectService.ProjectService; |
| 13 | const shell = yield* threads.getThreadShell(threadId); |
| 14 | if (shell === null) return undefined; |
| 15 | if (shell.worktreePath) return shell.worktreePath; |
| 16 | return Option.getOrUndefined(yield* projects.getById(shell.projectId))?.workspaceRoot; |
| 17 | }, |
| 18 | Effect.orElseSucceed(() => undefined), |
| 19 | ); |