Skip to content

Commit e86f537

Browse files
committed
Keep base2 current date prompt fresh
1 parent dc3aad6 commit e86f537

5 files changed

Lines changed: 46 additions & 10 deletions

File tree

agents/base2/base2.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ import {
1717
type SecretAgentDefinition,
1818
} from '../types/secret-agent-definition'
1919

20-
function formatCurrentDate(date: Date): string {
21-
return new Intl.DateTimeFormat('en-US', {
22-
year: 'numeric',
23-
month: 'long',
24-
day: 'numeric',
25-
}).format(date)
26-
}
27-
2820
export function createBase2(
2921
mode: 'default' | 'free' | 'lite' | 'max' | 'fast',
3022
options?: {
@@ -138,7 +130,7 @@ export function createBase2(
138130

139131
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.
140132
141-
Current date: ${formatCurrentDate(new Date())}.
133+
Current date: ${PLACEHOLDER.CURRENT_DATE}.
142134
143135
# Core Mandates
144136

agents/types/secret-agent-definition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface SecretAgentDefinition
2323
const placeholderNames = [
2424
'AGENT_NAME',
2525
'AGENTS_PROMPT',
26+
'CURRENT_DATE',
2627
'FILE_TREE_PROMPT_SMALL',
2728
'FILE_TREE_PROMPT',
2829
'FILE_TREE_PROMPT_LARGE',

packages/agent-runtime/src/templates/__tests__/strings.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { TEST_AGENT_RUNTIME_IMPL } from '@codebuff/common/testing/impl/agent-runtime'
22
import { describe, test, expect, mock } from 'bun:test'
33

4-
import { getAgentPrompt } from '../strings'
4+
import { PLACEHOLDER } from '../types'
5+
import { formatCurrentDate, getAgentPrompt } from '../strings'
56

67
import type { AgentTemplate } from '../types'
78
import type { AgentState } from '@codebuff/common/types/session-state'
@@ -81,6 +82,38 @@ const createMockAgentTemplate = (
8182
})
8283

8384
describe('getAgentPrompt', () => {
85+
test('replaces CURRENT_DATE when formatting prompts', async () => {
86+
const agentTemplate = createMockAgentTemplate({
87+
id: 'date-agent',
88+
systemPrompt: `Today is ${PLACEHOLDER.CURRENT_DATE}.`,
89+
})
90+
const agentTemplates: Record<string, AgentTemplate> = {
91+
'date-agent': agentTemplate,
92+
}
93+
94+
const result = await getAgentPrompt({
95+
agentTemplate,
96+
promptType: { type: 'systemPrompt' },
97+
fileContext: createMockFileContext(),
98+
agentState: createMockAgentState('date-agent'),
99+
agentTemplates,
100+
additionalToolDefinitions: async () => ({}),
101+
logger: createMockLogger(),
102+
apiKey: TEST_AGENT_RUNTIME_IMPL.apiKey,
103+
databaseAgentCache: TEST_AGENT_RUNTIME_IMPL.databaseAgentCache,
104+
fetchAgentFromDatabase: TEST_AGENT_RUNTIME_IMPL.fetchAgentFromDatabase,
105+
})
106+
107+
expect(result).toBe(`Today is ${formatCurrentDate(new Date())}.`)
108+
expect(result).not.toContain(PLACEHOLDER.CURRENT_DATE)
109+
})
110+
111+
test('formats current date for prompts', () => {
112+
expect(formatCurrentDate(new Date('2026-05-22T12:00:00Z'))).toBe(
113+
'May 22, 2026',
114+
)
115+
})
116+
84117
describe('spawnerPrompt inclusion in instructionsPrompt', () => {
85118
test('includes spawnerPrompt for each spawnable agent with spawnerPrompt defined', async () => {
86119
const filePickerTemplate = createMockAgentTemplate({

packages/agent-runtime/src/templates/strings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ import type {
2929
ProjectFileContext,
3030
} from '@codebuff/common/util/file'
3131

32+
export function formatCurrentDate(date: Date): string {
33+
return new Intl.DateTimeFormat('en-US', {
34+
year: 'numeric',
35+
month: 'long',
36+
day: 'numeric',
37+
}).format(date)
38+
}
39+
3240
export async function formatPrompt(
3341
params: {
3442
prompt: string
@@ -85,6 +93,7 @@ export async function formatPrompt(
8593
const toInject: Record<PlaceholderValue, () => string | Promise<string>> = {
8694
[PLACEHOLDER.AGENT_NAME]: () =>
8795
agentTemplate ? agentTemplate.displayName || 'Unknown Agent' : 'Buffy',
96+
[PLACEHOLDER.CURRENT_DATE]: () => formatCurrentDate(new Date()),
8897
[PLACEHOLDER.FILE_TREE_PROMPT_SMALL]: () =>
8998
getProjectFileTreePrompt({
9099
fileContext,

packages/agent-runtime/src/templates/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type { AgentTemplate, StepGenerator, StepHandler }
1313

1414
const placeholderNames = [
1515
'AGENT_NAME',
16+
'CURRENT_DATE',
1617
'FILE_TREE_PROMPT_SMALL',
1718
'FILE_TREE_PROMPT',
1819
'FILE_TREE_PROMPT_LARGE',

0 commit comments

Comments
 (0)