feat(01-03): create process types and registry

- ProcessInfo interface for tracking process metadata
- SpawnOptions interface for spawn configuration
- ProcessRegistry class with Map-based storage
- CRUD operations: register, unregister, get, getAll, getByPid, clear
- Additional helpers: updateStatus, size getter
This commit is contained in:
Lukas May
2026-01-30 13:13:06 +01:00
parent e64e243407
commit 40a66175a2
2 changed files with 140 additions and 0 deletions

95
src/process/registry.ts Normal file
View File

@@ -0,0 +1,95 @@
/**
* Process Registry
*
* In-memory registry for tracking managed processes.
* Provides CRUD operations for process metadata.
*
* Note: This is in-memory for now. Phase 2 adds SQLite persistence.
*/
import type { ProcessInfo } from './types.js';
/**
* Registry for tracking managed processes.
* Stores process information in memory using a Map.
*/
export class ProcessRegistry {
private processes: Map<string, ProcessInfo> = new Map();
/**
* Register a new process in the registry.
* @param info - Process information to register
*/
register(info: ProcessInfo): void {
this.processes.set(info.id, info);
}
/**
* Remove a process from the registry.
* @param id - Process ID to unregister
*/
unregister(id: string): void {
this.processes.delete(id);
}
/**
* Get a process by its ID.
* @param id - Process ID to look up
* @returns Process info if found, undefined otherwise
*/
get(id: string): ProcessInfo | undefined {
return this.processes.get(id);
}
/**
* Get all registered processes.
* @returns Array of all process info objects
*/
getAll(): ProcessInfo[] {
return Array.from(this.processes.values());
}
/**
* Find a process by its operating system PID.
* @param pid - OS process ID to search for
* @returns Process info if found, undefined otherwise
*/
getByPid(pid: number): ProcessInfo | undefined {
for (const process of this.processes.values()) {
if (process.pid === pid) {
return process;
}
}
return undefined;
}
/**
* Clear all processes from the registry.
*/
clear(): void {
this.processes.clear();
}
/**
* Update a process's status in the registry.
* @param id - Process ID to update
* @param status - New status value
* @returns true if process was found and updated, false otherwise
*/
updateStatus(id: string, status: ProcessInfo['status']): boolean {
const process = this.processes.get(id);
if (process) {
process.status = status;
return true;
}
return false;
}
/**
* Get the count of registered processes.
* @returns Number of processes in the registry
*/
get size(): number {
return this.processes.size;
}
}

45
src/process/types.ts Normal file
View File

@@ -0,0 +1,45 @@
/**
* Process Management Types
*
* Type definitions for process lifecycle management.
* Used by ProcessRegistry and ProcessManager.
*/
/**
* Process status states
*/
export type ProcessStatus = 'running' | 'stopped' | 'crashed';
/**
* Information about a managed process
*/
export interface ProcessInfo {
/** Unique identifier for the process */
id: string;
/** Operating system process ID */
pid: number;
/** Command that was executed */
command: string;
/** Arguments passed to the command */
args: string[];
/** When the process was started */
startedAt: Date;
/** Current status of the process */
status: ProcessStatus;
}
/**
* Options for spawning a new process
*/
export interface SpawnOptions {
/** Unique identifier for tracking this process */
id: string;
/** Command to execute */
command: string;
/** Arguments to pass to the command */
args?: string[];
/** Working directory for the process */
cwd?: string;
/** Environment variables for the process */
env?: Record<string, string>;
}