File size: 2,794 Bytes
216004d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | from __future__ import annotations
# runtime: dev-only (writes outside repo)
import argparse
import shutil
from datetime import datetime
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
COPY_FILES = [
"AGENTS.md",
"scripts/wiki_check.py",
"scripts/raw_manifest_check.py",
"scripts/init_raw_root.py",
]
COPY_DIRS = [
("docs/wiki", "docs/wiki"),
("manifests", "manifests"),
]
OPTIONAL_COPY_DIRS = [
("verified_cases", "verified_cases"),
("backend/verified_cases", "verified_cases"),
]
def wipe_path(path: Path) -> None:
if not path.exists():
return
if path.is_dir():
shutil.rmtree(path)
else:
path.unlink()
def copy_file(src: Path, dest: Path) -> None:
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(src, dest)
def copy_dir(src: Path, dest: Path) -> None:
if dest.exists():
shutil.rmtree(dest)
shutil.copytree(src, dest)
def main() -> int:
parser = argparse.ArgumentParser(description="Export the repo memory surface into a dedicated GitHub/wiki repo checkout.")
parser.add_argument("target_dir", help="Target memory repo checkout directory")
args = parser.parse_args()
target = Path(args.target_dir).expanduser().resolve()
target.mkdir(parents=True, exist_ok=True)
managed_paths = [
target / "AGENTS.md",
target / "README.md",
target / "docs",
target / "manifests",
target / "verified_cases",
target / "scripts",
]
for path in managed_paths:
wipe_path(path)
exported_at = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
readme = f"""# Memory Repo
This repo is the exported long-term memory surface for a project.
## What belongs here
- `docs/wiki/`
- `manifests/`
- `verified_cases/`
- repo-level operating rules such as `AGENTS.md`
## What does not belong here
- raw PDFs / XLSX / XLS / ZIP / RAR files
- main application runtime code
- build artifacts
## Export time
`{exported_at}`
## Source repo
`{ROOT}`
## Refresh
Run from the source repo:
```bash
python3 scripts/export_memory_repo.py /path/to/memory-repo-checkout
```
"""
(target / "README.md").write_text(readme, encoding="utf-8")
for rel in COPY_FILES:
src = ROOT / rel
if src.exists():
copy_file(src, target / rel)
for src_rel, dest_rel in COPY_DIRS:
src = ROOT / src_rel
if src.exists():
copy_dir(src, target / dest_rel)
for src_rel, dest_rel in OPTIONAL_COPY_DIRS:
src = ROOT / src_rel
if src.exists():
copy_dir(src, target / dest_rel)
break
print(f"Exported memory repo snapshot to: {target}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
|