@@ -13,6 +13,7 @@ import { spawn, execSync, type ChildProcess } from "node:child_process";
1313import { createInterface } from "node:readline" ;
1414import { EventEmitter } from "node:events" ;
1515import { appendFileSync } from "node:fs" ;
16+ import { StateDirResolver } from "./state-dir" ;
1617import type { BridgeMessage } from "./types" ;
1718import type { ServerWebSocket } from "bun" ;
1819import {
@@ -56,8 +57,6 @@ interface PendingServerResponse {
5657 timestamp : number ;
5758}
5859
59- const LOG_FILE = "/tmp/agentbridge.log" ;
60-
6160interface PendingRequest {
6261 method : AppServerTrackedRequestMethod ;
6362 threadId ?: string ;
@@ -76,6 +75,7 @@ export class CodexAdapter extends EventEmitter {
7675 private nextInjectionId = - 1 ;
7776 private appPort : number ;
7877 private proxyPort : number ;
78+ private readonly logFile : string ;
7979 private tuiConnId = 0 ; // tracks which TUI connection is "current" (primary)
8080 private connIdCounter = 0 ; // monotonically increasing counter for unique conn IDs
8181 // Secondary (picker) connections: each gets its own dedicated app-server WS
@@ -107,10 +107,11 @@ export class CodexAdapter extends EventEmitter {
107107 // Generation counter to prevent stale app-server close handlers from interfering
108108 private appServerGeneration = 0 ;
109109
110- constructor ( appPort = 4500 , proxyPort = 4501 ) {
110+ constructor ( appPort = 4500 , proxyPort = 4501 , logFile = new StateDirResolver ( ) . logFile ) {
111111 super ( ) ;
112112 this . appPort = appPort ;
113113 this . proxyPort = proxyPort ;
114+ this . logFile = logFile ;
114115 }
115116
116117 get appServerUrl ( ) { return `ws://127.0.0.1:${ this . appPort } ` ; }
@@ -1240,6 +1241,6 @@ export class CodexAdapter extends EventEmitter {
12401241 private log ( msg : string ) {
12411242 const line = `[${ new Date ( ) . toISOString ( ) } ] [CodexAdapter] ${ msg } \n` ;
12421243 process . stderr . write ( line ) ;
1243- try { appendFileSync ( LOG_FILE , line ) ; } catch { }
1244+ try { appendFileSync ( this . logFile , line ) ; } catch { }
12441245 }
12451246}
0 commit comments