Skip to content

Commit a749e36

Browse files
committed
Escape placeholder prompts.
1 parent dc94a9f commit a749e36

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

backend/src/templates/strings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getShortToolInstructions, getToolsInstructions } from '../tools'
1414

1515
import { renderToolResults, ToolName } from '@codebuff/common/constants/tools'
1616
import { ProjectFileContext } from '@codebuff/common/util/file'
17-
import { generateCompactId } from '@codebuff/common/util/string'
17+
import { escapeString, generateCompactId } from '@codebuff/common/util/string'
1818
import { agentTemplates } from './agent-list'
1919
import {
2020
PLACEHOLDER,
@@ -61,13 +61,13 @@ export async function formatPrompt(
6161
'agent'
6262
),
6363
[PLACEHOLDER.GIT_CHANGES_PROMPT]: getGitChangesPrompt(fileContext),
64-
[PLACEHOLDER.USER_INPUT_PROMPT]: lastUserInput ?? '',
6564
[PLACEHOLDER.REMAINING_STEPS]: `${agentState.stepsRemaining!}`,
6665
[PLACEHOLDER.PROJECT_ROOT]: fileContext.projectRoot,
6766
[PLACEHOLDER.SYSTEM_INFO_PROMPT]: getSystemInfoPrompt(fileContext),
6867
[PLACEHOLDER.TOOLS_PROMPT]: getToolsInstructions(tools, spawnableAgents),
6968
[PLACEHOLDER.USER_CWD]: fileContext.cwd,
70-
[PLACEHOLDER.INITIAL_AGENT_PROMPT]: intitialAgentPrompt ?? '',
69+
[PLACEHOLDER.USER_INPUT_PROMPT]: escapeString(lastUserInput ?? ''),
70+
[PLACEHOLDER.INITIAL_AGENT_PROMPT]: escapeString(intitialAgentPrompt ?? ''),
7171
[PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS]: renderToolResults(
7272
Object.entries({
7373
...Object.fromEntries(

common/src/util/string.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,7 @@ export function suffixPrefixOverlap(source: string, next: string): string {
339339

340340
return ''
341341
}
342+
343+
export const escapeString = (str: string) => {
344+
return JSON.stringify(str).slice(1, -1)
345+
}

0 commit comments

Comments
 (0)