@@ -7,7 +7,7 @@ import type {
77 SessionCommandResult ,
88 SessionServerMessage ,
99} from "./types" ;
10- import { HUNK_SESSION_SOCKET_PATH , resolveHunkMcpConfig } from "./config" ;
10+ import { HUNK_SESSION_SOCKET_PATH , resolveHunkMcpConfig , type ResolvedHunkMcpConfig } from "./config" ;
1111import { isHunkDaemonHealthy , isLoopbackPortReachable , launchHunkDaemon , waitForHunkDaemonHealth } from "./daemonLauncher" ;
1212
1313const DAEMON_LAUNCH_COOLDOWN_MS = 5_000 ;
@@ -31,7 +31,6 @@ export class HunkHostClient {
3131 private startupPromise : Promise < void > | null = null ;
3232 private lastDaemonLaunchStartedAt = 0 ;
3333 private lastConnectionWarning : string | null = null ;
34- private readonly config = resolveHunkMcpConfig ( ) ;
3534
3635 constructor (
3736 private readonly registration : HunkSessionRegistration ,
@@ -73,13 +72,18 @@ export class HunkHostClient {
7372 this . websocket = null ;
7473 }
7574
75+ private resolveConfig ( ) {
76+ return resolveHunkMcpConfig ( ) ;
77+ }
78+
7679 private async ensureDaemonAndConnect ( ) {
77- await this . ensureDaemonAvailable ( ) ;
78- this . connect ( ) ;
80+ const config = this . resolveConfig ( ) ;
81+ await this . ensureDaemonAvailable ( config ) ;
82+ this . connect ( config ) ;
7983 }
8084
81- private async ensureDaemonAvailable ( ) {
82- if ( await isHunkDaemonHealthy ( this . config ) ) {
85+ private async ensureDaemonAvailable ( config : ResolvedHunkMcpConfig ) {
86+ if ( await isHunkDaemonHealthy ( config ) ) {
8387 this . lastConnectionWarning = null ;
8488 return ;
8589 }
@@ -91,7 +95,7 @@ export class HunkHostClient {
9195 }
9296
9397 const ready = await waitForHunkDaemonHealth ( {
94- config : this . config ,
98+ config,
9599 timeoutMs : shouldLaunch ? DAEMON_STARTUP_TIMEOUT_MS : 1_500 ,
96100 } ) ;
97101
@@ -100,16 +104,16 @@ export class HunkHostClient {
100104 return ;
101105 }
102106
103- const portReachable = await isLoopbackPortReachable ( this . config ) ;
107+ const portReachable = await isLoopbackPortReachable ( config ) ;
104108 if ( portReachable ) {
105109 throw new Error (
106- `Hunk MCP port ${ this . config . host } :${ this . config . port } is already in use by another process. ` +
110+ `Hunk MCP port ${ config . host } :${ config . port } is already in use by another process. ` +
107111 `Stop the conflicting process or set HUNK_MCP_PORT to a different loopback port.` ,
108112 ) ;
109113 }
110114
111115 throw new Error (
112- `Timed out waiting for the Hunk MCP daemon on ${ this . config . host } :${ this . config . port } . ` +
116+ `Timed out waiting for the Hunk MCP daemon on ${ config . host } :${ config . port } . ` +
113117 `Hunk will retry in the background.` ,
114118 ) ;
115119 }
@@ -128,12 +132,12 @@ export class HunkHostClient {
128132 } ) ;
129133 }
130134
131- private connect ( ) {
135+ private connect ( config : ResolvedHunkMcpConfig ) {
132136 if ( this . stopped || this . websocket ) {
133137 return ;
134138 }
135139
136- const websocket = new WebSocket ( `${ this . config . wsOrigin } ${ HUNK_SESSION_SOCKET_PATH } ` ) ;
140+ const websocket = new WebSocket ( `${ config . wsOrigin } ${ HUNK_SESSION_SOCKET_PATH } ` ) ;
137141 this . websocket = websocket ;
138142
139143 websocket . onopen = ( ) => {
0 commit comments