/**
 * Trust source scorer — assigns trust levels based on memory source.
 */
import { scoreAgent, buildAgentHierarchy } from './agent-scorer.js';
const BASE_SCORES = {
    'user:direct': 1.0,
    'user:approved': 0.9,
};
const TYPE_SCORES = {
    user: 1.0,
    cli: 0.9,
    hook: 0.8,
    api: 0.7,
    file: 0.6,
    tool_response: 0.5,
    agent: 0.5,
    email: 0.4,
    web: 0.3,
};
const HIERARCHY_DISPLAY = [
    'user:direct = 1.0',
    'user:approved = 0.9',
    'cli:* = 0.9',
    'hook:* = 0.8',
    'api:* = 0.7',
    'file:* = 0.6',
    'agent:* = hierarchy',
    'email:* = 0.4',
    'web:* = 0.3',
];
export function scoreSource(source) {
    const key = `${source.type}:${source.identifier}`;
    // Exact match overrides
    const baseScore = BASE_SCORES[key];
    if (baseScore !== undefined) {
        return { score: baseScore, source, hierarchy: [...HIERARCHY_DISPLAY, `>> ${key} = ${baseScore}`] };
    }
    // Agent hierarchy scoring
    if (source.type === 'agent') {
        const score = scoreAgent(source.identifier);
        return {
            score,
            source,
            hierarchy: [
                'Agent Hierarchy:',
                ...buildAgentHierarchy(source.identifier),
                `>> ${key} = ${score}`,
            ],
        };
    }
    // Type fallback
    const score = TYPE_SCORES[source.type] ?? 0;
    return { score, source, hierarchy: [...HIERARCHY_DISPLAY, `>> ${key} = ${score}`] };
}
