/*
 * Copyright 2026, Jaime Terrats.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { randomBytes } from 'node:crypto';
import { join } from 'node:path';
import { appendJsonlFile, readJsonlFile } from './file-writer.js';
const LESSONS_FILE = 'lessons-operational.jsonl';
function lessonsPath(cwd) {
    return join(cwd, '.setup-agents', 'state', LESSONS_FILE);
}
function nextLessonId() {
    return `lesson-${Date.now()}-${randomBytes(3).toString('hex')}`;
}
export function addOperationalLesson(cwd, lesson) {
    const record = {
        id: nextLessonId(),
        createdAt: new Date().toISOString(),
        ...lesson,
    };
    appendJsonlFile(lessonsPath(cwd), record);
    return record;
}
export function listLessons(cwd) {
    return readJsonlFile(lessonsPath(cwd));
}
export function searchLessons(cwd, keyword) {
    const lower = keyword.toLowerCase();
    return listLessons(cwd).filter((l) => l.errorSignature.toLowerCase().includes(lower) || l.operation.toLowerCase().includes(lower));
}
//# sourceMappingURL=workflow-lessons.js.map