diff --git a/packages/opencode/src/effect/runner.ts b/packages/opencode/src/effect/runner.ts index cbd2359e91..1e7d4c2966 100644 --- a/packages/opencode/src/effect/runner.ts +++ b/packages/opencode/src/effect/runner.ts @@ -1,10 +1,10 @@ -import { Cause, Deferred, Effect, Exit, Fiber, Schema, Scope, SynchronizedRef } from "effect" +import { Cause, Deferred, Effect, Exit, Fiber, Latch, Schema, Scope, SynchronizedRef } from "effect" export interface Runner { readonly state: State readonly busy: boolean readonly ensureRunning: (work: Effect.Effect) => Effect.Effect - readonly startShell: (work: Effect.Effect, ready?: Deferred.Deferred) => Effect.Effect + readonly startShell: (work: Effect.Effect, ready?: Latch.Latch) => Effect.Effect readonly cancel: Effect.Effect } @@ -19,7 +19,7 @@ interface RunHandle { interface ShellHandle { id: number cancelled: Deferred.Deferred - ready?: Deferred.Deferred + ready?: Latch.Latch fiber: Fiber.Fiber } @@ -107,7 +107,7 @@ export const make = ( const stopShell = (shell: ShellHandle) => Effect.gen(function* () { - if (shell.ready) yield* Deferred.await(shell.ready).pipe(Effect.exit, Effect.asVoid) + if (shell.ready) yield* shell.ready.await.pipe(Effect.exit, Effect.asVoid) yield* Deferred.succeed(shell.cancelled, undefined).pipe(Effect.asVoid) yield* Fiber.interrupt(shell.fiber) }) @@ -137,7 +137,7 @@ export const make = ( }), ).pipe(Effect.flatten) - const startShell = (work: Effect.Effect, ready?: Deferred.Deferred) => + const startShell = (work: Effect.Effect, ready?: Latch.Latch) => SynchronizedRef.modifyEffect( ref, Effect.fnUntraced(function* (st) { diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 22d1da4e8f..4c259e4aef 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -45,7 +45,7 @@ import { AppFileSystem } from "@opencode-ai/core/filesystem" import { Truncate } from "@/tool/truncate" import { decodeDataUrl } from "@/util/data-url" import { Process } from "@/util/process" -import { Cause, Deferred, Effect, Exit, Layer, Option, Scope, Context, Schema } from "effect" +import { Cause, Effect, Exit, Latch, Layer, Option, Scope, Context, Schema } from "effect" import { zod } from "@/util/effect-zod" import { withStatics } from "@/util/schema" import * as EffectLogger from "@opencode-ai/core/effect/logger" @@ -720,10 +720,10 @@ NOTE: At any point in time through this workflow you should feel free to ask the } satisfies MessageV2.TextPart) }) - const shellImpl = Effect.fn("SessionPrompt.shellImpl")(function* (input: ShellInput, ready?: Deferred.Deferred) { + const shellImpl = Effect.fn("SessionPrompt.shellImpl")(function* (input: ShellInput, ready?: Latch.Latch) { return yield* Effect.uninterruptibleMask((restore) => Effect.gen(function* () { - const markReady = ready ? Deferred.succeed(ready, undefined).pipe(Effect.asVoid) : Effect.void + const markReady = ready ? ready.open.pipe(Effect.asVoid) : Effect.void const { msg, part, cwd } = yield* Effect.gen(function* () { const ctx = yield* InstanceState.context const session = yield* sessions.get(input.sessionID) @@ -1509,7 +1509,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the const shell: (input: ShellInput) => Effect.Effect = Effect.fn("SessionPrompt.shell")( function* (input: ShellInput) { - const ready = yield* Deferred.make() + const ready = yield* Latch.make() return yield* state.startShell(input.sessionID, lastAssistant(input.sessionID), shellImpl(input, ready), ready) }, ) diff --git a/packages/opencode/src/session/run-state.ts b/packages/opencode/src/session/run-state.ts index 5ad95c9c7d..9d4986f174 100644 --- a/packages/opencode/src/session/run-state.ts +++ b/packages/opencode/src/session/run-state.ts @@ -1,6 +1,6 @@ import { InstanceState } from "@/effect/instance-state" import { Runner } from "@/effect/runner" -import { Deferred, Effect, Layer, Scope, Context } from "effect" +import { Effect, Latch, Layer, Scope, Context } from "effect" import * as Session from "./session" import { MessageV2 } from "./message-v2" import { SessionID } from "./schema" @@ -18,7 +18,7 @@ export interface Interface { sessionID: SessionID, onInterrupt: Effect.Effect, work: Effect.Effect, - ready?: Deferred.Deferred, + ready?: Latch.Latch, ) => Effect.Effect } @@ -96,7 +96,7 @@ export const layer = Layer.effect( sessionID: SessionID, onInterrupt: Effect.Effect, work: Effect.Effect, - ready?: Deferred.Deferred, + ready?: Latch.Latch, ) { return yield* (yield* runner(sessionID, onInterrupt)).startShell(work, ready) })