feat(cli): Correct CLI plugin imports and add reset command/IPC to stop processes and clear persisted configs

This commit is contained in:
2025-08-29 16:52:00 +00:00
parent 51aa6eddad
commit cbea3f6187
24 changed files with 112 additions and 45 deletions

View File

@@ -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 };
}
}

View File

@@ -293,6 +293,15 @@ export class TspmDaemon {
},
);
// Reset handler: stops all and clears configs
this.ipcServer.onMessage(
'reset',
async (request: RequestForMethod<'reset'>) => {
const result = await this.tspmInstance.reset();
return result;
},
);
// Daemon management handlers
this.ipcServer.onMessage(
'daemon:status',