fix(client): Improve IPC client robustness and daemon debug logging; update tests and package metadata

This commit is contained in:
2025-08-29 09:29:53 +00:00
parent ebf06d6153
commit 6a8e723c03
10 changed files with 305 additions and 177 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@git.zone/tspm',
version: '3.1.2',
version: '3.1.3',
description: 'a no fuzz process manager'
}

View File

@@ -43,10 +43,14 @@ export class TspmIpcClient {
}
// Create IPC client
const uniqueClientId = `cli-${process.pid}-${Date.now()}-${Math.random()
.toString(36)
.slice(2, 8)}`;
this.ipcClient = plugins.smartipc.SmartIpc.createClient({
id: 'tspm-cli',
socketPath: this.socketPath,
clientId: `cli-${process.pid}`,
clientId: uniqueClientId,
clientOnly: true,
connectRetry: {
enabled: true,
initialDelay: 100,
@@ -54,7 +58,7 @@ export class TspmIpcClient {
maxAttempts: 30,
totalTimeout: 15000,
},
registerTimeoutMs: 8000,
registerTimeoutMs: 15000,
heartbeat: true,
heartbeatInterval: 5000,
heartbeatTimeout: 20000,
@@ -73,9 +77,19 @@ export class TspmIpcClient {
this.isConnected = false;
});
console.log('Connected to TSPM daemon');
// Reflect connection lifecycle on the client state
const markDisconnected = () => {
this.isConnected = false;
};
// Common lifecycle events
this.ipcClient.on('disconnect', markDisconnected as any);
this.ipcClient.on('close', markDisconnected as any);
this.ipcClient.on('end', markDisconnected as any);
this.ipcClient.on('error', markDisconnected as any);
// connected
} catch (error) {
console.error('Failed to connect to daemon:', error);
// surface meaningful error
throw new Error(
'Could not connect to TSPM daemon. Please try running "tspm daemon start" or "tspm enable".',
);
@@ -113,7 +127,15 @@ export class TspmIpcClient {
return response;
} catch (error) {
// Don't try to auto-reconnect, just throw the error
// If the underlying socket disconnected, mark state and surface error
const message = (error as any)?.message || '';
if (
message.includes('Client is not connected') ||
message.includes('ENOTCONN') ||
message.includes('ECONNREFUSED')
) {
this.isConnected = false;
}
throw error;
}
}

View File

@@ -56,6 +56,17 @@ export class TspmDaemon {
heartbeatThrowOnTimeout: false, // Don't throw, emit events instead
});
// Debug hooks for connection troubleshooting
this.ipcServer.on('clientConnect', (clientId: string) => {
console.log(`[IPC] client connected: ${clientId}`);
});
this.ipcServer.on('clientDisconnect', (clientId: string) => {
console.log(`[IPC] client disconnected: ${clientId}`);
});
this.ipcServer.on('error', (err: any) => {
console.error('[IPC] server error:', err?.message || err);
});
// Register message handlers
this.registerHandlers();