/*
 * 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 { ALL_PROFILES, PROFILE_ID_ALIASES } from './catalog.js';
const CAPABILITY_SKILLS = {
    'story-mapping': [
        {
            title: 'Story Mapping',
            path: '.setup-agents/skills/story-mapping/SKILL.md',
            activation: 'story maps, epic breakdowns, release planning maps, backlog visualization',
        },
        {
            title: 'Diagram Export',
            path: '.setup-agents/skills/diagram-export/SKILL.md',
            activation: 'Mermaid, architecture, sequence, workflow, Lucidchart, draw.io, SVG, or PDF diagram export',
        },
    ],
    deploy: [
        {
            title: 'Salesforce Deploy & Validate',
            path: '.setup-agents/skills/sf-deploy/SKILL.md',
            activation: 'Salesforce deploy, validate, quick deploy, package, or deployment troubleshooting',
        },
    ],
    'code-analysis': [
        {
            title: 'Salesforce Code Analyzer',
            path: '.setup-agents/skills/sf-code-analyzer/SKILL.md',
            activation: 'static analysis, Salesforce Code Analyzer, PMD, ESLint, rulesets, or quality gate evidence',
        },
    ],
    'backlog-sync': [
        {
            title: 'Backlog Sync',
            path: '.setup-agents/skills/backlog-sync/SKILL.md',
            activation: 'GitHub issues, epics, story refinement, acceptance criteria, or backlog synchronization',
        },
    ],
    'elements-sync': [
        {
            title: 'Elements Sync',
            path: '.setup-agents/skills/elements-sync/SKILL.md',
            activation: 'Elements.cloud requirements, stories, process maps, or metadata traceability',
        },
    ],
    'declare-points': [
        {
            title: 'Declare Story Points',
            path: '.setup-agents/playbooks/declare-story-points.md',
            activation: 'closing a phase, task completion, story-point declaration, effort recording, phase wrap-up',
        },
    ],
    'qa-evidence': [
        {
            title: 'QA Evidence Pack',
            path: '.setup-agents/skills/qa-evidence-pack/SKILL.md',
            activation: 'QA evidence, test evidence, acceptance criteria coverage, Playwright, screenshots, traces, videos, CLI output, API contracts, integration side effects, or release evidence',
        },
    ],
    transcription: [
        {
            title: 'Transcription Evidence',
            path: '.setup-agents/skills/transcription-evidence/SKILL.md',
            activation: 'transcribe audio, transcribe video, whisper, speech-to-text, meeting recording, transcript evidence',
        },
    ],
};
export const COMMON_RUNTIME_CAPABILITIES = ['qa-evidence', 'transcription'];
const RUNTIME_CAPABILITY_TRIGGERS = {
    'story-mapping': [
        'story map',
        'story maps',
        'epic breakdown',
        'release planning map',
        'backlog visualization',
        'diagram export',
        'mermaid',
        'lucidchart',
        'draw io',
    ],
    deploy: ['deploy', 'deployment', 'validate deployment', 'quick deploy', 'package deployment'],
    'code-analysis': ['code analyzer', 'static analysis', 'pmd', 'eslint', 'ruleset', 'quality gate'],
    'backlog-sync': ['backlog sync', 'github issues', 'story refinement', 'acceptance criteria sync'],
    'elements-sync': ['elements cloud', 'process map', 'metadata traceability'],
    'declare-points': ['declare points', 'story points', 'effort recording', 'phase wrap up'],
    'qa-evidence': [
        'qa evidence',
        'test evidence',
        'acceptance coverage',
        'acceptance criteria coverage',
        'playwright evidence',
        'screenshot evidence',
        'trace evidence',
        'release evidence',
        'evidence pack',
    ],
    transcription: [
        'transcribe',
        'transcription',
        'whisper',
        'speech to text',
        'meeting recording',
        'audio transcript',
        'video transcript',
        'transcript evidence',
    ],
};
export function listProfileCapabilities(profileIds) {
    const ids = profileIds ? new Set(profileIds) : undefined;
    const capabilities = new Set();
    let hasSelectedProfile = false;
    for (const profile of ALL_PROFILES) {
        if (ids && !ids.has(profile.id))
            continue;
        hasSelectedProfile = true;
        for (const capability of profile.capabilities) {
            capabilities.add(capability);
        }
    }
    if (!ids || hasSelectedProfile) {
        for (const capability of COMMON_RUNTIME_CAPABILITIES) {
            capabilities.add(capability);
        }
    }
    return [...capabilities].sort();
}
export function profilesForCapability(capability) {
    if (COMMON_RUNTIME_CAPABILITIES.includes(capability)) {
        return ALL_PROFILES.map((profile) => profile.id).sort();
    }
    return ALL_PROFILES.filter((profile) => profile.capabilities.includes(capability))
        .map((profile) => profile.id)
        .sort();
}
export function capabilitiesForProfile(profileId) {
    const resolvedId = PROFILE_ID_ALIASES[profileId] ?? profileId;
    const profile = ALL_PROFILES.find((entry) => entry.id === resolvedId);
    if (!profile)
        return [];
    return [...new Set([...profile.capabilities, ...COMMON_RUNTIME_CAPABILITIES])].sort();
}
export function skillsForCapability(capability) {
    return CAPABILITY_SKILLS[capability]?.map((skill) => ({ ...skill })) ?? [];
}
export function getCapabilityCatalog(profileIds) {
    return listProfileCapabilities(profileIds).map((id) => ({
        id,
        profiles: profilesForCapability(id).filter((profileId) => !profileIds || profileIds.includes(profileId)),
        skills: skillsForCapability(id),
    }));
}
export function resolveRuntimeCapabilities(request) {
    const signals = request.signals.map(normalizeSignal).filter(Boolean);
    if (signals.length === 0)
        return [];
    return getCapabilityCatalog(request.profileIds)
        .map((capability) => {
        const needles = capabilityNeedles(capability);
        const matchedSignals = signals.filter((signal) => needles.some((needle) => signal.includes(needle) || needle.includes(signal)));
        return { ...capability, matchedSignals };
    })
        .filter((capability) => capability.matchedSignals.length > 0);
}
function capabilityNeedles(capability) {
    return [
        capability.id,
        ...capability.skills.map((skill) => skill.title),
        ...(RUNTIME_CAPABILITY_TRIGGERS[capability.id] ?? []),
    ]
        .map(normalizeSignal)
        .filter(Boolean);
}
function normalizeSignal(value) {
    return value
        .toLowerCase()
        .replace(/[^a-z0-9]+/g, ' ')
        .trim();
}
//# sourceMappingURL=capabilities.js.map