From 678f0dbfec8bf863f907764d8cc1ab351678021f Mon Sep 17 00:00:00 2001 From: Fouad Matin <169186268+fouad-openai@users.noreply.github.com> Date: Wed, 14 May 2025 01:27:46 -0700 Subject: [PATCH] add: dynamic instructions (#927) --- .../chat/terminal-chat-response-item.tsx | 8 +++----- .../chat/terminal-message-history.tsx | 10 +++++++++- codex-cli/src/utils/agent/agent-loop.ts | 19 ++++++++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/codex-cli/src/components/chat/terminal-chat-response-item.tsx b/codex-cli/src/components/chat/terminal-chat-response-item.tsx index a81d5414..747c3dfc 100644 --- a/codex-cli/src/components/chat/terminal-chat-response-item.tsx +++ b/codex-cli/src/components/chat/terminal-chat-response-item.tsx @@ -325,14 +325,12 @@ function rewriteFileCitations( fileOpener: FileOpenerScheme | undefined, cwd: string = process.cwd(), ): string { - if (!fileOpener) { - // Should we reformat the citations even if we cannot linkify them? - return markdown; - } - citationRegex.lastIndex = 0; return markdown.replace(citationRegex, (_match, file, start, _end) => { const absPath = path.resolve(cwd, file); + if (!fileOpener) { + return `[${file}](${absPath})`; + } const uri = `${fileOpener}://file${absPath}:${start}`; const label = `${file}:${start}`; // In practice, sometimes multiple citations for the same file, but with a diff --git a/codex-cli/src/components/chat/terminal-message-history.tsx b/codex-cli/src/components/chat/terminal-message-history.tsx index 5ecf7fe0..5036f081 100644 --- a/codex-cli/src/components/chat/terminal-message-history.tsx +++ b/codex-cli/src/components/chat/terminal-message-history.tsx @@ -62,11 +62,19 @@ const TerminalMessageHistory: React.FC = ({ key={`${message.id}-${index}`} flexDirection="column" marginLeft={ - message.type === "message" && message.role === "user" ? 0 : 4 + message.type === "message" && + (message.role === "user" || message.role === "assistant") + ? 0 + : 4 } marginTop={ message.type === "message" && message.role === "user" ? 0 : 1 } + marginBottom={ + message.type === "message" && message.role === "assistant" + ? 1 + : 0 + } > = [ + `User: ${userName}`, + `Workdir: ${workdir}`, +]; +if (spawnSync("rg", ["--version"], { stdio: "ignore" }).status === 0) { + dynamicLines.push( + "- Always use rg instead of grep/ls -R because it is much faster and respects gitignore", + ); +} +const dynamicPrefix = dynamicLines.join("\n") + "\n\n"; const prefix = `You are operating as and within the Codex CLI, a terminal-based agentic coding assistant built by OpenAI. It wraps OpenAI models to enable natural language interaction with a local codebase. You are expected to be precise, safe, and helpful. You can: @@ -1535,7 +1550,9 @@ You MUST adhere to the following criteria when executing the task: - Respond in a friendly tone as a remote teammate, who is knowledgeable, capable and eager to help with coding. - When your task involves writing or modifying files: - Do NOT tell the user to "save the file" or "copy the code into a file" if you already created or modified the file using \`apply_patch\`. Instead, reference the file as already saved. - - Do NOT show the full contents of large files you have already written, unless the user explicitly asks for them.`; + - Do NOT show the full contents of large files you have already written, unless the user explicitly asks for them. + +${dynamicPrefix}`; function filterToApiMessages( items: Array,