| ... | ... | @@ -8,8 +8,9 @@ import { |
| 8 | 8 | type ThreadId, |
| 9 | 9 | type TurnId, |
| 10 | 10 | } from "@t3tools/contracts"; |
| 11 | | import { Cache, Duration, Effect, Layer, Option, Queue, Stream } from "effect"; |
| 11 | import { Cache, Cause, Duration, Effect, Layer, Option, Queue, Stream } from "effect"; |
| 12 | 12 | |
| 13 | import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts"; |
| 13 | 14 | import { ProviderService } from "../../provider/Services/ProviderService.ts"; |
| 14 | 15 | import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts"; |
| 15 | 16 | import { |
| ... | ... | @@ -33,24 +34,6 @@ function toNonEmptyProviderInput(value: string | undefined): string | undefined |
| 33 | 34 | return normalized && normalized.length > 0 ? normalized : undefined; |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | | function resolveEffectiveThreadCwd(input: { |
| 37 | | readonly thread: { |
| 38 | | readonly projectId: string; |
| 39 | | readonly worktreePath: string | null; |
| 40 | | }; |
| 41 | | readonly projects: ReadonlyArray<{ |
| 42 | | readonly id: string; |
| 43 | | readonly workspaceRoot: string; |
| 44 | | }>; |
| 45 | | }): string | undefined { |
| 46 | | const worktreeCwd = input.thread.worktreePath ?? undefined; |
| 47 | | if (worktreeCwd) { |
| 48 | | return worktreeCwd; |
| 49 | | } |
| 50 | | |
| 51 | | return input.projects.find((project) => project.id === input.thread.projectId)?.workspaceRoot; |
| 52 | | } |
| 53 | | |
| 54 | 37 | function mapProviderSessionStatusToOrchestrationStatus( |
| 55 | 38 | status: "connecting" | "ready" | "running" | "error" | "closed", |
| 56 | 39 | ): OrchestrationSession["status"] { |
| ... | ... | @@ -161,7 +144,7 @@ const make = Effect.gen(function* () { |
| 161 | 144 | thread.session?.providerName === "codex" || thread.session?.providerName === "claudeCode" |
| 162 | 145 | ? thread.session.providerName |
| 163 | 146 | : undefined; |
| 164 | | const effectiveCwd = resolveEffectiveThreadCwd({ |
| 147 | const effectiveCwd = resolveThreadWorkspaceCwd({ |
| 165 | 148 | thread, |
| 166 | 149 | projects: readModel.projects, |
| 167 | 150 | }); |
| ... | ... | @@ -353,12 +336,25 @@ const make = Effect.gen(function* () { |
| 353 | 336 | } |
| 354 | 337 | }); |
| 355 | 338 | |
| 339 | const processDomainEventSafely = (event: ProviderIntentEvent) => |
| 340 | processDomainEvent(event).pipe( |
| 341 | Effect.catchCause((cause) => { |
| 342 | if (Cause.hasInterruptsOnly(cause)) { |
| 343 | return Effect.failCause(cause); |
| 344 | } |
| 345 | return Effect.logWarning("provider command reactor failed to process event", { |
| 346 | eventType: event.type, |
| 347 | cause: Cause.pretty(cause), |
| 348 | }); |
| 349 | }), |
| 350 | ); |
| 351 | |
| 356 | 352 | const start: ProviderCommandReactorShape["start"] = Effect.gen(function* () { |
| 357 | 353 | const queue = yield* Queue.unbounded<ProviderIntentEvent>(); |
| 358 | 354 | yield* Effect.addFinalizer(() => Queue.shutdown(queue).pipe(Effect.asVoid)); |
| 359 | 355 | |
| 360 | 356 | yield* Effect.forkScoped( |
| 361 | | Effect.forever(Queue.take(queue).pipe(Effect.flatMap(processDomainEvent))), |
| 357 | Effect.forever(Queue.take(queue).pipe(Effect.flatMap(processDomainEventSafely))), |
| 362 | 358 | ); |
| 363 | 359 | |
| 364 | 360 | yield* Effect.forkScoped( |