AdithyaSK's picture
AdithyaSK HF Staff
MiMo-V2.6-RL code in Harbor (mimo_harbor 1.2.0): hardening + plain-language deviations, Daytona job
b0e054a verified
Raw History Blame Contribute Delete
5.07 kB
#!/bin/bash
# Runs once, as root, before the agent starts: Harbor's [environment.healthcheck] unpacks this folder into
# /var/lib/mimo and runs it. Generated by mimo_harbor; see its README for how each step maps to Xiaomi's harness.
M=/var/lib/mimo
[ -f "$M/ready" ] && exit 0
chmod 700 "$M"
fail() { echo "setup: $*" >&2; exit 1; }
# the answer-leak blocklist (mimoagent), applied to /etc/hosts by the agent right after it installs
write_blocklist() { cp "$M/files/blocklist" "$M/blocklist"; }
# Code: mimoagent environments/datasets/opensource_code.py + base.py, as the explorer runs it (app/runner/domains.py Code).
CWD=/testbed
git config --global --add safe.directory "$CWD"
cd "$CWD" || fail "no working directory $CWD"
if ! git rev-parse --git-dir >/dev/null 2>&1; then # a bare source tree: give it a baseline commit
git init -q && git add -A && git -c user.name=mimo -c user.email=mimo@localhost commit -q -m baseline --allow-empty
fi
BASE=$(git rev-parse HEAD 2>/dev/null)
[ ${#BASE} -eq 40 ] || fail "could not resolve the base commit in $CWD"
echo "$BASE" > "$M/base"
# Images are built with history truncated at the base. If one is not, the fix could be read out of git log,
# so .git is hidden while the agent works and put back for grading.
LATER=$(git rev-list --all --not "$BASE" 2>/dev/null | head -n 5 | grep -c . || true)
rm -rf /testbed/node_modules/.cache /testbed/node_modules/.vitest 2>/dev/null; true
rm -f /tmp/fail.log /tmp/pass.log /tmp/patch.diff /tmp/test_patch.diff /tmp/*.log 2>/dev/null; rm -rf /tmp/claude-0 /tmp/claude-* /tmp/testem-* /tmp/puppeteer_dev_chrome_profile-* 2>/dev/null; rm -f /tmp/test_files.json 2>/dev/null; rm -rf /tmp/jest_* /tmp/jest-* /tmp/build /tmp/build_env 2>/dev/null; rm -rf /tmp/pytest-of-root /tmp/pytest-* /tmp/.pytest_cache /tmp/__pycache__ 2>/dev/null; rm -rf /tmp/go-build* /tmp/standards /tmp/wordpress /tmp/zig-* /tmp/testbase /tmp/testbed 2>/dev/null; rm -f /tmp/tmp*.tmp /tmp/*.bak /tmp/expect* /tmp/butwas* 2>/dev/null; rm -rf /root/.cache/go-build 2>/dev/null; rm -rf /tests 2>/dev/null; find /logs -mindepth 1 -delete 2>/dev/null; mkdir -p /logs/agent /logs/verifier /logs/artifacts; chmod 777 /logs/agent /logs/verifier /logs/artifacts; find /var/log -type f -delete 2>/dev/null || true; rm -rf /var/lib/postgresql/*/*/log /var/lib/postgresql/*/*/pg_log 2>/dev/null || true; find /var/lib/mysql /var/lib/mongodb -type f -name '*.log' -delete 2>/dev/null || true; rm -rf /root/.npm/_logs /root/.babel.json /root/.pytest_cache 2>/dev/null || true; find / -maxdepth 4 -xdev -name task_description.md -path '*/.build_env/*' -delete 2>/dev/null || true; true
git clean -fdx --exclude=node_modules --exclude=bower_components --exclude=.husky --exclude=vendor --exclude=third_party --exclude=_deps --exclude=vcpkg_installed --exclude=.venv --exclude=venv --exclude=.gradle --exclude=target --exclude=.build --exclude=lib --exclude=.bundle --exclude=Manifest.toml --exclude=_build --exclude=.stack-work --exclude=dist-newstyle >/dev/null 2>&1
find /root/.m2 -type f \( -name '*-SNAPSHOT.jar' -o -name '*-SNAPSHOT-sources.jar' -o -name '*-SNAPSHOT-tests.jar' -o -name '*-SNAPSHOT-test-sources.jar' \) -delete 2>/dev/null; rm -rf /root/.julia/compiled 2>/dev/null; rm -rf /root/.gradle/caches/build-cache-* /root/.gradle/daemon 2>/dev/null; rm -rf /root/.gradle/caches/*/scripts /root/.gradle/caches/jars-* 2>/dev/null; rm -rf /root/.cache/bazel 2>/dev/null; true
if [ "$LATER" -gt 0 ]; then
# mimoagent's default git_leak_prevention is "strip": physically remove the fix-bearing future commits in place so
# .git stays usable and nothing leaks, even to a root agent. Hide .git only if the strip can't be verified; grading
# (code_test.sh) restores a hidden .git before it applies the test patch.
if ( set -eo pipefail
git checkout --detach $BASE 2>/dev/null || true
git for-each-ref --format="%(refname)" refs/heads | while read r; do git update-ref -d "$r" 2>/dev/null; done || true
git remote | xargs -r -n1 git remote remove 2>/dev/null || true
git for-each-ref --format="%(refname)" refs/replace refs/notes refs/stash refs/remotes refs/pull 2>/dev/null | while read r; do git update-ref -d "$r" 2>/dev/null; done || true
git for-each-ref --format="%(refname)" refs/tags | while read t; do if ! git merge-base --is-ancestor "$t" $BASE 2>/dev/null; then git tag -d "${t#refs/tags/}" >/dev/null 2>&1; fi; done || true
git reflog expire --expire=now --all 2>/dev/null || true
git -c gc.pruneExpire=now -c gc.cruftPacks=false gc --prune=now 2>/dev/null || true
set -euo pipefail
TARGET_TIMESTAMP=$(git show -s --format=%ci $BASE)
AFTER_TIMESTAMP=$(date -d "$TARGET_TIMESTAMP + 1 second" '+%Y-%m-%d %H:%M:%S')
COMMIT_COUNT=$(git log --oneline --all --since="$AFTER_TIMESTAMP" | wc -l)
[ "$COMMIT_COUNT" -eq 0 ] ); then
echo "history not truncated at ${BASE:0:12}: future commits stripped in place"
else
mv "$CWD/.git" "$M/git-hidden" && echo "history not truncated and unstrippable: .git hidden while the agent works"
fi
fi
write_blocklist
touch "$M/ready"
echo "setup done"