From 401017a3e80a96996a17b5ad05e3cb8fc056cec4 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sat, 9 May 2026 19:43:57 +0200 Subject: [PATCH] refactor(agent): rename resource formatting helpers --- packages/agent/src/harness/agent-harness.ts | 8 ++++---- packages/agent/src/harness/prompt-templates.ts | 4 ++-- packages/agent/src/harness/skills.ts | 4 ++-- packages/agent/src/harness/types.ts | 2 +- .../test/harness/prompt-templates.test.ts | 6 +++--- .../test/harness/resource-expansion.test.ts | 18 +++++++++--------- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/agent/src/harness/agent-harness.ts b/packages/agent/src/harness/agent-harness.ts index f5e2b29f..5d1d516d 100644 --- a/packages/agent/src/harness/agent-harness.ts +++ b/packages/agent/src/harness/agent-harness.ts @@ -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 { 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 { diff --git a/packages/agent/src/harness/prompt-templates.ts b/packages/agent/src/harness/prompt-templates.ts index 24227a19..c7c06ccd 100644 --- a/packages/agent/src/harness/prompt-templates.ts +++ b/packages/agent/src/harness/prompt-templates.ts @@ -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); } diff --git a/packages/agent/src/harness/skills.ts b/packages/agent/src/harness/skills.ts index 27b852bb..3fd6b7fb 100644 --- a/packages/agent/src/harness/skills.ts +++ b/packages/agent/src/harness/skills.ts @@ -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 = `\nReferences are relative to ${dirnameEnvPath(skill.filePath)}.\n\n${skill.content}\n`; return additionalInstructions ? `${skillBlock}\n\n${additionalInstructions}` : skillBlock; } diff --git a/packages/agent/src/harness/types.ts b/packages/agent/src/harness/types.ts index c9a3bb6f..2e93ef32 100644 --- a/packages/agent/src/harness/types.ts +++ b/packages/agent/src/harness/types.ts @@ -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; } diff --git a/packages/agent/test/harness/prompt-templates.test.ts b/packages/agent/test/harness/prompt-templates.test.ts index 1d2c7eb8..62ae9aee 100644 --- a/packages/agent/test/harness/prompt-templates.test.ts +++ b/packages/agent/test/harness/prompt-templates.test.ts @@ -3,7 +3,7 @@ import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { NodeExecutionEnv } from "../../src/harness/execution-env.js"; import { - expandPromptTemplate, + formatPromptTemplateInvocation, loadPromptTemplates, loadSourcedPromptTemplates, } from "../../src/harness/prompt-templates.js"; @@ -80,10 +80,10 @@ describe("loadPromptTemplates", () => { }); }); -describe("expandPromptTemplate", () => { +describe("formatPromptTemplateInvocation", () => { it("substitutes command arguments", () => { const content = "$1 $" + "{@:2} $ARGUMENTS"; - expect(expandPromptTemplate({ name: "one", content }, ["hello world", "test"])).toBe( + expect(formatPromptTemplateInvocation({ name: "one", content }, ["hello world", "test"])).toBe( "hello world test hello world test", ); }); diff --git a/packages/agent/test/harness/resource-expansion.test.ts b/packages/agent/test/harness/resource-expansion.test.ts index 74bf95b5..fe3fed40 100644 --- a/packages/agent/test/harness/resource-expansion.test.ts +++ b/packages/agent/test/harness/resource-expansion.test.ts @@ -1,9 +1,9 @@ import { describe, expect, it } from "vitest"; -import { expandPromptTemplate } from "../../src/harness/prompt-templates.js"; -import { expandSkillCommand } from "../../src/harness/skills.js"; +import { formatPromptTemplateInvocation } from "../../src/harness/prompt-templates.js"; +import { formatSkillInvocation } from "../../src/harness/skills.js"; -describe("resource expansion helpers", () => { - it("expands skills with additional instructions", () => { +describe("resource formatting helpers", () => { + it("formats skill invocations with additional instructions", () => { const skill = { name: "inspect", description: "Inspect things", @@ -11,14 +11,14 @@ describe("resource expansion helpers", () => { filePath: "/project/.pi/skills/inspect/SKILL.md", }; - expect(expandSkillCommand(skill, "Check errors.")).toBe( + expect(formatSkillInvocation(skill, "Check errors.")).toBe( '\nReferences are relative to /project/.pi/skills/inspect.\n\nUse inspection tools.\n\n\nCheck errors.', ); }); - it("expands prompt templates with positional arguments", () => { - expect(expandPromptTemplate({ name: "review", content: "Review $1 with $ARGUMENTS" }, ["a.ts", "care"])).toBe( - "Review a.ts with a.ts care", - ); + it("formats prompt template invocations with positional arguments", () => { + expect( + formatPromptTemplateInvocation({ name: "review", content: "Review $1 with $ARGUMENTS" }, ["a.ts", "care"]), + ).toBe("Review a.ts with a.ts care"); }); });