feat(cli): Correct CLI plugin imports and add reset command/IPC to stop processes and clear persisted configs
This commit is contained in:
@@ -470,4 +470,47 @@ export class ProcessManager extends EventEmitter {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset: stop all running processes and clear all saved configurations
|
||||
*/
|
||||
public async reset(): Promise<{
|
||||
stopped: string[];
|
||||
removed: string[];
|
||||
failed: Array<{ id: string; error: string }>;
|
||||
}> {
|
||||
this.logger.info('Resetting TSPM: stopping all processes and clearing configs');
|
||||
|
||||
const removed = Array.from(this.processConfigs.keys());
|
||||
const stopped: string[] = [];
|
||||
const failed: Array<{ id: string; error: string }> = [];
|
||||
|
||||
// Attempt to stop all currently running processes with per-id error collection
|
||||
for (const id of Array.from(this.processes.keys())) {
|
||||
try {
|
||||
await this.stop(id);
|
||||
stopped.push(id);
|
||||
} catch (error: any) {
|
||||
failed.push({ id, error: error?.message || String(error) });
|
||||
}
|
||||
}
|
||||
|
||||
// Clear in-memory maps regardless of stop outcomes
|
||||
this.processes.clear();
|
||||
this.processInfo.clear();
|
||||
this.processConfigs.clear();
|
||||
|
||||
// Remove persisted configs
|
||||
try {
|
||||
await this.config.deleteKey(this.configStorageKey);
|
||||
this.logger.debug('Cleared persisted process configurations');
|
||||
} catch (error) {
|
||||
// Fallback: write empty list if deleteKey fails for any reason
|
||||
this.logger.warn('deleteKey failed, writing empty process list instead');
|
||||
await this.saveProcessConfigs().catch(() => {});
|
||||
}
|
||||
|
||||
this.logger.info('TSPM reset complete');
|
||||
return { stopped, removed, failed };
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user