Add skills system with Claude Code compatibility (#171)

* Add skills system with Claude Code compatibility

* consolidate skills into single module, merge loaders, add <available_skills> XML tags

* add Codex CLI skills compatibility, skip hidden/symlinks
This commit is contained in:
Nico Bailon 2025-12-12 09:24:52 -08:00 committed by GitHub
parent 4d9a06b931
commit 09bca9672f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 376 additions and 11 deletions

View file

@ -6,6 +6,7 @@ import chalk from "chalk";
import { existsSync, readFileSync } from "fs";
import { join, resolve } from "path";
import { getAgentDir, getDocsPath, getReadmePath } from "../config.js";
import { loadSkills, type Skill } from "./skills.js";
import type { ToolName } from "./tools/index.js";
/** Tool descriptions for system prompt */
@ -101,12 +102,39 @@ export function loadProjectContextFiles(): Array<{ path: string; content: string
return contextFiles;
}
function buildSkillsSection(skills: Skill[]): string {
if (skills.length === 0) {
return "";
}
const lines = [
"\n\n<available_skills>",
"The following skills provide specialized instructions for specific tasks.",
"Use the read tool to load a skill's file when the task matches its description.",
"Skills may contain {baseDir} placeholders - replace them with the skill's base directory path.\n",
];
for (const skill of skills) {
lines.push(`- ${skill.name}: ${skill.description}`);
lines.push(` File: ${skill.filePath}`);
lines.push(` Base directory: ${skill.baseDir}`);
}
lines.push("</available_skills>");
return lines.join("\n");
}
export interface BuildSystemPromptOptions {
customPrompt?: string;
selectedTools?: ToolName[];
appendSystemPrompt?: string;
skillsEnabled?: boolean;
}
/** Build the system prompt with tools, guidelines, and context */
export function buildSystemPrompt(
customPrompt?: string,
selectedTools?: ToolName[],
appendSystemPrompt?: string,
): string {
export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {
const { customPrompt, selectedTools, appendSystemPrompt, skillsEnabled = true } = options;
const resolvedCustomPrompt = resolvePromptInput(customPrompt, "system prompt");
const resolvedAppendPrompt = resolvePromptInput(appendSystemPrompt, "append system prompt");
@ -141,6 +169,13 @@ export function buildSystemPrompt(
}
}
// Append skills section (only if read tool is available)
const customPromptHasRead = !selectedTools || selectedTools.includes("read");
if (skillsEnabled && customPromptHasRead) {
const skills = loadSkills();
prompt += buildSkillsSection(skills);
}
// Add date/time and working directory last
prompt += `\nCurrent date and time: ${dateTime}`;
prompt += `\nCurrent working directory: ${process.cwd()}`;
@ -241,6 +276,12 @@ Documentation:
}
}
// Append skills section (only if read tool is available)
if (skillsEnabled && hasRead) {
const skills = loadSkills();
prompt += buildSkillsSection(skills);
}
// Add date/time and working directory last
prompt += `\nCurrent date and time: ${dateTime}`;
prompt += `\nCurrent working directory: ${process.cwd()}`;