import { resolve } from 'node:path';
import { MemoryCatalogService } from './catalog.js';
import { MemoryMaintenanceRepository } from './maintenance-repository.js';
import { MemoryNoteService } from './note-service.js';
/**
 * Owns host-facing memory status and note visibility reads.
 */
export class MemoryVisibilityService {
    memoryRoot;
    notes;
    maintenance;
    catalog;
    constructor(memoryRoot, notes = new MemoryNoteService(memoryRoot), maintenance = new MemoryMaintenanceRepository(memoryRoot), catalog = new MemoryCatalogService(memoryRoot)) {
        this.memoryRoot = memoryRoot;
        this.notes = notes;
        this.maintenance = maintenance;
        this.catalog = catalog;
    }
    async loadStatus(recentRunLimit = 5) {
        const [notes, pending, latestRuns] = await Promise.all([
            this.notes.list(),
            this.maintenance.readPendingCandidates(),
            this.maintenance.readRecentMaintenanceRuns(recentRunLimit),
        ]);
        const catalog = this.catalog.validateShape();
        return {
            memoryRoot: resolve(this.memoryRoot),
            catalog: {
                ok: catalog.ok,
                missing: catalog.missing,
            },
            notes: {
                count: notes.length,
            },
            candidates: {
                pending: pending.length,
            },
            runs: {
                latest: latestRuns,
            },
        };
    }
    async listNotePaths(path) {
        return await this.notes.list({ path });
    }
    async readNote(input) {
        return await this.notes.read(input);
    }
    async searchNotes(input) {
        return await this.notes.search(input);
    }
    async readRecentMaintenanceRuns(limit = 5) {
        return await this.maintenance.readRecentMaintenanceRuns(limit);
    }
}
//# sourceMappingURL=visibility.js.map