feat(daemon): Add central TSPM daemon and IPC client; refactor CLI to use daemon and improve monitoring/error handling

This commit is contained in:
2025-08-25 08:52:57 +00:00
parent 1c06fb54b9
commit 3ad8f29e1c
23 changed files with 4761 additions and 3252 deletions

View File

@@ -8,7 +8,7 @@ export enum ErrorType {
PROCESS = 'ProcessError',
RUNTIME = 'RuntimeError',
VALIDATION = 'ValidationError',
UNKNOWN = 'UnknownError'
UNKNOWN = 'UnknownError',
}
// Base error class with type and code support
@@ -18,17 +18,17 @@ export class TspmError extends Error {
details?: Record<string, any>;
constructor(
message: string,
type: ErrorType = ErrorType.UNKNOWN,
message: string,
type: ErrorType = ErrorType.UNKNOWN,
code: string = 'ERR_UNKNOWN',
details?: Record<string, any>
details?: Record<string, any>,
) {
super(message);
this.name = type;
this.type = type;
this.code = code;
this.details = details;
// Preserve proper stack trace
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
@@ -42,19 +42,31 @@ export class TspmError extends Error {
// Specific error classes
export class ConfigError extends TspmError {
constructor(message: string, code: string = 'ERR_CONFIG', details?: Record<string, any>) {
constructor(
message: string,
code: string = 'ERR_CONFIG',
details?: Record<string, any>,
) {
super(message, ErrorType.CONFIG, code, details);
}
}
export class ProcessError extends TspmError {
constructor(message: string, code: string = 'ERR_PROCESS', details?: Record<string, any>) {
constructor(
message: string,
code: string = 'ERR_PROCESS',
details?: Record<string, any>,
) {
super(message, ErrorType.PROCESS, code, details);
}
}
export class ValidationError extends TspmError {
constructor(message: string, code: string = 'ERR_VALIDATION', details?: Record<string, any>) {
constructor(
message: string,
code: string = 'ERR_VALIDATION',
details?: Record<string, any>,
) {
super(message, ErrorType.VALIDATION, code, details);
}
}
@@ -64,11 +76,13 @@ export const handleError = (error: Error | unknown): TspmError => {
if (error instanceof TspmError) {
return error;
}
if (error instanceof Error) {
return new TspmError(error.message, ErrorType.UNKNOWN, 'ERR_UNKNOWN', { originalError: error });
return new TspmError(error.message, ErrorType.UNKNOWN, 'ERR_UNKNOWN', {
originalError: error,
});
}
return new TspmError(String(error), ErrorType.UNKNOWN, 'ERR_UNKNOWN');
};
@@ -78,7 +92,7 @@ export enum LogLevel {
INFO = 1,
WARN = 2,
ERROR = 3,
NONE = 4
NONE = 4,
}
export class Logger {
@@ -128,11 +142,11 @@ export class Logger {
if (this.level <= LogLevel.ERROR) {
const tspmError = handleError(error);
console.error(this.formatMessage(`ERROR: ${tspmError.toString()}`));
// In debug mode, also log stack trace
if (this.level === LogLevel.DEBUG && tspmError.stack) {
console.error(tspmError.stack);
}
}
}
}
}