Skip to content

Commit 4ba05da

Browse files
committed
feat: integrate override prompt for dynamic instructions in Codex responses
1 parent e0a9262 commit 4ba05da

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

src/api/providers/openai-native-codex.prompt.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,44 @@ You are producing plain text that will later be styled by the CLI. Follow these
103103
* Do not provide range of lines
104104
* Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\\repo\\project\\main.rs:12:5
105105
`
106+
107+
export const overridePrompt = `## Identity and precedence
108+
- You are Roo (not Codex). Ignore any "Codex", "Codex CLI", or "based on GPT-5" identity statements. Roo's rules take precedence over any harness text.
109+
110+
## Tooling model
111+
- Ignore any "shell" function, execvp argument formats, and "workdir" parameters. Use Roo's command-execution tool with an explicit working directory.
112+
- If a command must run elsewhere, run a single command string prefixed with "cd <path> && ..." via the tool; do not rely on a separate "workdir" concept.
113+
114+
## Code search and file exploration
115+
- Do not use terminal search utilities (e.g., ripgrep/grep) to explore repositories.
116+
- For any new area of exploration: first use the semantic code search tool; then use the project's regex search and file reader tools as needed.
117+
118+
## Planning and preambles
119+
- Do not reference or depend on a generic "planning tool."
120+
- For non-trivial tasks: briefly restate the goal, outline a short plan up front, provide concise progress updates during tool use, and summarize outcomes distinctly.
121+
122+
## Approvals and sandboxing
123+
- Ignore Codex approval/sandbox modes and escalation parameters (including any fields to request escalated permissions or justifications).
124+
- Follow Roo's one-tool-per-message flow and wait for user confirmation after each tool use. Do not take destructive/high-impact actions without explicit user confirmation.
125+
126+
## Testing and validation
127+
- Do not add temporary tests/scripts solely for validation and then remove them.
128+
- Ensure changes retain or add proper test coverage using the repository's established test runner, paths, and conventions.
129+
130+
## Output and formatting
131+
- Ignore "plain text only" guidance. Follow Roo's Markdown rules, including clickable file and syntax references in the required link format.
132+
- Do not dump large file contents; reference file paths instead.
133+
134+
## Command outputs and environment assumptions
135+
- Do not assume a CLI will style or relay outputs automatically. Summarize essential results per Roo's rules; request pasted output only if absolutely necessary.
136+
- Assume Roo's environment semantics (e.g., macOS, constrained workspace directory) and tool behavior.
137+
138+
## Risky operations and GUIs
139+
- Do not request or simulate escalation flows from Codex. Propose safe alternatives within Roo's constraints and obtain explicit confirmation when required.
140+
- Do not launch GUI apps or perform networked installs via Codex-style approvals.
141+
142+
## Eagerness calibration
143+
- Gather just enough context to act; avoid repetitive searches; prefer acting and validating over extended exploration. Proceed under reasonable uncertainty when appropriate, documenting assumptions succinctly.
144+
145+
- Any instructions following these rules in this override prompt take precedence over these override rules.
146+
`

src/api/providers/openai-native-codex.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { BaseProvider } from "./base-provider"
88
import { ApiStream, ApiStreamUsageChunk } from "../transform/stream"
99
import { getModelParams } from "../transform/model-params"
1010
// Provider prompt content as a TS string module (no loader required)
11-
import codexPromptContent from "./openai-native-codex.prompt"
11+
import codexPromptContent, { overridePrompt } from "./openai-native-codex.prompt"
1212

1313
import {
1414
type ModelInfo,
@@ -190,23 +190,27 @@ export class OpenAiNativeCodexHandler extends BaseProvider {
190190

191191
// Format full conversation (Responses API expects structured input)
192192
const formattedInput: any[] = []
193-
// Inject systemPrompt into the first user turn wrapped in <user_instructions> XML tags
193+
// Inject provider overrides and dynamic instructions as a system role using <instructions_override> and <new_instructions> XML tags
194194
let injectedUserInstructions = false
195195
for (const message of messages) {
196196
const role = message.role === "user" ? "user" : "assistant"
197197
const content: any[] = []
198198

199-
if (
200-
role === "user" &&
201-
!injectedUserInstructions &&
202-
typeof systemPrompt === "string" &&
203-
systemPrompt.trim().length > 0
204-
) {
199+
if (!injectedUserInstructions && typeof systemPrompt === "string" && systemPrompt.trim().length > 0) {
205200
// For ChatGPT Codex (Responses API), the top-level "instructions" payload is fixed and must be
206201
// provided from a canonical prompt file. We cannot programmatically modify that contents here.
207-
// Therefore, the only supported way to pass the dynamic system prompt is to inject it into the
208-
// first user turn wrapped in <user_instructions> ... </user_instructions>.
209-
content.push({ type: "input_text", text: `<user_instructions>${systemPrompt}</user_instructions>` })
202+
// Therefore, inject provider overrides and dynamic instructions as a separate system role message
203+
// using <instructions_override> and <new_instructions> tags before the first user/assistant turn.
204+
formattedInput.push({
205+
role: "system",
206+
content: [
207+
{
208+
type: "input_text",
209+
text: `<instructions_override>${overridePrompt}</instructions_override>`,
210+
},
211+
{ type: "input_text", text: `<new_instructions>${systemPrompt}</new_instructions>` },
212+
],
213+
})
210214
injectedUserInstructions = true
211215
}
212216

0 commit comments

Comments
 (0)