@@ -18,24 +18,18 @@ import {
1818 type IpcMainInvokeEvent ,
1919 ipcMain ,
2020} from "electron" ;
21+ import type { AcpMessage } from "../../shared/types/session-events" ;
2122import { logger } from "../lib/logger" ;
2223
2324const log = logger . scope ( "session-manager" ) ;
2425
25- type MessageCallback = (
26- message : unknown ,
27- direction : "client" | "agent" ,
28- ) => void ;
29- type MessageDirection = "client" | "agent" ;
26+ type MessageCallback = ( message : unknown ) => void ;
3027
3128class NdJsonTap {
3229 private decoder = new TextDecoder ( ) ;
3330 private buffer = "" ;
3431
35- constructor (
36- private onMessage : MessageCallback ,
37- private direction : MessageDirection ,
38- ) { }
32+ constructor ( private onMessage : MessageCallback ) { }
3933
4034 process ( chunk : Uint8Array ) : void {
4135 this . buffer += this . decoder . decode ( chunk , { stream : true } ) ;
@@ -45,7 +39,7 @@ class NdJsonTap {
4539 for ( const line of lines ) {
4640 if ( ! line . trim ( ) ) continue ;
4741 try {
48- this . onMessage ( JSON . parse ( line ) , this . direction ) ;
42+ this . onMessage ( JSON . parse ( line ) ) ;
4943 } catch {
5044 // Not valid JSON, skip
5145 }
@@ -56,10 +50,9 @@ class NdJsonTap {
5650function createTappedReadableStream (
5751 underlying : ReadableStream < Uint8Array > ,
5852 onMessage : MessageCallback ,
59- direction : MessageDirection ,
6053) : ReadableStream < Uint8Array > {
6154 const reader = underlying . getReader ( ) ;
62- const tap = new NdJsonTap ( onMessage , direction ) ;
55+ const tap = new NdJsonTap ( onMessage ) ;
6356
6457 return new ReadableStream < Uint8Array > ( {
6558 async pull ( controller ) {
@@ -77,9 +70,8 @@ function createTappedReadableStream(
7770function createTappedWritableStream (
7871 underlying : WritableStream < Uint8Array > ,
7972 onMessage : MessageCallback ,
80- direction : MessageDirection ,
8173) : WritableStream < Uint8Array > {
82- const tap = new NdJsonTap ( onMessage , direction ) ;
74+ const tap = new NdJsonTap ( onMessage ) ;
8375
8476 return new WritableStream < Uint8Array > ( {
8577 async write ( chunk ) {
@@ -471,30 +463,31 @@ export class SessionManager {
471463 }
472464 } ;
473465
474- // Emit all raw ACP messages (bidirectional) to the renderer
475- const onAcpMessage = ( message : unknown , direction : "client" | "agent" ) => {
476- emitToRenderer ( {
466+ // Emit all raw ACP messages to the renderer
467+ const onAcpMessage = ( message : unknown ) => {
468+ const acpMessage : AcpMessage = {
477469 type : "acp_message" ,
478- direction,
479470 ts : Date . now ( ) ,
480- message,
481- } ) ;
471+ message : message as AcpMessage [ "message" ] ,
472+ } ;
473+ emitToRenderer ( acpMessage ) ;
482474 } ;
483475
484- // Tap both streams to capture all messages bidirectionally
476+ // Tap both streams to capture all messages
485477 const tappedReadable = createTappedReadableStream (
486478 clientStreams . readable as ReadableStream < Uint8Array > ,
487479 onAcpMessage ,
488- "agent" ,
489480 ) ;
490481
491482 const tappedWritable = createTappedWritableStream (
492483 clientStreams . writable as WritableStream < Uint8Array > ,
493484 onAcpMessage ,
494- "client" ,
495485 ) ;
496486
497487 // Create Client implementation that forwards to renderer
488+ // Note: sessionUpdate is NOT implemented here because session/update
489+ // notifications are already captured by the stream tap and forwarded
490+ // as acp_message events. This avoids duplicate events.
498491 const client : Client = {
499492 async requestPermission (
500493 params : RequestPermissionRequest ,
@@ -511,12 +504,9 @@ export class SessionManager {
511504 } ;
512505 } ,
513506
514- async sessionUpdate ( params : SessionNotification ) : Promise < void > {
515- emitToRenderer ( {
516- type : "session_update" ,
517- ts : Date . now ( ) ,
518- notification : params ,
519- } ) ;
507+ async sessionUpdate ( _params : SessionNotification ) : Promise < void > {
508+ // No-op: session/update notifications are captured by the stream tap
509+ // and forwarded as acp_message events to avoid duplication
520510 } ,
521511 } ;
522512
0 commit comments