this repo has no description
1/**
2 * System prompt loader with dynamic tool injection
3 *
4 * Loads the system prompt from a markdown file and injects
5 * the available tools from the tool registry.
6 */
7
8import { toolRegistry } from './tools';
9
10/**
11 * Path to the system prompt template
12 */
13const SYSTEM_PROMPT_PATH = new URL('../prompts/SYSTEM_PROMPT.md', import.meta.url).pathname;
14
15/**
16 * Format a tool definition as a bullet point for the prompt
17 */
18function formatToolForPrompt(name: string, description: string): string {
19 return `- ${name}: ${description}`;
20}
21
22/**
23 * Generate the tools section from the registry
24 */
25function generateToolsSection(): string {
26 const tools = toolRegistry.getAll();
27
28 if (tools.length === 0) {
29 return '(No tools registered yet)';
30 }
31
32 return tools.map((tool) => formatToolForPrompt(tool.name, tool.description)).join('\n');
33}
34
35/**
36 * Load the system prompt from file and inject tools
37 *
38 * @returns The complete system prompt with tools injected
39 */
40export async function loadSystemPrompt(): Promise<string> {
41 const templateFile = Bun.file(SYSTEM_PROMPT_PATH);
42 const template = await templateFile.text();
43
44 const toolsSection = generateToolsSection();
45 const prompt = template.replace('{{TOOLS}}', toolsSection);
46
47 return prompt;
48}