import { GuardianDaemon } from './core.js'; import { getApiKey, getApiUrl, getProjectId } from '../utils/config.js'; import { loadManifest } from '../utils/manifest.js'; import { DaemonConfig } from './types.js'; /** * Factory for creating a GuardianDaemon with resolved configuration. */ export async function createDaemon(options: { project?: string; path?: string; noBridge?: boolean; verbose?: boolean; }): Promise { const apiUrl = getApiUrl(); let projectId = options.project; if (!projectId) { const manifest = await loadManifest(); if (manifest) projectId = manifest.project_id; } if (!projectId) projectId = getProjectId(); if (!projectId) { throw new Error('No project ID found. Run "rigstate link" or use --project .'); } const apiKey = getApiKey(); if (!apiKey) { throw new Error('Not authenticated. Run "rigstate login" first.'); } const config: DaemonConfig = { projectId, apiUrl, apiKey, watchPath: options.path || process.cwd(), checkOnChange: true, bridgeEnabled: !options.noBridge, verbose: !!options.verbose }; return new GuardianDaemon(config); }