// tools/multi-teammate-review.ts — MCP tool registration for multi-teammate review (SPEC-593)
// NOTE (SPEC-658): registerMultiTeammateReviewTool now registers a deprecation stub.
// The underlying handleMultiTeammateReview logic is kept for direct import by skills/tests.
import { z } from 'zod';
// safeTracked removed — registration replaced by deprecation stub (SPEC-658)
import { toolResult, formatError } from './response-helpers.js';
import { makeDeprecationStub } from './tool-registry/deprecated-stubs.js';
import { registerFromEntries } from './tool-entry.js';
import { runReviewPanel } from '../engine/multi-teammate-review/panel-orchestrator.js';
import { buildModelHeader } from '../engine/model-router/subtask-model-assigner.js';
// ---------------------------------------------------------------------------
// Default LlmInvoker: no-op fallback (real impl would delegate to Claude API)
// ---------------------------------------------------------------------------
// The default invoker is intentionally minimal. In a real deployment, the
// Claude Code host spawns subagents via the Agent Teams infrastructure; the
// tool itself cannot directly call the LLM SDK without creating a circular
// dependency on the host runtime. The caller (Claude Code) provides the
// context; the panel results are assembled by whoever invokes this tool.
//
// Fallback behaviour when no real invoker is wired:
//   - Returns a structured placeholder indicating "LLM not available in this context"
//   - The arbitrator then promotes all specialist placeholders as suggestions
// This is intentional: the tool is usable in CI pipelines or programmatic
// contexts where an external invoker is injected.
class NoOpLlmInvoker {
    invoke(_systemPrompt, _userMessage) {
        return Promise.resolve(JSON.stringify([
            {
                role: 'security',
                file: '',
                line: 0,
                message: 'LLM invoker not configured — inject a real LlmInvoker to get specialist analysis',
                recommendation: 'Configure an LlmInvoker implementation in the tool handler',
                severity: 'suggestion',
                reasoning: 'No LLM was available to perform this analysis',
            },
        ]));
    }
}
// ---------------------------------------------------------------------------
// Exported for tests / injection
// ---------------------------------------------------------------------------
export const DEFAULT_LLM_INVOKER = new NoOpLlmInvoker();
// Factory allowing tests or wrappers to inject a custom invoker
let _invokerOverride;
export function setLlmInvoker(invoker) {
    _invokerOverride = invoker;
}
export function getActiveLlmInvoker() {
    return _invokerOverride ?? DEFAULT_LLM_INVOKER;
}
// ---------------------------------------------------------------------------
// Input schema
// ---------------------------------------------------------------------------
export const MultiTeammateReviewInputSchema = {
    projectPath: z.string().min(1).max(4096).describe('Absolute path to the project root directory.'),
    diff: z
        .string()
        .optional()
        .describe('Unified diff text to review. Provide at least one of: diff, prNumber, branch, or commitRange.'),
    prNumber: z
        .number()
        .int()
        .positive()
        .optional()
        .describe('PR number for context (included in the output report header).'),
    branch: z
        .string()
        .optional()
        .describe('Branch name for context (included in the output report header).'),
    commitRange: z
        .string()
        .optional()
        .describe('Commit range for context, e.g. "main..HEAD" (included in the output report header).'),
    spec: z
        .string()
        .optional()
        .describe('Linked spec content. When provided, the arbitrator uses it to resolve contradictions and detect spec drift.'),
};
// ---------------------------------------------------------------------------
// Tool registration
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// handleMultiTeammateReview — exported for skill-runner / direct import
// ---------------------------------------------------------------------------
export async function handleMultiTeammateReview(args) {
    const { projectPath, diff, prNumber, branch, commitRange, spec } = args;
    if (!diff && prNumber === undefined && !branch && !commitRange) {
        return toolResult(formatError('Provide at least one of: diff (unified diff text), prNumber, branch, or commitRange.'), undefined, true);
    }
    const input = {
        projectPath,
        diff,
        prNumber,
        branch,
        commitRange,
        spec,
    };
    const invoker = getActiveLlmInvoker();
    const report = await runReviewPanel(input, invoker);
    const specialistModels = [
        `security: ${buildModelHeader('opus')}`,
        `correctness: ${buildModelHeader('sonnet')}`,
        `performance: ${buildModelHeader('sonnet')}`,
        `maintainability: ${buildModelHeader('haiku')}`,
        `architecture: ${buildModelHeader('opus')}`,
    ];
    const outputLines = [
        report.markdownReport,
        '',
        '---',
        `Reviewed at: ${report.reviewedAt}`,
        `Total decisions: ${String(report.decisions.length)}`,
        '',
        '**Specialist model assignments**:',
        ...specialistModels.map((line) => `- ${line}`),
    ];
    return toolResult(outputLines.join('\n'));
}
// ---------------------------------------------------------------------------
// Tool registration (SPEC-658: replaced with deprecation stub)
// ---------------------------------------------------------------------------
export function registerMultiTeammateReviewTool(s) {
    // multi_teammate_review has been migrated to .claude/skills/review-and-merge.md
    // The tool stays registered so callers receive a helpful message, not "unknown tool".
    registerFromEntries(s, [
        makeDeprecationStub('multi_teammate_review', '.claude/skills/review-and-merge.md', 'review-and-merge'),
    ]);
}
//# sourceMappingURL=multi-teammate-review.js.map