src / tools / skillTools.ts
src / tools / skillTools.ts
import fs from 'fs/promises';
import path from 'path';
import { getState } from '../stateRegistry';
const SKILLS_FILE = '.timber_skills.json';
interface Skill {
id: string;
name: string;
description: string;
role: string;
tools_enabled: string[];
prompt_template: string;
}
let skills: Skill[] = [];
async function loadSkills(): Promise<void> {
try {
const content = await fs.readFile(path.join(process.cwd(), SKILLS_FILE), 'utf-8');
skills = JSON.parse(content);
} catch {
skills = [
{ id: 'security_auditor', name: 'Security Auditor', description: 'Expert in code security review and vulnerability scanning', role: 'reviewer', tools_enabled: ['search_file_content', 'read_file', 'replace_text_in_file'], prompt_template: 'You are a security auditor. Review the provided code for vulnerabilities, OWASP top 10 issues, and best practices.' },
{ id: 'refactor_expert', name: 'Refactoring Expert', description: 'Specialist in modernizing legacy codebases', role: 'coder', tools_enabled: ['read_file', 'list_directory', 'save_file', 'replace_text_in_file'], prompt_template: 'You are a refactoring expert. Modernize the provided code while maintaining functionality.' },
{ id: 'docs_writer', name: 'Documentation Writer', description: 'Creates comprehensive technical documentation', role: 'general', tools_enabled: ['read_file', 'list_directory', 'save_file'], prompt_template: 'You are a technical writer. Create clear, comprehensive documentation for the provided codebase.' }
];
}
}
export async function skill_list(): Promise<{ skills: Skill[] }> {
await loadSkills();
return { skills };
}
export async function skill_create(name: string, description: string, role: string, tools_enabled: string[], prompt_template: string): Promise<{ success: boolean; id?: string }> {
await loadSkills();
const id = `skill_${Date.now()}`;
skills.push({ id, name, description, role, tools_enabled, prompt_template });
await fs.writeFile(path.join(process.cwd(), SKILLS_FILE), JSON.stringify(skills, null, 2));
getState().lastConfigChange = new Date();
return { success: true, id };
}
export async function skill_delete(id: string): Promise<{ success: boolean }> {
await loadSkills();
skills = skills.filter(s => s.id !== id);
await fs.writeFile(path.join(process.cwd(), SKILLS_FILE), JSON.stringify(skills, null, 2));
return { success: true };
}
export async function skill_get(id: string): Promise<{ skill?: Skill }> {
await loadSkills();
const skill = skills.find(s => s.id === id);
return { skill };
}
import fs from 'fs/promises';
import path from 'path';
import { getState } from '../stateRegistry';
const SKILLS_FILE = '.timber_skills.json';
interface Skill {
id: string;
name: string;
description: string;
role: string;
tools_enabled: string[];
prompt_template: string;
}
let skills: Skill[] = [];
async function loadSkills(): Promise<void> {
try {
const content = await fs.readFile(path.join(process.cwd(), SKILLS_FILE), 'utf-8');
skills = JSON.parse(content);
} catch {
skills = [
{ id: 'security_auditor', name: 'Security Auditor', description: 'Expert in code security review and vulnerability scanning', role: 'reviewer', tools_enabled: ['search_file_content', 'read_file', 'replace_text_in_file'], prompt_template: 'You are a security auditor. Review the provided code for vulnerabilities, OWASP top 10 issues, and best practices.' },
{ id: 'refactor_expert', name: 'Refactoring Expert', description: 'Specialist in modernizing legacy codebases', role: 'coder', tools_enabled: ['read_file', 'list_directory', 'save_file', 'replace_text_in_file'], prompt_template: 'You are a refactoring expert. Modernize the provided code while maintaining functionality.' },
{ id: 'docs_writer', name: 'Documentation Writer', description: 'Creates comprehensive technical documentation', role: 'general', tools_enabled: ['read_file', 'list_directory', 'save_file'], prompt_template: 'You are a technical writer. Create clear, comprehensive documentation for the provided codebase.' }
];
}
}
export async function skill_list(): Promise<{ skills: Skill[] }> {
await loadSkills();
return { skills };
}
export async function skill_create(name: string, description: string, role: string, tools_enabled: string[], prompt_template: string): Promise<{ success: boolean; id?: string }> {
await loadSkills();
const id = `skill_${Date.now()}`;
skills.push({ id, name, description, role, tools_enabled, prompt_template });
await fs.writeFile(path.join(process.cwd(), SKILLS_FILE), JSON.stringify(skills, null, 2));
getState().lastConfigChange = new Date();
return { success: true, id };
}
export async function skill_delete(id: string): Promise<{ success: boolean }> {
await loadSkills();
skills = skills.filter(s => s.id !== id);
await fs.writeFile(path.join(process.cwd(), SKILLS_FILE), JSON.stringify(skills, null, 2));
return { success: true };
}
export async function skill_get(id: string): Promise<{ skill?: Skill }> {
await loadSkills();
const skill = skills.find(s => s.id === id);
return { skill };
}