Layer 1 — src/agents/ (thin agent definitions, no prompt text)
registry.ts — AgentConfig, registerAgent(), getAgent(), AGENTS proxy, pick()
orchestrator.ts, coder.ts, pm.ts, marketing.ts — one file each, just metadata + tool picks
index.ts — barrel: imports prompts then agents (correct registration order)
Layer 2 — src/prompts/ (prompt text separated from agent logic)
loader.ts — registerPrompt(), resolvePrompt() with {{variable}} substitution
orchestrator.ts, coder.ts, pm.ts, marketing.ts — prompt templates as registered strings
orchestrator.ts now uses resolvePrompt('orchestrator', { knowledge }) instead of
inline SYSTEM_PROMPT const; {{knowledge}} variable injects project memory cleanly.
agent-runner.ts uses resolvePrompt(config.promptId) per agent turn.
Layer 3 — src/tools/skills.ts (new skills capability)
list_skills(repo) — lists .skills/<name>/SKILL.md directories from a Gitea repo
get_skill(repo, name) — reads and returns the markdown body of a skill file
Orchestrator and all agents now have get_skill in their tool sets.
Orchestrator also has list_skills and references skills in its prompt.
Also fixed:
- server.ts now passes history + knowledge_context from request body to orchestratorChat()
(these were being sent by the frontend but silently dropped)
- server.ts imports PROTECTED_GITEA_REPOS from tools/security.ts (no more duplicate)
- Deleted src/agents.ts (replaced by src/agents/ directory)
Made-with: Cursor
63 lines
2.6 KiB
TypeScript
63 lines
2.6 KiB
TypeScript
import { registerTool } from './registry';
|
|
import { ToolContext } from './context';
|
|
|
|
const SKILL_FILE = 'SKILL.md';
|
|
const SKILLS_DIR = '.skills';
|
|
|
|
async function giteaGetContents(repo: string, path: string, ctx: ToolContext): Promise<any> {
|
|
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();
|
|
}
|
|
|
|
registerTool({
|
|
name: 'list_skills',
|
|
description: `List available skills for a project repo. Skills are stored in .skills/<name>/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: any) => entry.type === 'dir')
|
|
.map((entry: any) => ({ name: entry.name, path: entry.path }));
|
|
return { repo, skills };
|
|
}
|
|
});
|
|
|
|
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 };
|
|
}
|
|
});
|