GeezerVison is showing github.com — fix(acp): a blank line from an ACP agent no longer ends the session (… · pingdotgg/t3code@db0ae7b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/effect-acp/src/protocol.test.ts +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -531,6 +531,31 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => { | 531 | 531 | }), | 532 | 532 | ); | 533 | 533 |
| | 534 | + it.effect("skips blank lines between agent messages", () => | | 535 | + Effect.gen(function* () { | | 536 | + const { stdio, input } = yield* makeInMemoryStdio(); | | 537 | + const outcome = yield* Deferred.make<string>(); | | 538 | + const transport = yield* AcpProtocol.makeAcpPatchedProtocol({ | | 539 | + stdio, | | 540 | + serverRequestMethods: new Set(), | | 541 | + onTermination: (error) => Deferred.succeed(outcome, error._tag).pipe(Effect.asVoid), | | 542 | + }); | | 543 | + yield* transport.incoming.pipe( | | 544 | + Stream.runForEach((notification) => Deferred.succeed(outcome, notification._tag)), | | 545 | + Effect.forkScoped, | | 546 | + ); | | 547 | + | | 548 | + const update = encodeUnknownJsonString({ | | 549 | + jsonrpc: "2.0", | | 550 | + method: "session/update", | | 551 | + params: { sessionId: "session-1", update: { sessionUpdate: "plan", entries: [] } }, | | 552 | + }); | | 553 | + yield* Queue.offer(input, encoder.encode(`\n\r\n \t\n${update}\n\n`)); | | 554 | + | | 555 | + assert.equal(yield* Deferred.await(outcome), "SessionUpdate"); | | 556 | + }), | | 557 | + ); | | 558 | + | 534 | 559 | it.effect("logs decode failures without copying the cause or wire payload", () => | 535 | 560 | Effect.gen(function* () { | 536 | 561 | const secret = "acp-wire-secret-sentinel"; | |
Collapse file Copy file name to clipboardExpand all lines: packages/effect-acp/src/protocol.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -173,7 +173,7 @@ const decodeElicitationComplete = Schema.decodeUnknownEffect( | 173 | 173 | ); | 174 | 174 | const parserFactory = RpcSerialization.ndJsonRpc(); | 175 | 175 | // ndJsonRpc skips lines that are not JSON. A malformed agent line has to end the | 176 | | -// session, so frames are split here and each one goes through the strict codec. | | 176 | +// session, so frames are split here and each nonblank one goes through the strict codec. | 177 | 177 | const makeStrictNdJsonRpcParser = () => { | 178 | 178 | const codec = RpcSerialization.jsonRpc().makeUnsafe(); | 179 | 179 | const decoder = new TextDecoder(); | @@ -197,7 +197,7 @@ const makeStrictNdJsonRpcParser = () => { | 197 | 197 | } | 198 | 198 | const lines = (buffer + chunk.slice(0, lastNewline)).split("\n"); | 199 | 199 | buffer = chunk.slice(lastNewline + 1); | 200 | | - return lines.flatMap(decodeLine); | | 200 | + return lines.flatMap((line) => (line.trim() === "" ? [] : decodeLine(line))); | 201 | 201 | }, | 202 | 202 | // A truncated final line is left to the exit status, which explains a crash better. | 203 | 203 | end: (): ReadonlyArray<AcpDecodedWireMessage> => { | |
|