"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = register;
const zod_1 = require("zod");
const defaults_1 = require("../../../lib/defaults");
function register(server, mgr) {
    server.registerTool('skills_list', {
        description: 'List skills with optional filters. ' +
            'Returns an array of { id, title, description, tags, source, confidence, usageCount, lastUsedAt, createdAt, updatedAt }. ' +
            'Use search_skills for semantic search.',
        inputSchema: {
            source: zod_1.z.enum(['user', 'learned']).optional().describe('Filter by source: "user" or "learned"'),
            tag: zod_1.z.string().max(defaults_1.MAX_TAG_LEN).optional().describe('Filter by tag (exact match, case-insensitive)'),
            filter: zod_1.z.string().max(500).optional().describe('Substring match on title or ID'),
            limit: zod_1.z.number().int().min(1).max(1000).optional().describe('Max results (default 50)'),
            offset: zod_1.z.number().int().min(0).max(100_000).optional().describe('Offset for pagination (default 0)'),
        },
    }, async ({ source, tag, filter, limit, offset }) => {
        const { results, total } = mgr.listSkills({ source, tag, filter, limit, offset });
        const clean = (k, v) => (k !== '' && (v === null || (Array.isArray(v) && v.length === 0)) ? undefined : v);
        const output = results.map(({ version: _, ...r }) => r);
        return { content: [{ type: 'text', text: JSON.stringify({ results: output, total }, clean, 2) }] };
    });
}
