// tools/register-hooks-tools.ts — Registers manage_hooks on the MCP server (SPEC-071)
import { z } from 'zod';
import { safeLicensed } from './safe-handler.js';
import { handleManageHooks } from './manage-hooks.js';
export function registerHooksTools(server) {
    server.registerTool('manage_hooks', {
        description: 'Create, list, delete, enable/disable, and install templates for agent hooks. ' +
            'Hooks automate actions when Planu events fire (spec created, status change, drift detected, commit). ' +
            'Use dry_run to preview which hooks would fire without side effects.',
        inputSchema: {
            projectId: z.string().describe('Project ID to manage hooks for'),
            operation: z
                .enum([
                'create',
                'list',
                'delete',
                'enable',
                'disable',
                'install_template',
                'dry_run',
                'list_logs',
            ])
                .describe('Operation: create | list | delete | enable | disable | install_template | dry_run | list_logs'),
            hook: z
                .object({
                name: z.string().describe('Human-readable hook name').optional(),
                description: z.string().describe('What this hook does').optional(),
                trigger: z
                    .enum(['on_spec_created', 'on_spec_status_change', 'on_drift_detected', 'on_commit'])
                    .describe('Trigger: on_spec_created | on_spec_status_change | on_drift_detected | on_commit')
                    .optional(),
                filter: z
                    .object({
                    fromStatus: z
                        .string()
                        .optional()
                        .describe('Only fire when status changes FROM this'),
                    toStatus: z.string().optional().describe('Only fire when status changes TO this'),
                    specIdPattern: z
                        .string()
                        .optional()
                        .describe('Only fire for specs matching this glob pattern (e.g. SPEC-*)'),
                })
                    .optional()
                    .describe('Optional filter conditions for conditional firing'),
                actions: z
                    .array(z.object({
                    type: z
                        .enum(['run_tool', 'log_message', 'set_variable', 'notify'])
                        .describe('Action type: run_tool | log_message | set_variable | notify'),
                    tool: z.string().optional().describe('Tool name (for run_tool)'),
                    args: z
                        .record(z.string(), z.unknown())
                        .optional()
                        .describe('Tool args (for run_tool)'),
                    message: z
                        .string()
                        .optional()
                        .describe('Message template (for log_message/notify)'),
                    key: z.string().optional().describe('Variable key (for set_variable)'),
                    value: z.string().optional().describe('Variable value (for set_variable)'),
                }))
                    .optional()
                    .describe('Ordered list of actions to execute when hook fires'),
                enabled: z.boolean().optional().describe('Whether hook is active (default: true)'),
            })
                .optional()
                .describe('Hook definition — required for create operation'),
            hookId: z
                .string()
                .optional()
                .describe('Hook ID — required for delete, enable, disable, dry_run'),
            templateName: z
                .string()
                .optional()
                .describe('Template name — required for install_template. Options: sdd-full | ci-ready | quality-gate'),
            dryRunPayload: z
                .object({
                trigger: z
                    .enum(['on_spec_created', 'on_spec_status_change', 'on_drift_detected', 'on_commit'])
                    .describe('Trigger type to simulate'),
                projectId: z.string().describe('Project ID for the simulated event'),
                timestamp: z.string().optional().describe('Event timestamp (defaults to now)'),
                specId: z.string().optional().describe('Spec ID (for spec-related triggers)'),
                specTitle: z.string().optional().describe('Spec title'),
                specType: z.string().optional().describe('Spec type (for on_spec_created)'),
                fromStatus: z
                    .string()
                    .optional()
                    .describe('Previous status (for on_spec_status_change)'),
                toStatus: z.string().optional().describe('New status (for on_spec_status_change)'),
                driftScore: z.number().optional().describe('Drift score 0-100 (for on_drift_detected)'),
                driftSummary: z.string().optional().describe('Drift summary (for on_drift_detected)'),
                commitHash: z.string().optional().describe('Commit hash (for on_commit)'),
                commitMessage: z.string().optional().describe('Commit message (for on_commit)'),
                branch: z.string().optional().describe('Branch name (for on_commit)'),
            })
                .optional()
                .describe('Simulated event payload for dry_run operation'),
        },
        annotations: {
            title: 'Manage Agent Hooks',
            readOnlyHint: false,
        },
    }, safeLicensed('manage_hooks', async (args) => handleManageHooks(args)));
}
//# sourceMappingURL=register-hooks-tools.js.map