"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const registry_1 = require("./registry"); const SKILL_FILE = 'SKILL.md'; const SKILLS_DIR = '.skills'; async function giteaGetContents(repo, path, ctx) { const res = await fetch(`${ctx.gitea.apiUrl}/api/v1/repos/${repo}/contents/${path}`, { headers: { 'Authorization': `token ${ctx.gitea.apiToken}` } }); if (!res.ok) return null; return res.json(); } (0, registry_1.registerTool)({ name: 'list_skills', description: `List available skills for a project repo. Skills are stored in .skills//SKILL.md and provide reusable instructions the agent should follow (e.g. deploy process, test commands, code conventions).`, parameters: { type: 'object', properties: { repo: { type: 'string', description: 'Repo in "owner/name" format' } }, required: ['repo'] }, async handler(args, ctx) { const repo = String(args.repo); const contents = await giteaGetContents(repo, SKILLS_DIR, ctx); if (!contents || !Array.isArray(contents)) { return { skills: [], message: `No .skills/ directory found in ${repo}` }; } const skills = contents .filter((entry) => entry.type === 'dir') .map((entry) => ({ name: entry.name, path: entry.path })); return { repo, skills }; } }); (0, registry_1.registerTool)({ name: 'get_skill', description: `Read the full content of a specific skill from a project repo. Call list_skills first to see what's available. Use this before spawning agents so they have the relevant project-specific instructions.`, parameters: { type: 'object', properties: { repo: { type: 'string', description: 'Repo in "owner/name" format' }, skill_name: { type: 'string', description: 'Skill name (directory name inside .skills/)' } }, required: ['repo', 'skill_name'] }, async handler(args, ctx) { const repo = String(args.repo); const skillName = String(args.skill_name); const filePath = `${SKILLS_DIR}/${skillName}/${SKILL_FILE}`; const file = await giteaGetContents(repo, filePath, ctx); if (!file || !file.content) { return { error: `Skill "${skillName}" not found in ${repo}. Try list_skills to see available skills.` }; } const content = Buffer.from(file.content, 'base64').toString('utf8'); // Strip YAML frontmatter if present, return just the markdown body const body = content.replace(/^---[\s\S]*?---\s*/m, '').trim(); return { repo, skill: skillName, content: body }; } });