Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions agents/base2/base2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?: {
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions agents/types/secret-agent-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
35 changes: 34 additions & 1 deletion packages/agent-runtime/src/templates/__tests__/strings.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<string, AgentTemplate> = {
'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({
Expand Down
9 changes: 9 additions & 0 deletions packages/agent-runtime/src/templates/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,6 +93,7 @@ export async function formatPrompt(
const toInject: Record<PlaceholderValue, () => string | Promise<string>> = {
[PLACEHOLDER.AGENT_NAME]: () =>
agentTemplate ? agentTemplate.displayName || 'Unknown Agent' : 'Buffy',
[PLACEHOLDER.CURRENT_DATE]: () => formatCurrentDate(new Date()),
[PLACEHOLDER.FILE_TREE_PROMPT_SMALL]: () =>
getProjectFileTreePrompt({
fileContext,
Expand Down
1 change: 1 addition & 0 deletions packages/agent-runtime/src/templates/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading