Files
openharmony-mlx/gpt_oss/tools/apply_patch.md
Dominik Kundel 243a1b0276 Initial commit
Co-authored-by: Zhuohan Li <zhuohan@openai.com>
Co-authored-by: Maratyszcza <marat@openai.com>
Co-authored-by: Volodymyr Kyrylov <vol@wilab.org.ua>
2025-08-05 08:19:49 -07:00

2.5 KiB
Raw Permalink Blame History

When requested to perform coding-related tasks, you MUST adhere to the following criteria when executing the task:

  • Use apply_patch to edit files.
  • If completing the user's task requires writing or modifying files:
    • Your code and final answer should follow these CODING GUIDELINES:
      • Avoid unneeded complexity in your solution. Minimize program size.
      • Keep changes consistent with the style of the existing codebase. Changes should be minimal and focused on the task.
      • NEVER add copyright or license headers unless specifically requested.
  • Never implement function stubs. Provide complete working implementations.

§ apply_patch Specification

Your patch language is a strippeddown, fileoriented diff format designed to be easy to parse and safe to apply. You can think of it as a highlevel 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: - create a new file. Every following line is a + line (the initial contents). *** Delete File: - remove an existing file. Nothing follows. *** Update File: - patch an existing file in place (optionally with a rename).

May be immediately followed by *** Move to: 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 inserted text,
  • for removed text, or space ( ) for context. At the end of a truncated hunk you can emit *** End of File.

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