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

Function parse_multi_file_full

openspace/skill_engine/patch.py:382–417  ·  view source on GitHub ↗

Parse ``*** Begin Files`` format into ``{relative_path: content}``. Falls back to ``{SKILL.md: content}`` if no markers are found (single-file).

(content: str)

Source from the content-addressed store, hash-verified

380
381
382def parse_multi_file_full(content: str) -> Dict[str, str]:
383 """Parse ``*** Begin Files`` format into ``{relative_path: content}``.
384
385 Falls back to ``{SKILL.md: content}`` if no markers are found (single-file).
386 """
387 # Strip optional envelope
388 stripped = content.strip()
389 if stripped.startswith("*** Begin Files"):
390 stripped = stripped[len("*** Begin Files"):].strip()
391 # Strip *** End Files and anything after it (e.g. stray <EVOLUTION_COMPLETE> tokens)
392 end_files_idx = stripped.rfind("*** End Files")
393 if end_files_idx != -1:
394 stripped = stripped[:end_files_idx].strip()
395
396 # Find all *** File: headers
397 headers = list(_FILE_HEADER_RE.finditer(stripped))
398 if not headers:
399 # No multi-file markers — treat entire content as SKILL.md
400 return {SKILL_FILENAME: content}
401
402 files: Dict[str, str] = {}
403 for i, match in enumerate(headers):
404 file_path = match.group(1).strip()
405 start = match.end()
406 # Content extends to the next header or end of string
407 if i + 1 < len(headers):
408 end = headers[i + 1].start()
409 else:
410 end = len(stripped)
411 file_content = stripped[start:end].strip("\n")
412 # Preserve one trailing newline for non-empty files
413 if file_content and not file_content.endswith("\n"):
414 file_content += "\n"
415 files[file_path] = file_content
416
417 return files
418
419
420def _apply_multi_file_full(content: str, skill_dir: Path) -> None:

Callers 1

_apply_multi_file_fullFunction · 0.85

Calls 1

startMethod · 0.45

Tested by

no test coverage detected