#!/bin/bash # programgen forward pre-cleanup: closed-book repo # (keep build config + provisioned deps; strip target-repo source/tests). set -euo pipefail ROOT="${1:-/workspace/repo}" cd "$ROOT" # 0. Remove the target distribution installed while provisioning deps. Both # editable and wheel installs can otherwise copy the answer into site-packages. TARGET_DIST=bvh for PROGRAMGEN_UNINSTALL_ATTEMPT in 1 2 3; do python3 - "$ROOT" "$TARGET_DIST" <<'PY' > /tmp/programgen-target-dists.txt import importlib.metadata import json import re import sys from pathlib import Path from urllib.parse import unquote, urlparse root = Path(sys.argv[1]).resolve() target = re.sub(r'[-_.]+', '-', sys.argv[2]).lower() for dist in importlib.metadata.distributions(): name = str(dist.metadata.get('Name') or '').strip() try: metadata_root = Path(dist.locate_file('')).resolve() metadata_is_local = metadata_root == root or root in metadata_root.parents except Exception: metadata_is_local = False try: direct = json.loads(dist.read_text('direct_url.json') or '{}') url = str(direct.get('url') or '') source = Path(unquote(urlparse(url).path)).resolve() if url.startswith('file:') else None except Exception: source = None normalized = re.sub(r'[-_.]+', '-', name).lower() if name and not metadata_is_local and (source == root or (target and normalized == target)): print(name) PY sort -fu /tmp/programgen-target-dists.txt -o /tmp/programgen-target-dists.txt if [ ! -s /tmp/programgen-target-dists.txt ]; then break; fi xargs -r python3 -m pip uninstall -y < /tmp/programgen-target-dists.txt done # Fail closed if a local-project distribution survived uninstall. python3 - "$ROOT" "$TARGET_DIST" <<'PY' import importlib.metadata import json import re import sys from pathlib import Path from urllib.parse import unquote, urlparse root = Path(sys.argv[1]).resolve() target = re.sub(r'[-_.]+', '-', sys.argv[2]).lower() leaks = [] for dist in importlib.metadata.distributions(): name = str(dist.metadata.get('Name') or '').strip() try: metadata_root = Path(dist.locate_file('')).resolve() metadata_is_local = metadata_root == root or root in metadata_root.parents except Exception: metadata_is_local = False try: direct = json.loads(dist.read_text('direct_url.json') or '{}') url = str(direct.get('url') or '') source = Path(unquote(urlparse(url).path)).resolve() if url.startswith('file:') else None except Exception: source = None normalized = re.sub(r'[-_.]+', '-', name).lower() if not metadata_is_local and (source == root or (target and normalized == target)): leaks.append(name or str(dist)) if leaks: raise SystemExit('target distributions remain installed: ' + ', '.join(leaks)) PY # 1. strip target-repo source + test files (build config kept) find . -type f \( -name '*.c' -o -name '*.c++' -o -name '*.cc' -o -name '*.cjs' -o -name '*.cpp' -o -name '*.cts' -o -name '*.cu' -o -name '*.cuh' -o -name '*.cxx' -o -name '*.go' -o -name '*.h' -o -name '*.h++' -o -name '*.hh' -o -name '*.hpp' -o -name '*.hxx' -o -name '*.inl' -o -name '*.ipp' -o -name '*.java' -o -name '*.js' -o -name '*.jsx' -o -name '*.kt' -o -name '*.kts' -o -name '*.mjs' -o -name '*.mts' -o -name '*.pxd' -o -name '*.pxi' -o -name '*.py' -o -name '*.pyi' -o -name '*.pyx' -o -name '*.rs' -o -name '*.tpp' -o -name '*.ts' -o -name '*.tsx' \) -not -path './setup.py' -not -path './vendor/*' -not -path './node_modules/*' -delete || true rm -rf -- tests/test_bvh.py tests/test_freebvh.bvh tests/test_mocapbank.bvh 2>/dev/null || true rm -rf tests test spec specs __tests__ 2>/dev/null || true # 2. strip build caches + editor/CI metadata (deps in ~/.cargo etc. kept) rm -rf target build dist .programgen-build .pytest_cache __pycache__ *.egg-info .github .idea 2>/dev/null || true # 2a. programgen closed-book artifact sweep v2: provisioning leftovers reproduce the stripped # implementation (bytecode, in-place compiled extensions) or its layout # (egg-info/dist-info); remove them everywhere except vendored deps. find . \( -path './vendor' -o -path './node_modules' \) -prune -o -type d \( -name '__pycache__' -o -name '*.egg-info' -o -name '*.dist-info' -o -name '.eggs' -o -name '.pytest_cache' -o -name '.mypy_cache' -o -name '.ruff_cache' -o -name '.hypothesis' -o -name '.tox' -o -name '.nox' -o -name 'htmlcov' \) -print0 2>/dev/null | xargs -0 -r rm -rf || true find . \( -path './vendor' -o -path './node_modules' \) -prune -o -type d \( -name .venv -o -name venv \) -exec test -f '{}/pyvenv.cfg' \; -print0 2>/dev/null | xargs -0 -r rm -rf || true find . \( -path './vendor' -o -path './node_modules' \) -prune -o -type d \( -path '*/build/lib.*' -o -path '*/build/temp.*' -o -path '*/build/bdist.*' -o -path '*/build/lib' \) -print0 2>/dev/null | xargs -0 -r rm -rf || true find . \( -path './vendor' -o -path './node_modules' \) -prune -o -type f \( -name '*.pyc' -o -name '*.pyo' -o -name '*.pyd' -o -name '*.cpython-*.so' -o -name '*.abi3.so' -o -name '*.cpython-*.dylib' -o -name '*.whl' -o -name '*.egg' -o -name '*.orig' -o -name '*.rej' -o -name '.coverage' -o -name '.coverage.*' \) -print0 2>/dev/null | xargs -0 -r rm -f || true # 2b. strip editable-install residue that leaks the target package name/layout # (`pip/pdm install -e .`): repo-local .pdm-build/*.egg-*, and the editable # .pth pointers in site-packages that resolve back to this repo. Third-party # dependency packages have their own dist-info and are untouched. rm -rf .pdm-build .pdm-python *.egg-link 2>/dev/null || true for SP in $(python3 -c "import site,sys;print(\"\\n\".join(set(site.getsitepackages()+[site.getusersitepackages()])))" 2>/dev/null); do [ -d "$SP" ] || continue find "$SP" -maxdepth 1 -name "__editable__*.pth" -delete 2>/dev/null || true grep -rl "$ROOT" "$SP"/*.pth 2>/dev/null | xargs -r rm -f || true done # 2c. strip docs/examples + leftover EMPTY dirs (align with DeNovoSWE clean.sh): # docs/*.rst can leak API usage; an empty package dir leaks the package # name+layout. Build config (setup.py / pyproject / lockfiles / LICENSE) # is kept; provisioned deps live outside $ROOT and are untouched. find . -type f \( -name '*.md' -o -name '*.rst' \) -delete 2>/dev/null || true find . -type d \( -name docs -o -name doc -o -name examples -o -name example \) -not -path './vendor/*' -not -path './node_modules/*' -exec rm -rf {} + 2>/dev/null || true find . -type d -empty -delete 2>/dev/null || true # 2z. programgen closed-book artifact check v2: fail closed before the baseline commit PROGRAMGEN_LEFTOVERS=$(find . \( -path './vendor' -o -path './node_modules' \) -prune -o \( -type d \( -name '__pycache__' -o -name '*.egg-info' -o -name '*.dist-info' \) -o -type f \( -name '*.pyc' -o -name '*.pyo' -o -name '*.pyd' -o -name '*.cpython-*.so' -o -name '*.abi3.so' -o -name '*.whl' -o -name '*.egg' \) \) -print 2>/dev/null | head -20 || true) if [ -n "$PROGRAMGEN_LEFTOVERS" ]; then echo "programgen closed-book leftovers remain under $ROOT:" >&2 echo "$PROGRAMGEN_LEFTOVERS" >&2 exit 1 fi # 3. git history sanitization (fresh repo, no history to mine) rm -rf .git git init -q git config user.email closed-book@programgen.local git config user.name programgen git add -f -A git commit --allow-empty -qm 'programgen forward closed-book baseline'