refactor(agent): rename resource formatting helpers
This commit is contained in:
@@ -4,8 +4,8 @@ import { Agent } from "../agent.js";
|
||||
import type { AgentEvent, AgentMessage, AgentTool, ThinkingLevel } from "../types.js";
|
||||
import { collectEntriesForBranchSummary, generateBranchSummary } from "./compaction/branch-summarization.js";
|
||||
import { compact, DEFAULT_COMPACTION_SETTINGS, prepareCompaction } from "./compaction/compaction.js";
|
||||
import { expandPromptTemplate } from "./prompt-templates.js";
|
||||
import { expandSkillCommand } from "./skills.js";
|
||||
import { formatPromptTemplateInvocation } from "./prompt-templates.js";
|
||||
import { formatSkillInvocation } from "./skills.js";
|
||||
import type {
|
||||
AbortResult,
|
||||
AgentHarnessContext,
|
||||
@@ -335,14 +335,14 @@ export class AgentHarness {
|
||||
const resources = await this.resolveResources();
|
||||
const skill = (resources.skills ?? []).find((candidate) => candidate.name === name);
|
||||
if (!skill) throw new Error(`Unknown skill: ${name}`);
|
||||
return await this.prompt(expandSkillCommand(skill, additionalInstructions));
|
||||
return await this.prompt(formatSkillInvocation(skill, additionalInstructions));
|
||||
}
|
||||
|
||||
async promptFromTemplate(name: string, args: string[] = []): Promise<AssistantMessage> {
|
||||
const resources = await this.resolveResources();
|
||||
const template = (resources.promptTemplates ?? []).find((candidate) => candidate.name === name);
|
||||
if (!template) throw new Error(`Unknown prompt template: ${name}`);
|
||||
return await this.prompt(expandPromptTemplate(template, args));
|
||||
return await this.prompt(formatPromptTemplateInvocation(template, args));
|
||||
}
|
||||
|
||||
steer(message: AgentMessage): void {
|
||||
|
||||
@@ -211,7 +211,7 @@ export function substituteArgs(content: string, args: string[]): string {
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Expand a prompt template with positional command arguments. */
|
||||
export function expandPromptTemplate(template: PromptTemplate, args: string[] = []): string {
|
||||
/** Format a prompt template invocation with positional arguments. */
|
||||
export function formatPromptTemplateInvocation(template: PromptTemplate, args: string[] = []): string {
|
||||
return substituteArgs(template.content, args);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ interface SkillFrontmatter {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
/** Expand a skill into a prompt, optionally appending additional user instructions. */
|
||||
export function expandSkillCommand(skill: Skill, additionalInstructions?: string): string {
|
||||
/** Format a skill invocation prompt, optionally appending additional user instructions. */
|
||||
export function formatSkillInvocation(skill: Skill, additionalInstructions?: string): string {
|
||||
const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${dirnameEnvPath(skill.filePath)}.\n\n${skill.content}\n</skill>`;
|
||||
return additionalInstructions ? `${skillBlock}\n\n${additionalInstructions}` : skillBlock;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export interface PromptTemplate {
|
||||
name: string;
|
||||
/** Optional description for command lists or autocomplete. */
|
||||
description?: string;
|
||||
/** Template content. Argument placeholders are expanded by `expandPromptTemplate`. */
|
||||
/** Template content. Argument placeholders are expanded by `formatPromptTemplateInvocation`. */
|
||||
content: string;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user