fix(cli): Use server-side start-by-id flow for starting processes

This commit is contained in:
2025-08-29 21:10:01 +00:00
parent 611b756670
commit dfe0677cab
6 changed files with 72 additions and 9 deletions

View File

@@ -20,12 +20,20 @@ export class TspmDaemon {
private socketPath: string;
private heartbeatInterval: NodeJS.Timeout | null = null;
private daemonPidFile: string;
private version: string;
constructor() {
this.tspmInstance = new ProcessManager();
this.socketPath = plugins.path.join(paths.tspmDir, 'tspm.sock');
this.daemonPidFile = plugins.path.join(paths.tspmDir, 'daemon.pid');
this.startTime = Date.now();
// Determine daemon version from package metadata
try {
const proj = new plugins.projectinfo.ProjectInfo(paths.packageDir);
this.version = proj.npm.version || 'unknown';
} catch {
this.version = 'unknown';
}
}
/**
@@ -128,6 +136,29 @@ export class TspmDaemon {
},
);
// Start by id (resolve config on server)
this.ipcServer.onMessage(
'startById',
async (request: RequestForMethod<'startById'>) => {
try {
const config = this.tspmInstance.processConfigs.get(request.id);
if (!config) {
throw new Error(`Process ${request.id} not found`);
}
await this.tspmInstance.setDesiredState(request.id, 'online');
await this.tspmInstance.start(config);
const processInfo = this.tspmInstance.processInfo.get(request.id);
return {
processId: request.id,
pid: processInfo?.pid,
status: processInfo?.status || 'stopped',
};
} catch (error) {
throw new Error(`Failed to start process: ${error.message}`);
}
},
);
this.ipcServer.onMessage(
'stop',
async (request: RequestForMethod<'stop'>) => {
@@ -321,6 +352,7 @@ export class TspmDaemon {
processCount: this.tspmInstance.processes.size,
memoryUsage: memUsage.heapUsed,
cpuUsage: process.cpuUsage().user / 1000000, // Convert to seconds
version: this.version,
};
},
);