mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Remove unused apply_patch prompt fallback (#38291)
## What changed - Delete the unused standalone `apply_patch` instruction template and its `codex-prompts` export. - Simplify prompt-caching coverage to assert that requests use the model's base instructions. GitOrigin-RevId: 8c0dc9426d9ac0184d587272622db608a75e8436
This commit is contained in:
1 parent
5104cb649e
commit
8d637ae398
4 files changed
+2
-95
No files matched your search
@@ -6,7 +6,6 @@ use std::path::Path;
|
|||||||
use codex_core::TurnInputRequest;
|
use codex_core::TurnInputRequest;
|
||||||
use codex_core::shell::default_user_shell;
|
use codex_core::shell::default_user_shell;
|
||||||
use codex_features::Feature;
|
use codex_features::Feature;
|
||||||
use codex_prompts::APPLY_PATCH_TOOL_INSTRUCTIONS;
|
|
||||||
use codex_protocol::config_types::CollaborationMode;
|
use codex_protocol::config_types::CollaborationMode;
|
||||||
use codex_protocol::config_types::ModeKind;
|
use codex_protocol::config_types::ModeKind;
|
||||||
use codex_protocol::config_types::ReasoningSummary;
|
use codex_protocol::config_types::ReasoningSummary;
|
||||||
@@ -198,23 +197,11 @@ async fn prompt_tools_are_consistent_across_requests() -> anyhow::Result<()> {
|
|||||||
]);
|
]);
|
||||||
let body0 = req1.single_request().body_json();
|
let body0 = req1.single_request().body_json();
|
||||||
|
|
||||||
let expected_instructions = if expected_tools_names.contains(&"apply_patch") {
|
assert_eq!(body0["instructions"], serde_json::json!(base_instructions),);
|
||||||
base_instructions
|
|
||||||
} else {
|
|
||||||
[base_instructions, APPLY_PATCH_TOOL_INSTRUCTIONS.to_string()].join("\n")
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
body0["instructions"],
|
|
||||||
serde_json::json!(expected_instructions),
|
|
||||||
);
|
|
||||||
assert_tool_names(&body0, &expected_tools_names);
|
assert_tool_names(&body0, &expected_tools_names);
|
||||||
|
|
||||||
let body1 = req2.single_request().body_json();
|
let body1 = req2.single_request().body_json();
|
||||||
assert_eq!(
|
assert_eq!(body1["instructions"], serde_json::json!(base_instructions),);
|
||||||
body1["instructions"],
|
|
||||||
serde_json::json!(expected_instructions),
|
|
||||||
);
|
|
||||||
assert_tool_names(&body1, &expected_tools_names);
|
assert_tool_names(&body1, &expected_tools_names);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
/// Detailed instructions for gpt-4.1 on how to use the `apply_patch` tool.
|
|
||||||
pub const APPLY_PATCH_TOOL_INSTRUCTIONS: &str =
|
|
||||||
include_str!("../templates/apply_patch_tool_instructions.md");
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
mod apply_patch;
|
|
||||||
mod compact;
|
mod compact;
|
||||||
mod goals;
|
mod goals;
|
||||||
mod permissions_instructions;
|
mod permissions_instructions;
|
||||||
@@ -6,7 +5,6 @@ mod realtime;
|
|||||||
mod review_exit;
|
mod review_exit;
|
||||||
mod review_request;
|
mod review_request;
|
||||||
|
|
||||||
pub use apply_patch::APPLY_PATCH_TOOL_INSTRUCTIONS;
|
|
||||||
pub use compact::SUMMARIZATION_PROMPT;
|
pub use compact::SUMMARIZATION_PROMPT;
|
||||||
pub use compact::SUMMARY_PREFIX;
|
pub use compact::SUMMARY_PREFIX;
|
||||||
pub use goals::budget_limit_prompt;
|
pub use goals::budget_limit_prompt;
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
## `apply_patch`
|
|
||||||
|
|
||||||
Use the `apply_patch` shell command to edit files.
|
|
||||||
Your patch language is a stripped‑down, file‑oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high‑level envelope:
|
|
||||||
|
|
||||||
*** Begin Patch
|
|
||||||
[ one or more file sections ]
|
|
||||||
*** End Patch
|
|
||||||
|
|
||||||
Within that envelope, you get a sequence of file operations.
|
|
||||||
You MUST include a header to specify the action you are taking.
|
|
||||||
Each operation starts with one of three headers:
|
|
||||||
|
|
||||||
*** Add File: <path> - create a new file. Every following line is a + line (the initial contents).
|
|
||||||
*** Delete File: <path> - remove an existing file. Nothing follows.
|
|
||||||
*** Update File: <path> - patch an existing file in place (optionally with a rename).
|
|
||||||
|
|
||||||
May be immediately followed by *** Move to: <new path> if you want to rename the file.
|
|
||||||
Then one or more “hunks”, each introduced by @@ (optionally followed by a hunk header).
|
|
||||||
Within a hunk each line starts with:
|
|
||||||
|
|
||||||
For instructions on [context_before] and [context_after]:
|
|
||||||
- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.
|
|
||||||
- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:
|
|
||||||
@@ class BaseClass
|
|
||||||
[3 lines of pre-context]
|
|
||||||
- [old_code]
|
|
||||||
+ [new_code]
|
|
||||||
[3 lines of post-context]
|
|
||||||
|
|
||||||
- If a code block is repeated so many times in a class or function such that even a single `@@` statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:
|
|
||||||
|
|
||||||
@@ class BaseClass
|
|
||||||
@@ def method():
|
|
||||||
[3 lines of pre-context]
|
|
||||||
- [old_code]
|
|
||||||
+ [new_code]
|
|
||||||
[3 lines of post-context]
|
|
||||||
|
|
||||||
The full grammar definition is below:
|
|
||||||
Patch := Begin { FileOp } End
|
|
||||||
Begin := "*** Begin Patch" NEWLINE
|
|
||||||
End := "*** End Patch" NEWLINE
|
|
||||||
FileOp := AddFile | DeleteFile | UpdateFile
|
|
||||||
AddFile := "*** Add File: " path NEWLINE { "+" line NEWLINE }
|
|
||||||
DeleteFile := "*** Delete File: " path NEWLINE
|
|
||||||
UpdateFile := "*** Update File: " path NEWLINE [ MoveTo ] { Hunk }
|
|
||||||
MoveTo := "*** Move to: " newPath NEWLINE
|
|
||||||
Hunk := "@@" [ header ] NEWLINE { HunkLine } [ "*** End of File" NEWLINE ]
|
|
||||||
HunkLine := (" " | "-" | "+") text NEWLINE
|
|
||||||
|
|
||||||
A full patch can combine several operations:
|
|
||||||
|
|
||||||
*** Begin Patch
|
|
||||||
*** Add File: hello.txt
|
|
||||||
+Hello world
|
|
||||||
*** Update File: src/app.py
|
|
||||||
*** Move to: src/main.py
|
|
||||||
@@ def greet():
|
|
||||||
-print("Hi")
|
|
||||||
+print("Hello, world!")
|
|
||||||
*** Delete File: obsolete.txt
|
|
||||||
*** End Patch
|
|
||||||
|
|
||||||
It is important to remember:
|
|
||||||
|
|
||||||
- You must include a header with your intended action (Add/Delete/Update)
|
|
||||||
- You must prefix new lines with `+` even when creating a new file
|
|
||||||
- File references can only be relative, NEVER ABSOLUTE.
|
|
||||||
|
|
||||||
You can invoke apply_patch like:
|
|
||||||
|
|
||||||
```
|
|
||||||
shell {"command":["apply_patch","*** Begin Patch\n*** Add File: hello.txt\n+Hello, world!\n*** End Patch\n"]}
|
|
||||||
```
|
|
||||||
Reference in new issue
Block a user