// tools/tool-registry/deprecated-stubs.ts — Shared factory for MCP deprecation stubs (SPEC-658).
//
// Tools migrated to skills stay registered so callers receive a helpful message
// instead of "unknown tool". The stub handler never throws and always returns
// HTTP 200 with a plain-text deprecation notice.
import { z } from 'zod';
import { compactResult } from '../output-formatter.js';
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
/** Template for the deprecation message. Interpolated at runtime. */
export const DEPRECATION_MESSAGE_TEMPLATE = 'This tool has been migrated to a skill. Use the {skill} skill instead: {path}';
/**
 * The 5 MCP tool names that have been migrated to skills.
 * Used in smoke tests (Scenario 6) and anywhere a guard on migrated tools is needed.
 */
export const DEPRECATED_TOOLS = [
    'execute_sdd_flow',
    'implement_plan',
    'multi_teammate_review',
    'run_healing_loop',
    'generate_orchestration_plan',
];
// ---------------------------------------------------------------------------
// Per-process warning dedup (one stderr line per tool name per process)
// ---------------------------------------------------------------------------
const _warned = new Set();
function warnOnce(toolName, skillPath) {
    if (!_warned.has(toolName)) {
        _warned.add(toolName);
        process.stderr.write(`[planu] DEPRECATION: MCP tool "${toolName}" has been migrated to skill "${skillPath}". ` +
            'Update callers to use the skill directly.\n');
    }
}
// ---------------------------------------------------------------------------
// Factory
// ---------------------------------------------------------------------------
/**
 * Create a ToolEntry-compatible deprecation stub.
 *
 * - Tool stays registered → callers never see "unknown tool".
 * - Description starts with `[Deprecated]` → LLMs stop calling it.
 * - Handler always returns success (no `isError`) regardless of input.
 * - One stderr warning per process per tool (deduped).
 */
export function makeDeprecationStub(toolName, replacementSkillPath, replacementSkillName) {
    const message = DEPRECATION_MESSAGE_TEMPLATE.replace('{skill}', replacementSkillName).replace('{path}', replacementSkillPath);
    return {
        name: toolName,
        description: `[Deprecated] Migrated to ${replacementSkillName} skill. See ${replacementSkillPath}`,
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        schema: z.object({}).passthrough().shape,
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        handler: (_args) => {
            warnOnce(toolName, replacementSkillPath);
            return Promise.resolve(compactResult(message));
        },
        annotations: {
            readOnlyHint: true,
            title: `[Deprecated] ${toolName}`,
        },
        wrap: 'safe',
    };
}
//# sourceMappingURL=deprecated-stubs.js.map