/*
 * 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 { pluginWorkflowLines, riskScaleLines } from './mdc-generator.js';
import { demandLoadedSkillSection, managedBlock, profileMetadataSection, stripMdcFrontmatter } from './shared.js';
import { getDemandLoadedSkillReferences } from './skill-generator.js';
/** Generates `.github/copilot-instructions.md` content. */
export function generateCopilotInstructions(profiles, version) {
    const base = [
        '## General Principles',
        '- Always read existing code before suggesting changes.',
        '- Prefer editing existing files over creating new ones.',
        '- Follow the coding conventions already present in this project.',
        '- Write concise, self-documenting code. Avoid unnecessary comments.',
        '',
        '## Code Quality',
        '- Ensure all new code is covered by tests.',
        '- Do not introduce linter errors or suppress warnings.',
        '- Handle errors explicitly; never swallow exceptions silently.',
        '',
        '## Security',
        '- Never hardcode credentials, tokens, or sensitive data.',
        '- Use environment variables or secret managers for sensitive values.',
        '',
        ...riskScaleLines(),
        '',
        ...pluginWorkflowLines(),
    ];
    const profileSections = profiles.flatMap((p) => [
        '',
        '---',
        '',
        profileMetadataSection(p),
        '',
        '---',
        '',
        stripMdcFrontmatter(p.ruleContent()).trimStart(),
    ]);
    const skillSection = demandLoadedSkillSection(getDemandLoadedSkillReferences(profiles.map((p) => p.id)));
    return [
        '# GitHub Copilot Instructions',
        `<!-- setup-agents: ${version} -->`,
        '',
        managedBlock('copilot-instructions', version, [...base, ...profileSections, ...(skillSection ? ['', '---', '', skillSection] : [])].join('\n')),
    ].join('\n');
}
//# sourceMappingURL=copilot-generator.js.map