MCPcopy Create free account
hub / github.com/HKUDS/OpenSpace / apply_update_chunks

Function apply_update_chunks

openspace/skill_engine/patch.py:752–771  ·  view source on GitHub ↗

Apply *chunks* to *original_content* and return the new content.

(
    file_path: str,
    original_content: str,
    chunks: List[UpdateChunk],
)

Source from the content-addressed store, hash-verified

750 return result
751
752def apply_update_chunks(
753 file_path: str,
754 original_content: str,
755 chunks: List[UpdateChunk],
756) -> str:
757 """Apply *chunks* to *original_content* and return the new content."""
758 original_lines = original_content.split("\n")
759
760 # Drop trailing empty element for consistent line counting
761 if original_lines and original_lines[-1] == "":
762 original_lines.pop()
763
764 replacements = _compute_replacements(original_lines, file_path, chunks)
765 new_lines = _apply_replacements(original_lines, replacements)
766
767 # Ensure trailing newline
768 if not new_lines or new_lines[-1] != "":
769 new_lines.append("")
770
771 return "\n".join(new_lines)
772
773def _apply_multi_file_patch(patch_text: str, skill_dir: Path) -> None:
774 """Parse and apply a ``*** Begin Patch`` block to a skill directory.

Callers 1

_apply_multi_file_patchFunction · 0.85

Calls 2

_compute_replacementsFunction · 0.85
_apply_replacementsFunction · 0.85

Tested by

no test coverage detected