import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import React from 'react';
import ToolMessage from '../components/tool-message.js';
import { ThemeContext } from '../hooks/useTheme.js';
import { checkSkillBundle, formatSkillCheckReport } from '../skills/check.js';
import { jsonSchema, tool } from '../types/core.js';
import { formatError } from '../utils/error-formatter.js';
const executeCheckSkill = async (args) => {
    const name = (args.name ?? '').trim();
    if (!name) {
        throw new Error('check_skill requires a "name" (the skill bundle name).');
    }
    try {
        const report = await checkSkillBundle(process.cwd(), name);
        return formatSkillCheckReport(report);
    }
    catch (error) {
        throw new Error(`Failed to check skill: ${formatError(error)}`);
    }
};
const checkSkillCoreTool = tool({
    description: 'Lint a bundle-form skill under .nanocoder/skills/<name>/ and report whether its skill.yaml and member files (commands/, agents/, tools/) are correctly formatted. Reads from disk, so it sees files just written this session. Returns PASS or FAIL with per-file errors and advisory warnings. Call this after authoring or editing a skill bundle and fix any reported errors until it reports PASS.',
    inputSchema: jsonSchema({
        type: 'object',
        properties: {
            name: {
                type: 'string',
                description: 'The skill bundle name (the directory under .nanocoder/skills/). Example: "pr-reviewer".',
            },
        },
        required: ['name'],
    }),
    execute: async (args, _options) => {
        return await executeCheckSkill(args);
    },
});
const CheckSkillFormatter = React.memo(({ args, result }) => {
    const themeContext = React.useContext(ThemeContext);
    if (!themeContext) {
        throw new Error('ThemeContext not found');
    }
    const { colors } = themeContext;
    const passed = !!result && result.startsWith('PASS');
    const messageContent = (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: colors.tool, children: "\u2692 check_skill" }), _jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Skill: " }), _jsx(Text, { color: colors.text, children: args.name })] }), result && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { color: passed ? colors.success : colors.error, children: result }) }))] }));
    return _jsx(ToolMessage, { message: messageContent, hideBox: true });
});
const checkSkillFormatter = (args, result) => {
    return _jsx(CheckSkillFormatter, { args: args, result: result });
};
export const checkSkillTool = {
    name: 'check_skill',
    tool: checkSkillCoreTool,
    formatter: checkSkillFormatter,
    readOnly: true,
};
//# sourceMappingURL=skill-check.js.map