/**
 * File-backed daemon registry repository.
 *
 * Owns registry path resolution and JSON I/O. Registry semantics live in
 * `RuntimeDaemonRegistryService`.
 */
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { homedir } from 'node:os';
import { dirname, join, resolve } from 'node:path';
import { DaemonRegistrySchema } from './schemas.js';
export class FileDaemonRegistryRepository {
    registryPath;
    constructor(args) {
        this.registryPath = args.registryPath;
    }
    static resolvePath(baseDir = join(homedir(), '.heddle')) {
        return join(resolve(baseDir), 'daemon-registry.json');
    }
    exists() {
        return existsSync(this.registryPath);
    }
    readRaw() {
        if (!this.exists()) {
            return undefined;
        }
        return JSON.parse(readFileSync(this.registryPath, 'utf8'));
    }
    save(registry) {
        mkdirSync(dirname(this.registryPath), { recursive: true });
        writeFileSync(this.registryPath, `${JSON.stringify(DaemonRegistrySchema.parse(registry), null, 2)}\n`, 'utf8');
    }
}
//# sourceMappingURL=registry-repository.js.map