@nanocollective/nanocoder
Version:
A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter
68 lines (64 loc) • 2.36 kB
JavaScript
/**
* Integrates commands with auto-injection capabilities into the LLM system prompt.
* Replaces the former SkillIntegration class.
*
* Commands that define `triggers` or `tags` in their frontmatter participate
* in relevance scoring: the top matches are automatically appended to the
* system prompt for each user request.
*/
export class CommandIntegration {
loader;
toolManager;
constructor(loader, toolManager) {
this.loader = loader;
this.toolManager = toolManager;
}
/**
* Enhance the system prompt with relevant auto-injectable commands.
*/
enhanceSystemPrompt(basePrompt, request) {
const availableTools = this.toolManager.getToolNames();
const relevant = this.loader.findRelevantCommands(request, availableTools);
if (relevant.length === 0) {
return basePrompt;
}
const commandPrompts = [];
for (const command of relevant) {
const block = this.formatCommandForPrompt(command);
if (block) {
commandPrompts.push(block);
}
}
if (commandPrompts.length === 0) {
return basePrompt;
}
const section = `
## Available Skills
You have access to the following Skills for this request:
${commandPrompts.join('\n\n')}
When a Skill is relevant, use its instructions. Tool restrictions listed in a Skill are enforced.`;
return basePrompt + section;
}
/**
* Format a single command for inclusion in the system prompt.
*/
formatCommandForPrompt(command) {
const name = command.metadata.description ? command.name : command.fullName;
let block = `### ${name}\n\n${command.content}`;
if (command.metadata.examples?.length) {
block += '\n\n**Examples:**\n';
for (const ex of command.metadata.examples) {
block += `- ${ex}\n`;
}
}
if (command.loadedResources?.length) {
block += '\n\n**Available Resources:**\n';
for (const r of command.loadedResources) {
const action = r.executable ? 'Execute' : 'Use';
block += `- \`${r.name}\` (${r.type}): ${action} via skill resource\n`;
}
}
return block;
}
}
//# sourceMappingURL=command-integration.js.map