// tools/register-living-spec-advanced-tools.ts — SPEC-121 Living Spec Advanced tools
// Registers: living_spec_watch, living_spec_status, spec_diff, living_spec_coverage,
//            sync_spec_to_code, sync_code_to_spec, resolve_sync_conflict
import { z } from 'zod';
import { safeLicensed } from './safe-handler.js';
import { handleLivingSpecWatch, handleLivingSpecStatus } from './living-spec-watch.js';
import { handleSpecDiff } from './spec-diff.js';
import { handleLivingSpecCoverage } from './living-spec-coverage.js';
import { handleSyncSpecToCode } from './sync-spec-to-code.js';
import { handleSyncCodeToSpec } from './sync-code-to-spec.js';
import { handleResolveSyncConflict } from './resolve-sync-conflict.js';
/**
 * Registers SPEC-121 living spec advanced tools on the MCP server.
 */
export function registerLivingSpecAdvancedTools(server) {
    // living_spec_watch
    server.registerTool('living_spec_watch', {
        description: 'Start, stop, or check status of the in-memory drift watcher for a project. The watcher caches drift detection results with a configurable TTL to avoid redundant computations.',
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            action: z
                .enum(['start', 'stop', 'status'])
                .describe('Action to perform. Valid values: "start", "stop", "status"'),
            ttlSeconds: z
                .number()
                .int()
                .min(5)
                .max(3600)
                .optional()
                .describe('Cache TTL in seconds (5-3600). Default: 60. Only used with "start" action'),
            excludePatterns: z
                .array(z.string().max(500))
                .max(50)
                .optional()
                .describe('Glob patterns to exclude from drift watching (e.g., ["node_modules/**", "dist/**"])'),
        },
    }, safeLicensed('living_spec_watch', async (args) => handleLivingSpecWatch(args)));
    // living_spec_status
    server.registerTool('living_spec_status', {
        description: 'Get detailed status of the living spec watcher including cache state and configuration. Read-only diagnostic tool.',
        annotations: { readOnlyHint: true },
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            specId: z
                .string()
                .max(500)
                .optional()
                .describe('Optional spec ID to get cached drift data for'),
        },
    }, safeLicensed('living_spec_status', async (args) => handleLivingSpecStatus(args)));
    // spec_diff
    server.registerTool('spec_diff', {
        description: 'Compare spec hash snapshots to detect file and signature changes. Shows a Markdown-formatted diff table. Use after snapshot_spec_hashes to see what changed.',
        annotations: { readOnlyHint: true },
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            specId: z
                .string()
                .max(500)
                .optional()
                .describe('Specific spec ID to diff (if omitted, diffs all specs)'),
        },
    }, safeLicensed('spec_diff', async (args) => handleSpecDiff(args)));
    // living_spec_coverage
    server.registerTool('living_spec_coverage', {
        description: 'Correlate test coverage with spec acceptance criteria. Parses Vitest JSON or JUnit XML reports and groups results by @spec annotations to determine criterion status (verified/regression/untested).',
        annotations: { readOnlyHint: true },
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            coverageJsonPath: z
                .string()
                .max(4096)
                .optional()
                .describe('Path to Vitest JSON report file'),
            junitXmlPath: z.string().max(4096).optional().describe('Path to JUnit XML report file'),
        },
    }, safeLicensed('living_spec_coverage', async (args) => handleLivingSpecCoverage(args)));
    // sync_spec_to_code
    server.registerTool('sync_spec_to_code', {
        description: 'Sync from spec to code: generate TODO comments for pending acceptance criteria that lack @spec annotations. Also detects conflicts between spec and code state.',
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            specId: z.string().max(500).describe('Spec ID to sync from'),
            projectPath: z.string().max(4096).describe('Path to the project root directory'),
        },
    }, safeLicensed('sync_spec_to_code', async (args) => handleSyncSpecToCode(args)));
    // sync_code_to_spec
    server.registerTool('sync_code_to_spec', {
        description: 'Sync from code to spec: detect @spec annotations in source code and generate progress updates for the corresponding spec criteria. Also detects conflicts.',
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            specId: z.string().max(500).describe('Spec ID to sync to'),
            projectPath: z.string().max(4096).describe('Path to the project root directory'),
        },
    }, safeLicensed('sync_code_to_spec', async (args) => handleSyncCodeToSpec(args)));
    // resolve_sync_conflict
    server.registerTool('resolve_sync_conflict', {
        description: 'Resolve a sync conflict detected by sync_spec_to_code or sync_code_to_spec. Choose to accept the code state, accept the spec state, or provide a manual resolution.',
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            conflictId: z.string().max(100).describe('Conflict ID from the sync result'),
            resolution: z
                .enum(['accept-code', 'accept-spec', 'manual'])
                .describe('Resolution strategy. Valid values: "accept-code", "accept-spec", "manual"'),
            manualResolution: z
                .string()
                .max(2000)
                .optional()
                .describe('Description of manual resolution (required when resolution is "manual")'),
        },
    }, safeLicensed('resolve_sync_conflict', async (args) => handleResolveSyncConflict(args)));
}
//# sourceMappingURL=register-living-spec-advanced-tools.js.map