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

Function compute_unified_diff

openspace/skill_engine/patch.py:903–918  ·  view source on GitHub ↗

Unified diff (git diff format) between two strings.

(
    original: str,
    updated: str,
    *,
    filename: str = SKILL_FILENAME,
    context: int = 3,
)

Source from the content-addressed store, hash-verified

901
902# DIFF COMPUTATION & SNAPSHOT
903def compute_unified_diff(
904 original: str,
905 updated: str,
906 *,
907 filename: str = SKILL_FILENAME,
908 context: int = 3,
909) -> str:
910 """Unified diff (git diff format) between two strings."""
911 diff_lines = difflib.unified_diff(
912 original.splitlines(keepends=True),
913 updated.splitlines(keepends=True),
914 fromfile=f"a/{filename}",
915 tofile=f"b/{filename}",
916 n=context,
917 )
918 return "".join(diff_lines)
919
920def compute_skill_diff(old_dir: Path, new_dir: Path) -> str:
921 """Compare all files in two skill directories, return combined diff."""

Callers 4

create_skillFunction · 0.85
compute_skill_diffFunction · 0.85
_compute_files_diffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected