From 00986956443d3b5bc0950e54f19c72680b351c05 Mon Sep 17 00:00:00 2001 From: Agent Date: Mon, 6 Apr 2026 09:26:18 +0000 Subject: [PATCH] fix: fix: cron agents (gardener, planner, architect, predictor) never set FORGE_REMOTE (#278) --- architect/architect-run.sh | 3 +++ gardener/gardener-run.sh | 11 +++++++---- lib/formula-session.sh | 25 ++++++++++++++++++++++--- planner/planner-run.sh | 3 +++ predictor/predictor-run.sh | 3 +++ supervisor/supervisor-run.sh | 3 +++ 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/architect/architect-run.sh b/architect/architect-run.sh index d2ecc3b..6052d0b 100755 --- a/architect/architect-run.sh +++ b/architect/architect-run.sh @@ -53,6 +53,9 @@ check_memory 2000 log "--- Architect run start ---" +# ── Resolve forge remote for git operations ───────────────────────────── +resolve_forge_remote + # ── Resolve agent identity for .profile repo ──────────────────────────── if [ -z "${AGENT_IDENTITY:-}" ] && [ -n "${FORGE_ARCHITECT_TOKEN:-}" ]; then AGENT_IDENTITY=$(curl -sf -H "Authorization: token ${FORGE_ARCHITECT_TOKEN}" \ diff --git a/gardener/gardener-run.sh b/gardener/gardener-run.sh index dba1875..abaf0a0 100755 --- a/gardener/gardener-run.sh +++ b/gardener/gardener-run.sh @@ -64,6 +64,9 @@ check_memory 2000 log "--- Gardener run start ---" +# ── Resolve forge remote for git operations ───────────────────────────── +resolve_forge_remote + # ── Resolve agent identity for .profile repo ──────────────────────────── if [ -z "${AGENT_IDENTITY:-}" ] && [ -n "${FORGE_GARDENER_TOKEN:-}" ]; then AGENT_IDENTITY=$(curl -sf -H "Authorization: token ${FORGE_GARDENER_TOKEN}" \ @@ -128,9 +131,9 @@ ${PROMPT_FOOTER}" # ── Create worktree ────────────────────────────────────────────────────── cd "$PROJECT_REPO_ROOT" -git fetch origin "$PRIMARY_BRANCH" 2>/dev/null || true +git fetch "${FORGE_REMOTE}" "$PRIMARY_BRANCH" 2>/dev/null || true worktree_cleanup "$WORKTREE" -git worktree add "$WORKTREE" "origin/${PRIMARY_BRANCH}" --detach 2>/dev/null +git worktree add "$WORKTREE" "${FORGE_REMOTE}/${PRIMARY_BRANCH}" --detach 2>/dev/null cleanup() { worktree_cleanup "$WORKTREE" @@ -328,9 +331,9 @@ if [ -n "$PR_NUMBER" ]; then if [ "$_PR_WALK_EXIT_REASON" = "merged" ]; then # Post-merge: pull primary, mirror push, execute manifest - git -C "$PROJECT_REPO_ROOT" fetch origin "$PRIMARY_BRANCH" 2>/dev/null || true + git -C "$PROJECT_REPO_ROOT" fetch "${FORGE_REMOTE}" "$PRIMARY_BRANCH" 2>/dev/null || true git -C "$PROJECT_REPO_ROOT" checkout "$PRIMARY_BRANCH" 2>/dev/null || true - git -C "$PROJECT_REPO_ROOT" pull --ff-only origin "$PRIMARY_BRANCH" 2>/dev/null || true + git -C "$PROJECT_REPO_ROOT" pull --ff-only "${FORGE_REMOTE}" "$PRIMARY_BRANCH" 2>/dev/null || true mirror_push _gardener_execute_manifest rm -f "$SCRATCH_FILE" diff --git a/lib/formula-session.sh b/lib/formula-session.sh index 8c228b0..264c8e1 100644 --- a/lib/formula-session.sh +++ b/lib/formula-session.sh @@ -91,6 +91,24 @@ resolve_agent_identity() { return 0 } +# ── Forge remote resolution ────────────────────────────────────────────── + +# resolve_forge_remote +# Resolves FORGE_REMOTE by matching FORGE_URL hostname against git remotes. +# Falls back to "origin" if no match found. +# Requires: FORGE_URL, git repo with remotes configured. +# Exports: FORGE_REMOTE (always set). +resolve_forge_remote() { + # Extract hostname from FORGE_URL (e.g., https://codeberg.org/user/repo -> codeberg.org) + _forge_host=$(printf '%s' "$FORGE_URL" | sed 's|https\?://||; s|/.*||; s|:.*||') + # Find git remote whose push URL matches the forge host + FORGE_REMOTE=$(git remote -v | awk -v host="$_forge_host" '$2 ~ host && /\(push\)/ {print $1; exit}') + # Fallback to origin if no match found + FORGE_REMOTE="${FORGE_REMOTE:-origin}" + export FORGE_REMOTE + log "forge remote: ${FORGE_REMOTE}" +} + # ── .profile repo management ────────────────────────────────────────────── # ensure_profile_repo [AGENT_IDENTITY] @@ -711,13 +729,14 @@ build_sdk_prompt_footer() { # Creates an isolated worktree for synchronous formula execution. # Fetches primary branch, cleans stale worktree, creates new one, and # sets an EXIT trap for cleanup. -# Requires globals: PROJECT_REPO_ROOT, PRIMARY_BRANCH. +# Requires globals: PROJECT_REPO_ROOT, PRIMARY_BRANCH, FORGE_REMOTE. +# Ensure resolve_forge_remote() is called before this function. formula_worktree_setup() { local worktree="$1" cd "$PROJECT_REPO_ROOT" || return - git fetch origin "$PRIMARY_BRANCH" 2>/dev/null || true + git fetch "${FORGE_REMOTE}" "$PRIMARY_BRANCH" 2>/dev/null || true worktree_cleanup "$worktree" - git worktree add "$worktree" "origin/${PRIMARY_BRANCH}" --detach 2>/dev/null + git worktree add "$worktree" "${FORGE_REMOTE}/${PRIMARY_BRANCH}" --detach 2>/dev/null # shellcheck disable=SC2064 # expand worktree now, not at trap time trap "worktree_cleanup '$worktree'" EXIT } diff --git a/planner/planner-run.sh b/planner/planner-run.sh index 663703c..4cc3800 100755 --- a/planner/planner-run.sh +++ b/planner/planner-run.sh @@ -52,6 +52,9 @@ check_memory 2000 log "--- Planner run start ---" +# ── Resolve forge remote for git operations ───────────────────────────── +resolve_forge_remote + # ── Resolve agent identity for .profile repo ──────────────────────────── if [ -z "${AGENT_IDENTITY:-}" ] && [ -n "${FORGE_PLANNER_TOKEN:-}" ]; then AGENT_IDENTITY=$(curl -sf -H "Authorization: token ${FORGE_PLANNER_TOKEN}" \ diff --git a/predictor/predictor-run.sh b/predictor/predictor-run.sh index 266829c..0fdc8fa 100755 --- a/predictor/predictor-run.sh +++ b/predictor/predictor-run.sh @@ -53,6 +53,9 @@ check_memory 2000 log "--- Predictor run start ---" +# ── Resolve forge remote for git operations ───────────────────────────── +resolve_forge_remote + # ── Resolve agent identity for .profile repo ──────────────────────────── if [ -z "${AGENT_IDENTITY:-}" ] && [ -n "${FORGE_PREDICTOR_TOKEN:-}" ]; then AGENT_IDENTITY=$(curl -sf -H "Authorization: token ${FORGE_PREDICTOR_TOKEN}" \ diff --git a/supervisor/supervisor-run.sh b/supervisor/supervisor-run.sh index 4ba6ec3..57a3f95 100755 --- a/supervisor/supervisor-run.sh +++ b/supervisor/supervisor-run.sh @@ -55,6 +55,9 @@ check_memory 2000 log "--- Supervisor run start ---" +# ── Resolve forge remote for git operations ───────────────────────────── +resolve_forge_remote + # ── Housekeeping: clean up stale crashed worktrees (>24h) ──────────────── cleanup_stale_crashed_worktrees 24