diff --git a/packages/effect-codex-app-server/src/protocol.ts b/packages/effect-codex-app-server/src/protocol.ts index 17bfaed2b64c..e87f5e9d8ae4 100644 --- a/packages/effect-codex-app-server/src/protocol.ts +++ b/packages/effect-codex-app-server/src/protocol.ts @@ -157,7 +157,6 @@ export const makeCodexAppServerPatchedProtocol = Effect.fn("makeCodexAppServerPa const incomingRequests = yield* Queue.unbounded(); const pending = yield* Ref.make(new Map()); const nextRequestId = yield* Ref.make(1); - const remainder = yield* Ref.make(""); const terminationHandled = yield* Ref.make(false); const logProtocol = (event: CodexAppServerProtocolLogEvent) => { @@ -353,31 +352,18 @@ export const makeCodexAppServerPatchedProtocol = Effect.fn("makeCodexAppServerPa yield* options.stdio.stdin.pipe( Stream.decodeText(), - Stream.runForEach((chunk) => - Ref.modify(remainder, (current) => { - const combined = current + chunk; - const lines = combined.split("\n"); - const nextRemainder = lines.pop() ?? ""; - return [lines.map((line) => line.replace(/\r$/, "")), nextRemainder] as const; - }).pipe(Effect.flatMap((lines) => Effect.forEach(lines, handleLine, { discard: true }))), - ), + Stream.splitLines, + Stream.runForEach(handleLine), Effect.matchEffect({ onFailure: (error) => handleTermination(() => Effect.succeed(normalizeIncomingError(error, "read-input-stream")), ), onSuccess: () => - Ref.get(remainder).pipe( - Effect.flatMap((line) => (line.trim().length === 0 ? Effect.void : handleLine(line))), - Effect.matchEffect({ - onFailure: (error) => handleTermination(() => Effect.succeed(error)), - onSuccess: () => - handleTermination( - () => - options.terminationError ?? - Effect.succeed(new CodexError.CodexAppServerInputStreamEndedError({})), - ), - }), + handleTermination( + () => + options.terminationError ?? + Effect.succeed(new CodexError.CodexAppServerInputStreamEndedError({})), ), }), Effect.forkScoped,