feat(skill-learning): merge plugin skill updates

This commit is contained in:
2026-06-16 11:55:55 +08:00
parent c9e6c37b5c
commit a34b1219bc
15 changed files with 860 additions and 5 deletions

View File

@ -32,6 +32,30 @@ def check_preservation(*, base_content: str, draft_content: str) -> dict[str, An
}
def check_plugin_merge_preservation(
*,
local_content: str,
upstream_content: str,
draft_content: str,
merge_decisions: dict[str, Any],
) -> dict[str, Any]:
local = check_preservation(base_content=local_content, draft_content=draft_content)
upstream = check_preservation(base_content=upstream_content, draft_content=draft_content)
unresolved = [str(item) for item in merge_decisions.get("unresolved_conflicts") or []]
safety_sections_missing = _important_sections_missing(upstream, local)
passed = bool(local.get("passed")) and bool(upstream.get("passed")) and not unresolved and not safety_sections_missing
return {
"mode": "plugin_three_way",
"passed": passed,
"risk_level": "high" if not passed else "low",
"local": local,
"upstream": upstream,
"unresolved_conflicts": unresolved,
"safety_sections_missing": safety_sections_missing,
"resolved_conflicts": [str(item) for item in merge_decisions.get("resolved_conflicts") or []],
}
def _sections(content: str) -> dict[str, str]:
current = "body"
sections: dict[str, list[str]] = {current: []}
@ -51,3 +75,13 @@ def _sections(content: str) -> dict[str, str]:
def _normalize(value: str) -> str:
return re.sub(r"\s+", " ", value or "").strip().lower()
def _important_sections_missing(*reports: dict[str, Any]) -> list[str]:
important = {"safety", "required tools", "required tool", "tools"}
missing: list[str] = []
for report in reports:
for section in report.get("dropped_sections") or []:
if str(section).strip().lower() in important and str(section) not in missing:
missing.append(str(section))
return missing