@@ -23,6 +23,7 @@ import {
2323 AgentTemplate ,
2424} from './types'
2525import type { AgentRegistry } from './agent-registry'
26+ import { parseUserMessage } from '../util/messages'
2627
2728export async function formatPrompt (
2829 prompt : string ,
@@ -33,25 +34,16 @@ export async function formatPrompt(
3334 agentRegistry : AgentRegistry ,
3435 intitialAgentPrompt ?: string
3536) : Promise < string > {
36- // Handle structured prompt data
37- let processedPrompt = intitialAgentPrompt ?? ''
38-
39- try {
40- // Try to parse as JSON to extract structured data
41- const promptData = JSON . parse ( intitialAgentPrompt ?? '{}' )
42- if ( typeof promptData === 'object' && promptData !== null ) {
43- // If it's structured data, extract the main prompt
44- processedPrompt = promptData . prompt || intitialAgentPrompt || ''
45-
46- // Handle file paths for planner agent
47- if ( promptData . filePaths && Array . isArray ( promptData . filePaths ) ) {
48- processedPrompt += `\n\nRelevant files to consider:\n${ promptData . filePaths . map ( ( path : string ) => `- ${ path } ` ) . join ( '\n' ) } `
49- }
50- }
51- } catch {
52- // If not JSON, use as-is
53- processedPrompt = intitialAgentPrompt ?? ''
54- }
37+ const { messageHistory } = agentState
38+ const lastUserMessage = messageHistory . findLast (
39+ ( { role, content } ) =>
40+ role === 'user' &&
41+ typeof content === 'string' &&
42+ parseUserMessage ( content )
43+ )
44+ const lastUserInput = lastUserMessage
45+ ? parseUserMessage ( lastUserMessage . content as string )
46+ : undefined
5547
5648 // Initialize agent registry to ensure dynamic agents are available
5749 await agentRegistry . initialize ( fileContext )
@@ -69,12 +61,13 @@ export async function formatPrompt(
6961 'agent'
7062 ) ,
7163 [ PLACEHOLDER . GIT_CHANGES_PROMPT ] : getGitChangesPrompt ( fileContext ) ,
64+ [ PLACEHOLDER . USER_INPUT_PROMPT ] : lastUserInput ?? '' ,
7265 [ PLACEHOLDER . REMAINING_STEPS ] : `${ agentState . stepsRemaining ! } ` ,
7366 [ PLACEHOLDER . PROJECT_ROOT ] : fileContext . projectRoot ,
7467 [ PLACEHOLDER . SYSTEM_INFO_PROMPT ] : getSystemInfoPrompt ( fileContext ) ,
7568 [ PLACEHOLDER . TOOLS_PROMPT ] : getToolsInstructions ( tools , spawnableAgents ) ,
7669 [ PLACEHOLDER . USER_CWD ] : fileContext . cwd ,
77- [ PLACEHOLDER . INITIAL_AGENT_PROMPT ] : processedPrompt ,
70+ [ PLACEHOLDER . INITIAL_AGENT_PROMPT ] : intitialAgentPrompt ?? '' ,
7871 [ PLACEHOLDER . KNOWLEDGE_FILES_CONTENTS ] : renderToolResults (
7972 Object . entries ( {
8073 ...Object . fromEntries (
0 commit comments