githubnext/chopinPublic

Let's compose rich plans together

Return Pi structured output from a terminating extension tool #196

Mergedlavaman131merged 2 commits intofeat/harness-5-pi-e2efromrefs/pull/196/head
ConversationFiles changed
8 files changed+429-168
StackedSplit
apps/server/package.json+2 −0
apps/server/src/harness/pi.contract.test.ts+78 −2
apps/server/src/harness/pi/adapter.test.ts+188 −69
apps/server/src/harness/pi/adapter.ts+116 −67
apps/server/src/harness/pi/model-stub.ts+13 −3
bun.lock+21 −17
docs/self-hosting.md+9 −10
package.json+2 −0

Comments on earlier or unavailable lines

[Earlier chat messages are included in that prompt](https://github.com/githubnext/chopin/blob/6a8fde021f02f924666a205d729e686d4b43c095/apps/server/src/chat/service.ts#L815-L831). If someone copies the sentence into chat, Pi could get the ‘submit result’ tool during a normal reply and stop before answering. [Those tool calls are hidden here](https://github.com/githubnext/chopin/blob/6a8fde021f02f924666a205d729e686d4b43c095/apps/server/src/harness/pi/adapter.ts#L113-L119), so it would be hard to spot. Could we add a test with the sentence in earlier chat?

apps/server/src/harness/pi/adapter.ts:67head6a8fde0
Author

Good catch, confirmed: `plannerInstructions()` puts the chat backscroll into Pi's system prompt, so quoting the sentence enabled the tool. Fixed in 89c13a7. Each Pi session now gets its own extension state, and the session wrapper sets it from the turn's `responseFormat` before the turn starts. Prompt text no longer affects it.

Added the test you asked for: `pi.contract.test.ts` runs a plain turn through the real Pi loop with `PI_RESULT_INSTRUCTION` quoted as earlier chat and checks that the tool isn't offered and the turn still answers. Against the old adapter it fails with an empty reply (the turn ended on the hidden tool call). There's also a unit test for the per-turn state. I rebased onto #195's d330c0f.

Assistant-workflow: inline Assistant-verification: bun test contract passed: plain turn with the instruction in earlier chat is answered normally and never offered the tool Assistant-verification: red check passed: same test fails against the previous adapter Assistant-verification: bun test passed: 1605 pass, 2 skip, 0 fail; bun run types and bun run ci passed

apps/server/src/harness/pi/adapter.ts:67head6a8fde0