diff --git a/lib/formula-session.sh b/lib/formula-session.sh index 789e695..7df85b0 100644 --- a/lib/formula-session.sh +++ b/lib/formula-session.sh @@ -95,14 +95,14 @@ ensure_profile_repo() { # Define cache directory: /home/agent/data/.profile/{agent-name} PROFILE_REPO_PATH="${HOME:-/home/agent}/data/.profile/${agent_identity}" - # Build clone URL from FORGE_URL and agent identity - local forge_url="${FORGE_URL:-http://localhost:3000}" - local auth_url - auth_url=$(printf '%s' "$forge_url" | sed "s|://|://$(whoami):${FORGE_TOKEN}@|") - local clone_url="${auth_url}/${agent_identity}/.profile.git" - # Check if already cached and up-to-date if [ -d "${PROFILE_REPO_PATH}/.git" ]; then + # Pull latest changes + local forge_url="${FORGE_URL:-http://localhost:3000}" + local auth_url + auth_url=$(printf '%s' "$forge_url" | sed "s|://|://$(whoami):${FORGE_TOKEN}@|") + local clone_url="${auth_url}/${agent_identity}/.profile.git" + log "Pulling .profile repo: ${agent_identity}/.profile" if git -C "$PROFILE_REPO_PATH" fetch origin --quiet 2>/dev/null; then git -C "$PROFILE_REPO_PATH" checkout main --quiet 2>/dev/null || \ @@ -114,6 +114,12 @@ ensure_profile_repo() { log "WARNING: failed to pull .profile repo, using cached version" fi else + # Clone fresh + local forge_url="${FORGE_URL:-http://localhost:3000}" + local auth_url + auth_url=$(printf '%s' "$forge_url" | sed "s|://|://$(whoami):${FORGE_TOKEN}@|") + local clone_url="${auth_url}/${agent_identity}/.profile.git" + log "Cloning .profile repo: ${agent_identity}/.profile -> ${PROFILE_REPO_PATH}" if git clone --quiet "$clone_url" "$PROFILE_REPO_PATH" 2>/dev/null; then log ".profile repo cloned: ${PROFILE_REPO_PATH}"