refactor: make service defs the setup SSOT
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export type ServiceKind = 'primary' | 'codex' | 'review';
|
||||
|
||||
export interface ServiceDef {
|
||||
/** Stable topology kind used by setup/verify logic */
|
||||
kind: ServiceKind;
|
||||
/** systemd unit name / nohup script name */
|
||||
name: string;
|
||||
/** launchd label */
|
||||
@@ -16,45 +20,76 @@ export interface ServiceDef {
|
||||
extraEnv?: Record<string, string>;
|
||||
}
|
||||
|
||||
interface ServiceTemplate {
|
||||
kind: ServiceKind;
|
||||
name: string;
|
||||
launchdLabel: string;
|
||||
description: string;
|
||||
logName: string;
|
||||
envFileName?: string;
|
||||
assistantName?: string;
|
||||
}
|
||||
|
||||
const SERVICE_TEMPLATES: ServiceTemplate[] = [
|
||||
{
|
||||
kind: 'primary',
|
||||
name: 'ejclaw',
|
||||
launchdLabel: 'com.ejclaw',
|
||||
description: 'EJClaw Personal Assistant (Claude Code)',
|
||||
logName: 'ejclaw',
|
||||
},
|
||||
{
|
||||
kind: 'codex',
|
||||
name: 'ejclaw-codex',
|
||||
launchdLabel: 'com.ejclaw-codex',
|
||||
description: 'EJClaw Codex Assistant',
|
||||
logName: 'ejclaw-codex',
|
||||
envFileName: '.env.codex',
|
||||
assistantName: 'codex',
|
||||
},
|
||||
{
|
||||
kind: 'review',
|
||||
name: 'ejclaw-review',
|
||||
launchdLabel: 'com.ejclaw-review',
|
||||
description: 'EJClaw Codex Review Assistant',
|
||||
logName: 'ejclaw-review',
|
||||
envFileName: '.env.codex-review',
|
||||
assistantName: 'codex',
|
||||
},
|
||||
];
|
||||
|
||||
function materializeServiceDef(
|
||||
projectRoot: string,
|
||||
template: ServiceTemplate,
|
||||
): ServiceDef | null {
|
||||
const environmentFile = template.envFileName
|
||||
? path.join(projectRoot, template.envFileName)
|
||||
: undefined;
|
||||
|
||||
if (environmentFile && !fs.existsSync(environmentFile)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
kind: template.kind,
|
||||
name: template.name,
|
||||
launchdLabel: template.launchdLabel,
|
||||
description: template.description,
|
||||
logName: template.logName,
|
||||
environmentFile,
|
||||
extraEnv: template.assistantName
|
||||
? {
|
||||
ASSISTANT_NAME: template.assistantName,
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export function getServiceDefs(projectRoot: string): ServiceDef[] {
|
||||
const defs: ServiceDef[] = [
|
||||
{
|
||||
name: 'ejclaw',
|
||||
launchdLabel: 'com.ejclaw',
|
||||
description: 'EJClaw Personal Assistant (Claude Code)',
|
||||
logName: 'ejclaw',
|
||||
},
|
||||
];
|
||||
|
||||
const codexEnvPath = path.join(projectRoot, '.env.codex');
|
||||
if (fs.existsSync(codexEnvPath)) {
|
||||
defs.push({
|
||||
name: 'ejclaw-codex',
|
||||
launchdLabel: 'com.ejclaw-codex',
|
||||
description: 'EJClaw Codex Assistant',
|
||||
logName: 'ejclaw-codex',
|
||||
environmentFile: codexEnvPath,
|
||||
extraEnv: {
|
||||
ASSISTANT_NAME: 'codex',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const reviewEnvPath = path.join(projectRoot, '.env.codex-review');
|
||||
if (fs.existsSync(reviewEnvPath)) {
|
||||
defs.push({
|
||||
name: 'ejclaw-review',
|
||||
launchdLabel: 'com.ejclaw-review',
|
||||
description: 'EJClaw Codex Review Assistant',
|
||||
logName: 'ejclaw-review',
|
||||
environmentFile: reviewEnvPath,
|
||||
extraEnv: {
|
||||
ASSISTANT_NAME: 'codex',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return defs;
|
||||
return SERVICE_TEMPLATES.flatMap((template) => {
|
||||
const def = materializeServiceDef(projectRoot, template);
|
||||
return def ? [def] : [];
|
||||
});
|
||||
}
|
||||
|
||||
export function getConfiguredServiceNames(projectRoot: string): string[] {
|
||||
|
||||
Reference in New Issue
Block a user