fix(cli): Fix internal imports, centralize IPC types and improve daemon entry/start behavior

This commit is contained in:
2025-08-28 18:34:56 +00:00
parent 529a403c4b
commit 4ee4bcdda2
20 changed files with 95 additions and 72 deletions

View File

@@ -1,9 +1,18 @@
#!/usr/bin/env node
import { startDaemon } from './tspm.daemon.js';
/**
* Daemon entry point - runs process management server
* This should only be run directly by the CLI or as a systemd service
*/
// Start the daemon
startDaemon().catch((error) => {
console.error('Failed to start daemon:', error);
process.exit(1);
});
export { startDaemon } from './tspm.daemon.js';
// When executed directly (not imported), start the daemon
if (import.meta.url === `file://${process.argv[1]}`) {
import('./tspm.daemon.js').then(({ startDaemon }) => {
startDaemon().catch((error) => {
console.error('Failed to start daemon:', error);
process.exit(1);
});
});
}

View File

@@ -1,11 +1,7 @@
import * as plugins from '../plugins.js';
import { EventEmitter } from 'events';
import * as paths from '../paths.js';
import {
ProcessMonitor,
type IMonitorConfig,
} from './processmonitor.js';
import { type IProcessLog } from './processwrapper.js';
import { ProcessMonitor } from './processmonitor.js';
import { TspmConfig } from './tspm.config.js';
import {
Logger,
@@ -14,23 +10,14 @@ import {
ValidationError,
handleError,
} from '../shared/common/utils.errorhandler.js';
import type {
IProcessConfig,
IProcessInfo,
IProcessLog,
IMonitorConfig
} from '../shared/protocol/ipc.types.js';
export interface IProcessConfig extends IMonitorConfig {
id: string; // Unique identifier for the process
autorestart: boolean; // Whether to restart the process automatically on crash
watch?: boolean; // Whether to watch for file changes and restart
watchPaths?: string[]; // Paths to watch for changes
}
export interface IProcessInfo {
id: string;
pid?: number;
status: 'online' | 'stopped' | 'errored';
memory: number;
cpu?: number;
uptime?: number;
restarts: number;
}
export class ProcessManager extends EventEmitter {
public processes: Map<string, ProcessMonitor> = new Map();

View File

@@ -1,18 +1,8 @@
import * as plugins from '../plugins.js';
import { EventEmitter } from 'events';
import { ProcessWrapper, type IProcessLog } from './processwrapper.js';
import { ProcessWrapper } from './processwrapper.js';
import { Logger, ProcessError, handleError } from '../shared/common/utils.errorhandler.js';
export interface IMonitorConfig {
name?: string; // Optional name to identify the instance
projectDir: string; // Directory where the command will run
command: string; // Full command to run (e.g., "npm run xyz")
args?: string[]; // Optional: arguments for the command
memoryLimitBytes: number; // Maximum allowed memory (in bytes) for the process group
monitorIntervalMs?: number; // Interval (in ms) at which memory is checked (default: 5000)
env?: NodeJS.ProcessEnv; // Optional: custom environment variables
logBufferSize?: number; // Optional: number of log lines to keep (default: 100)
}
import type { IMonitorConfig, IProcessLog } from '../shared/protocol/ipc.types.js';
export class ProcessMonitor extends EventEmitter {
private processWrapper: ProcessWrapper | null = null;

View File

@@ -1,6 +1,7 @@
import * as plugins from '../plugins.js';
import { EventEmitter } from 'events';
import { Logger, ProcessError, handleError } from '../shared/common/utils.errorhandler.js';
import type { IProcessLog } from '../shared/protocol/ipc.types.js';
export interface IProcessWrapperOptions {
command: string;
@@ -11,14 +12,6 @@ export interface IProcessWrapperOptions {
logBuffer?: number; // Number of log lines to keep in memory (default: 100)
}
export interface IProcessLog {
timestamp: Date;
type: 'stdout' | 'stderr' | 'system';
message: string;
seq: number;
runId: string;
}
export class ProcessWrapper extends EventEmitter {
private process: plugins.childProcess.ChildProcess | null = null;
private options: IProcessWrapperOptions;