move opencode's turn output into its own sidecar
The second copy of the same problem. The opencode sidecar reported raw ChatEvents and officer translated them, buffered the assistant text and wrote every durable message to chat_session_events — so an officer restart mid-turn lost whatever the model had produced since the last write, and `connect.ts` dropped the events that arrived while it was down without a word. Both harnesses speak ChatEvents, so the sidecar reuses the agent's session log verbatim: translate, commit, then deliver the finished message with its cursor id as `opencode:message`. Officer folds it into the in-memory transcript and relays it, exactly as it now does for claude — `createEventHandler` (166 lines, a duplicate of turn-stream.ts) and `emitToSession` are gone, and nothing in officer writes to chat_session_events any more. `opencode:event` stops being a wire event; it is the runner's internal report to the sidecar it runs in, typed as such so it cannot leak back onto the socket. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ import type {
|
||||
VncSessionInfo,
|
||||
} from './sidecar/protocol';
|
||||
import type { SidecarRegistration } from './sidecar/registration-protocol';
|
||||
import type { ChatEvent, TurnMessage } from './api/chat/types';
|
||||
import type { TurnMessage } from './api/chat/types';
|
||||
|
||||
// ── Types ──
|
||||
|
||||
@@ -298,14 +298,11 @@ export function killOpenCode(sessionKey: string): void {
|
||||
sendFire('opencode', { type: 'opencode:kill', id: nextId(), sessionKey });
|
||||
}
|
||||
|
||||
export function onOpenCodeEvent(handler: (sessionKey: string, event: ChatEvent) => void): () => void {
|
||||
return on('opencode:event', (msg) => {
|
||||
if (msg.type === 'opencode:event') {
|
||||
handler(
|
||||
(msg as SidecarEvent & { type: 'opencode:event' }).sessionKey,
|
||||
(msg as SidecarEvent & { type: 'opencode:event' }).event,
|
||||
);
|
||||
}
|
||||
export function onOpenCodeMessage(handler: (sessionKey: string, msg: TurnMessage, seq?: number) => void): () => void {
|
||||
return on('opencode:message', (ev) => {
|
||||
if (ev.type !== 'opencode:message') return;
|
||||
const msg = ev as SidecarEvent & { type: 'opencode:message' };
|
||||
handler(msg.sessionKey, msg.msg, msg.seq);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user