import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { AgentSkillSchemas } from './schemas.js';
/**
 * File-backed workspace activation state for Agent Skills.
 *
 * The repository stores only user consent/status metadata. Skill definitions
 * stay in their original `.agents/skills` or built-in package locations.
 */
export class FileAgentSkillActivationRepository {
    filePath;
    constructor(options) {
        this.filePath = FileAgentSkillActivationRepository.resolvePath(options.stateRoot);
    }
    static resolvePath(stateRoot) {
        return join(stateRoot, 'skills', 'activation.json');
    }
    read() {
        if (!existsSync(this.filePath)) {
            return AgentSkillSchemas.emptyActivationStore();
        }
        try {
            return AgentSkillSchemas.parseActivationStore(JSON.parse(readFileSync(this.filePath, 'utf8')));
        }
        catch {
            return AgentSkillSchemas.emptyActivationStore();
        }
    }
    write(store) {
        mkdirSync(dirname(this.filePath), { recursive: true });
        writeFileSync(this.filePath, `${JSON.stringify(AgentSkillSchemas.parseActivationStore(store), null, 2)}\n`, 'utf8');
    }
}
//# sourceMappingURL=activation-repository.js.map