MCPcopy
hub / github.com/openai/openai-agents-python / apply_diff

Function apply_diff

src/agents/apply_diff.py:52–65  ·  view source on GitHub ↗

Apply a V4A diff to the provided text. This parser understands both the create-file syntax (only "+" prefixed lines) and the default update syntax that includes context hunks.

(input: str, diff: str, mode: ApplyDiffMode = "default")

Source from the content-addressed store, hash-verified

50
51
52def apply_diff(input: str, diff: str, mode: ApplyDiffMode = "default") -> str:
53 """Apply a V4A diff to the provided text.
54
55 This parser understands both the create-file syntax (only "+" prefixed
56 lines) and the default update syntax that includes context hunks.
57 """
58 newline = _detect_newline(input, diff, mode)
59 diff_lines = _normalize_diff_lines(diff)
60 if mode == "create":
61 return _parse_create_diff(diff_lines, newline=newline)
62
63 normalized_input = _normalize_text_newlines(input)
64 parsed = _parse_update_diff(diff_lines, normalized_input)
65 return _apply_chunks(normalized_input, parsed.chunks, newline=newline)
66
67
68def _normalize_diff_lines(diff: str) -> list[str]:

Calls 6

_detect_newlineFunction · 0.85
_normalize_diff_linesFunction · 0.85
_parse_create_diffFunction · 0.85
_normalize_text_newlinesFunction · 0.85
_parse_update_diffFunction · 0.85
_apply_chunksFunction · 0.85