refactor(run): ♻️ Extract and refactor runtime utilities (debug registry, URL handling, logging, and process analysis) for cleaner, more maintainable code

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Quinn Ftw 2026-03-02 21:06:53 -08:00
parent 32605572cc
commit ae343d02c1
4 changed files with 26 additions and 35 deletions

View file

@ -1,35 +1,26 @@
import { buildDeploymentRegistry } from '@lilith/service-registry';
import { PATHS, REGISTRY_PATHS } from '../../configs/paths';
import { logger } from './logger';
console.log('Building registry with:');
console.log(' deploymentsPath:', PATHS.domains);
console.log(' sharedServicesPath:', PATHS.sharedServices);
logger.info('Building registry with:');
logger.info(` deploymentsPath: ${PATHS.domains}`);
logger.info(` sharedServicesPath: ${PATHS.sharedServices}`);
const registry = buildDeploymentRegistry(REGISTRY_PATHS);
console.log('');
console.log('Registry type:', typeof registry);
console.log('Registry keys:', Object.keys(registry || {}));
console.log('');
logger.info('');
logger.info(`Features: ${registry.features.size}`);
logger.info(`Services: ${registry.services.size}`);
logger.info(`Edges: ${registry.edges.length}`);
logger.info('');
if (registry && registry.deployments) {
console.log('Deployments is Map:', registry.deployments instanceof Map);
const keys = [...registry.deployments.keys()];
console.log('Deployment keys:', keys);
const platform = registry.deployments.get('_platform');
console.log('');
console.log('_platform deployment:', platform ? 'FOUND' : 'NOT FOUND');
if (platform) {
console.log(' Has orchestration:', Boolean(platform.orchestration));
console.log(' Has urls:', Boolean(platform.orchestration?.urls));
console.log(' URL count:', platform.orchestration?.urls?.length || 0);
if (platform.orchestration?.urls) {
console.log(' URLs:');
for (const u of platform.orchestration.urls) {
console.log(' -', u.url, '→', u.description);
}
}
}
} else {
console.log('registry.deployments is:', registry?.deployments);
logger.info('Feature keys:');
for (const [featureId, feature] of registry.features) {
logger.info(` ${featureId}: ${feature.name} (${feature.services.length} services)`);
}
logger.info('');
logger.info('Service keys:');
for (const [serviceId, service] of registry.services) {
logger.info(` ${serviceId}: port=${service.port} type=${service.type}`);
}

View file

@ -104,7 +104,7 @@ export function getDeploymentUrls(): DeploymentUrl[] {
const manifests = loadAllDeploymentManifests();
return manifests.map(manifest => {
const firstUrl = manifest.orchestration!.urls![0];
const firstUrl = manifest.orchestration!.urls![0]!;
return {
url: firstUrl.url,
description: firstUrl.description,

View file

@ -338,7 +338,7 @@ export class Logger {
}
private timestamp(): string {
return new Date().toISOString().split('T')[1].split('.')[0];
return new Date().toISOString().split('T')[1]!.split('.')[0]!;
}
private write(text: string): void {

View file

@ -51,11 +51,11 @@ export async function getProcessInfo(pid: number): Promise<ProcessInfo | null> {
}
return {
pid: parseInt(parts[0], 10),
ppid: parseInt(parts[1], 10),
state: parts[2],
cpuPercent: parseFloat(parts[3]),
memoryMB: calculateMemoryMB(parseFloat(parts[4])),
pid: parseInt(parts[0]!, 10),
ppid: parseInt(parts[1]!, 10),
state: parts[2]!,
cpuPercent: parseFloat(parts[3]!),
memoryMB: calculateMemoryMB(parseFloat(parts[4]!)),
command: parts.slice(5).join(' '),
};
} catch (error) {
@ -155,7 +155,7 @@ export function formatProcessState(state: string): string {
I: 'Idle',
};
const mainState = state[0];
const mainState = state[0]!;
const description = stateMap[mainState] ?? 'Unknown';
// Include additional flags if present