← Back to task

Commit c8489bf7

commit c8489bf728035cf1abeed1faebeed8f2584dc748
Author: Ben Sima <ben@bensima.com>
Date:   Tue Dec 30 23:46:44 2025

    Omni/Ide: Add ava-env.sh environment wrapper
    
    Consolidates scattered environment setup into a single script:
    - PATH setup for /usr/local/bin
    - API key sourcing from /run/secrets/ava.env
    - direnv environment loading
    - CODEROOT setup
    - Git user.name/email for automated commits
    
    pi-orchestrate.sh, pi-code.sh, pi-review.sh now source this.
    
    Task-Id: t-298.1

diff --git a/Omni/Ide/ava-env.sh b/Omni/Ide/ava-env.sh
new file mode 100755
index 00000000..8f6cd835
--- /dev/null
+++ b/Omni/Ide/ava-env.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+# ava-env.sh - Environment setup for Ava (automated agent)
+#
+# This script should be sourced (not executed) at the start of
+# pi-orchestrate.sh, pi-code.sh, and pi-review.sh.
+#
+# Sets up:
+# - PATH (for node/pi at /usr/local/bin)
+# - API keys from /run/secrets/ava.env
+# - direnv/nix-shell environment (for bild, lint, etc.)
+# - CODEROOT (repository root)
+# - Git user.name/email for commits
+#
+# Usage:
+#   source "$(dirname "${BASH_SOURCE[0]}")/ava-env.sh"
+
+# Ensure /usr/local/bin is in PATH for node/pi
+export PATH="/usr/local/bin:$PATH"
+
+# Source API keys if available (for Ava service user)
+if [[ -f /run/secrets/ava.env && -r /run/secrets/ava.env ]]; then
+    set -a
+    # shellcheck source=/dev/null
+    source /run/secrets/ava.env
+    set +a
+fi
+
+# Load direnv/nix-shell environment for bild, lint, etc.
+if command -v direnv &> /dev/null; then
+    eval "$(direnv export bash 2>/dev/null || true)"
+fi
+
+# Set CODEROOT if not already set by direnv
+# This is the repository root, needed by many tools
+if [[ -z "$CODEROOT" ]]; then
+    # Try to find repo root from script location
+    _AVA_ENV_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+    CODEROOT="$(cd "$_AVA_ENV_DIR/../.." && pwd)"
+    export CODEROOT
+    unset _AVA_ENV_DIR
+fi
+
+# Configure git identity for automated commits
+# Only set if not already configured (allows override)
+if [[ -z "$(git config user.name 2>/dev/null)" ]]; then
+    git config user.name "Ava"
+fi
+if [[ -z "$(git config user.email 2>/dev/null)" ]]; then
+    git config user.email "ava@bsima.me"
+fi
diff --git a/Omni/Ide/pi-code.sh b/Omni/Ide/pi-code.sh
index 67a0c628..42dad589 100755
--- a/Omni/Ide/pi-code.sh
+++ b/Omni/Ide/pi-code.sh
@@ -10,20 +10,9 @@
 
 set -e
 
-# Ensure /usr/local/bin is in PATH for node/pi
-export PATH="/usr/local/bin:$PATH"
-
-# Source API keys if available (for Ava service user)
-if [[ -f /run/secrets/ava.env && -r /run/secrets/ava.env ]]; then
-    set -a
-    source /run/secrets/ava.env
-    set +a
-fi
-
-# Load direnv/nix-shell environment for bild, lint, etc.
-if command -v direnv &> /dev/null; then
-    eval "$(direnv export bash 2>/dev/null || true)"
-fi
+# Load Ava environment (PATH, API keys, direnv, CODEROOT, git config)
+# shellcheck source=./ava-env.sh
+source "$(dirname "${BASH_SOURCE[0]}")/ava-env.sh"
 
 VERSION="0.2.0"
 LAST_UPDATED="2025-12-30"
diff --git a/Omni/Ide/pi-orchestrate.sh b/Omni/Ide/pi-orchestrate.sh
index b4569eed..604b2e7c 100755
--- a/Omni/Ide/pi-orchestrate.sh
+++ b/Omni/Ide/pi-orchestrate.sh
@@ -9,20 +9,9 @@
 
 set -e
 
-# Ensure /usr/local/bin is in PATH for node/pi
-export PATH="/usr/local/bin:$PATH"
-
-# Source API keys if available (for Ava service user)
-if [[ -f /run/secrets/ava.env && -r /run/secrets/ava.env ]]; then
-    set -a
-    source /run/secrets/ava.env
-    set +a
-fi
-
-# Load direnv/nix-shell environment for bild, lint, etc.
-if command -v direnv &> /dev/null; then
-    eval "$(direnv export bash 2>/dev/null || true)"
-fi
+# Load Ava environment (PATH, API keys, direnv, CODEROOT, git config)
+# shellcheck source=./ava-env.sh
+source "$(dirname "${BASH_SOURCE[0]}")/ava-env.sh"
 
 # Logging
 LOG_DIR="${HOME}/logs/orchestrator"
diff --git a/Omni/Ide/pi-review.sh b/Omni/Ide/pi-review.sh
index fa09bb04..a44affcb 100755
--- a/Omni/Ide/pi-review.sh
+++ b/Omni/Ide/pi-review.sh
@@ -9,20 +9,9 @@
 
 set -e
 
-# Ensure /usr/local/bin is in PATH for node/pi
-export PATH="/usr/local/bin:$PATH"
-
-# Source API keys if available (for Ava service user)
-if [[ -f /run/secrets/ava.env && -r /run/secrets/ava.env ]]; then
-    set -a
-    source /run/secrets/ava.env
-    set +a
-fi
-
-# Load direnv/nix-shell environment for bild, lint, etc.
-if command -v direnv &> /dev/null; then
-    eval "$(direnv export bash 2>/dev/null || true)"
-fi
+# Load Ava environment (PATH, API keys, direnv, CODEROOT, git config)
+# shellcheck source=./ava-env.sh
+source "$(dirname "${BASH_SOURCE[0]}")/ava-env.sh"
 
 VERSION="0.1.0"
 LAST_UPDATED="2025-12-30"