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:
2025-08-29 09:43:54 +00:00
parent 0427d38c7d
commit 4db128edaf
10 changed files with 263 additions and 142 deletions

View File

@@ -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
*/