diff --git a/agents/base2/base2.ts b/agents/base2/base2.ts index 924683e0ac..662cc2a775 100644 --- a/agents/base2/base2.ts +++ b/agents/base2/base2.ts @@ -17,14 +17,6 @@ import { type SecretAgentDefinition, } from '../types/secret-agent-definition' -function formatCurrentDate(date: Date): string { - return new Intl.DateTimeFormat('en-US', { - year: 'numeric', - month: 'long', - day: 'numeric', - }).format(date) -} - export function createBase2( mode: 'default' | 'free' | 'lite' | 'max' | 'fast', options?: { @@ -138,7 +130,7 @@ export function createBase2( systemPrompt: `You are Buffy, a strategic assistant that orchestrates complex coding tasks through specialized sub-agents. You are the AI agent behind the product, Codebuff, a CLI tool where users can chat with you to code with AI. -Current date: ${formatCurrentDate(new Date())}. +Current date: ${PLACEHOLDER.CURRENT_DATE}. # Core Mandates diff --git a/agents/types/secret-agent-definition.ts b/agents/types/secret-agent-definition.ts index fa0656f557..cab28c2669 100644 --- a/agents/types/secret-agent-definition.ts +++ b/agents/types/secret-agent-definition.ts @@ -23,6 +23,7 @@ export interface SecretAgentDefinition const placeholderNames = [ 'AGENT_NAME', 'AGENTS_PROMPT', + 'CURRENT_DATE', 'FILE_TREE_PROMPT_SMALL', 'FILE_TREE_PROMPT', 'FILE_TREE_PROMPT_LARGE', diff --git a/packages/agent-runtime/src/templates/__tests__/strings.test.ts b/packages/agent-runtime/src/templates/__tests__/strings.test.ts index 89a11a4aab..b77a115cec 100644 --- a/packages/agent-runtime/src/templates/__tests__/strings.test.ts +++ b/packages/agent-runtime/src/templates/__tests__/strings.test.ts @@ -1,7 +1,8 @@ import { TEST_AGENT_RUNTIME_IMPL } from '@codebuff/common/testing/impl/agent-runtime' import { describe, test, expect, mock } from 'bun:test' -import { getAgentPrompt } from '../strings' +import { PLACEHOLDER } from '../types' +import { formatCurrentDate, getAgentPrompt } from '../strings' import type { AgentTemplate } from '../types' import type { AgentState } from '@codebuff/common/types/session-state' @@ -81,6 +82,38 @@ const createMockAgentTemplate = ( }) describe('getAgentPrompt', () => { + test('replaces CURRENT_DATE when formatting prompts', async () => { + const agentTemplate = createMockAgentTemplate({ + id: 'date-agent', + systemPrompt: `Today is ${PLACEHOLDER.CURRENT_DATE}.`, + }) + const agentTemplates: Record = { + 'date-agent': agentTemplate, + } + + const result = await getAgentPrompt({ + agentTemplate, + promptType: { type: 'systemPrompt' }, + fileContext: createMockFileContext(), + agentState: createMockAgentState('date-agent'), + agentTemplates, + additionalToolDefinitions: async () => ({}), + logger: createMockLogger(), + apiKey: TEST_AGENT_RUNTIME_IMPL.apiKey, + databaseAgentCache: TEST_AGENT_RUNTIME_IMPL.databaseAgentCache, + fetchAgentFromDatabase: TEST_AGENT_RUNTIME_IMPL.fetchAgentFromDatabase, + }) + + expect(result).toBe(`Today is ${formatCurrentDate(new Date())}.`) + expect(result).not.toContain(PLACEHOLDER.CURRENT_DATE) + }) + + test('formats current date for prompts', () => { + expect(formatCurrentDate(new Date(2026, 4, 22, 12))).toBe( + 'May 22, 2026', + ) + }) + describe('spawnerPrompt inclusion in instructionsPrompt', () => { test('includes spawnerPrompt for each spawnable agent with spawnerPrompt defined', async () => { const filePickerTemplate = createMockAgentTemplate({ diff --git a/packages/agent-runtime/src/templates/strings.ts b/packages/agent-runtime/src/templates/strings.ts index 6ac005a151..8391900fc1 100644 --- a/packages/agent-runtime/src/templates/strings.ts +++ b/packages/agent-runtime/src/templates/strings.ts @@ -29,6 +29,14 @@ import type { ProjectFileContext, } from '@codebuff/common/util/file' +export function formatCurrentDate(date: Date): string { + return new Intl.DateTimeFormat('en-US', { + year: 'numeric', + month: 'long', + day: 'numeric', + }).format(date) +} + export async function formatPrompt( params: { prompt: string @@ -85,6 +93,7 @@ export async function formatPrompt( const toInject: Record string | Promise> = { [PLACEHOLDER.AGENT_NAME]: () => agentTemplate ? agentTemplate.displayName || 'Unknown Agent' : 'Buffy', + [PLACEHOLDER.CURRENT_DATE]: () => formatCurrentDate(new Date()), [PLACEHOLDER.FILE_TREE_PROMPT_SMALL]: () => getProjectFileTreePrompt({ fileContext, diff --git a/packages/agent-runtime/src/templates/types.ts b/packages/agent-runtime/src/templates/types.ts index 6ce6739631..7131183991 100644 --- a/packages/agent-runtime/src/templates/types.ts +++ b/packages/agent-runtime/src/templates/types.ts @@ -13,6 +13,7 @@ export type { AgentTemplate, StepGenerator, StepHandler } const placeholderNames = [ 'AGENT_NAME', + 'CURRENT_DATE', 'FILE_TREE_PROMPT_SMALL', 'FILE_TREE_PROMPT', 'FILE_TREE_PROMPT_LARGE',