"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.phaseMatchesCall = phaseMatchesCall;
exports.expectedToolNames = expectedToolNames;
/**
 * Predicate testing whether a logged tool call satisfies a phase's
 * expectations. `expectedCalls` (when set) trumps `expectedTools`; otherwise
 * the legacy "any call with the right tool name" semantics apply. Tool
 * names are normalised by stripping the MCP prefix on both sides.
 */
function phaseMatchesCall(phase, record) {
    const MCP_PREFIX = 'mcp__smartperfetto__';
    const shortTool = record.toolName.startsWith(MCP_PREFIX)
        ? record.toolName.slice(MCP_PREFIX.length)
        : record.toolName;
    if (phase.expectedCalls && phase.expectedCalls.length > 0) {
        return phase.expectedCalls.some(call => {
            if (call.tool !== shortTool)
                return false;
            if (call.skillId && call.skillId !== record.skillId)
                return false;
            return true;
        });
    }
    return phase.expectedTools.includes(shortTool);
}
/** Flatten a phase's expectations to plain tool names for log/UI rendering. */
function expectedToolNames(phase) {
    if (phase.expectedCalls && phase.expectedCalls.length > 0) {
        return phase.expectedCalls.map(c => c.skillId ? `${c.tool}(${c.skillId})` : c.tool);
    }
    return phase.expectedTools;
}
//# sourceMappingURL=types.js.map