BREAKING CHANGE(cli): Add persistent process registration (tspm add), alias remove, and change start to use saved process IDs (breaking CLI behavior)
This commit is contained in:
@@ -34,6 +34,42 @@ export class ProcessManager extends EventEmitter {
|
||||
this.loadProcessConfigs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a process configuration without starting it.
|
||||
* Returns the assigned numeric sequential id as string.
|
||||
*/
|
||||
public async add(configInput: Omit<IProcessConfig, 'id'> & { id?: string }): Promise<string> {
|
||||
// Determine next numeric id
|
||||
const nextId = this.getNextSequentialId();
|
||||
|
||||
const config: IProcessConfig = {
|
||||
id: String(nextId),
|
||||
name: configInput.name || `process-${nextId}`,
|
||||
command: configInput.command,
|
||||
args: configInput.args,
|
||||
projectDir: configInput.projectDir,
|
||||
memoryLimitBytes: configInput.memoryLimitBytes || 512 * 1024 * 1024,
|
||||
monitorIntervalMs: configInput.monitorIntervalMs,
|
||||
env: configInput.env,
|
||||
logBufferSize: configInput.logBufferSize,
|
||||
autorestart: configInput.autorestart ?? true,
|
||||
watch: configInput.watch,
|
||||
watchPaths: configInput.watchPaths,
|
||||
};
|
||||
|
||||
// Store config and initial info
|
||||
this.processConfigs.set(config.id, config);
|
||||
this.processInfo.set(config.id, {
|
||||
id: config.id,
|
||||
status: 'stopped',
|
||||
memory: 0,
|
||||
restarts: 0,
|
||||
});
|
||||
|
||||
await this.saveProcessConfigs();
|
||||
return config.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a new process with the given configuration
|
||||
*/
|
||||
@@ -342,6 +378,20 @@ export class ProcessManager extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute next sequential numeric id based on existing configs
|
||||
*/
|
||||
private getNextSequentialId(): number {
|
||||
let maxId = 0;
|
||||
for (const id of this.processConfigs.keys()) {
|
||||
const n = parseInt(id, 10);
|
||||
if (!isNaN(n)) {
|
||||
maxId = Math.max(maxId, n);
|
||||
}
|
||||
}
|
||||
return maxId + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all process configurations to config storage
|
||||
*/
|
||||
|
@@ -171,6 +171,31 @@ export class TspmDaemon {
|
||||
);
|
||||
|
||||
// Query handlers
|
||||
this.ipcServer.onMessage(
|
||||
'add',
|
||||
async (request: RequestForMethod<'add'>) => {
|
||||
try {
|
||||
const id = await this.tspmInstance.add(request.config as any);
|
||||
const config = this.tspmInstance.processConfigs.get(id)!;
|
||||
return { id, config };
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to add process: ${error.message}`);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
this.ipcServer.onMessage(
|
||||
'remove',
|
||||
async (request: RequestForMethod<'remove'>) => {
|
||||
try {
|
||||
await this.tspmInstance.delete(request.id);
|
||||
return { success: true, message: `Process ${request.id} deleted successfully` };
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to remove process: ${error.message}`);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
this.ipcServer.onMessage(
|
||||
'list',
|
||||
async (request: RequestForMethod<'list'>) => {
|
||||
|
Reference in New Issue
Block a user