feat(submodule): atualizar submodulo .agent na branch master ao iniciar sessao
This commit is contained in:
parent
b1c4c5c42e
commit
29e5bc979e
14 changed files with 306 additions and 13 deletions
77
scripts/atualizar-submodulo.sh
Executable file
77
scripts/atualizar-submodulo.sh
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Script de Ciclo de Vida: Atualização do Submódulo .agent ao Iniciar Sessão
|
||||
# Executa: git submodule update --init --recursive --remote na branch master
|
||||
# Compatível com CLI e Lifecycle Hook do Antigravity (PreInvocation).
|
||||
# ==============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
INPUT_JSON=""
|
||||
IS_PIPE=0
|
||||
if [ ! -t 0 ]; then
|
||||
IS_PIPE=1
|
||||
INPUT_JSON=$(cat 2>/dev/null || true)
|
||||
fi
|
||||
|
||||
# Extrair conversationId se chamado via Hook Antigravity
|
||||
CONV_ID=""
|
||||
if [ -n "$INPUT_JSON" ]; then
|
||||
CONV_ID=$(echo "$INPUT_JSON" | grep -o '"conversationId":[[:space:]]*"[^"]*' | sed 's/.*"//' || true)
|
||||
fi
|
||||
|
||||
# Idempotência: executar apenas uma vez por sessão de conversa
|
||||
if [ -n "$CONV_ID" ]; then
|
||||
LOCK_FILE="/tmp/.antigravity_agent_updated_${CONV_ID}"
|
||||
if [ -f "$LOCK_FILE" ]; then
|
||||
echo "{}"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Detectar diretório raiz do superprojeto
|
||||
SUPER_DIR=$(git rev-parse --show-superproject-working-tree 2>/dev/null || true)
|
||||
if [ -z "$SUPER_DIR" ]; then
|
||||
if [ -f ".gitmodules" ]; then
|
||||
SUPER_DIR="."
|
||||
elif [ -f "../.gitmodules" ]; then
|
||||
SUPER_DIR=".."
|
||||
elif [ -f "../../.gitmodules" ]; then
|
||||
SUPER_DIR="../.."
|
||||
else
|
||||
SUPER_DIR="."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f "$SUPER_DIR/.gitmodules" ]; then
|
||||
# Garantir configuração branch = master no .gitmodules
|
||||
CURRENT_BRANCH=$(git -C "$SUPER_DIR" config -f .gitmodules submodule..agent.branch 2>/dev/null || true)
|
||||
if [ "$CURRENT_BRANCH" != "master" ]; then
|
||||
git -C "$SUPER_DIR" config -f .gitmodules submodule..agent.branch master 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Executar a atualização remota do submódulo .agent
|
||||
if git -C "$SUPER_DIR" submodule update --init --recursive --remote .agent >/dev/null 2>&1; then
|
||||
[ -n "$CONV_ID" ] && touch "$LOCK_FILE" 2>/dev/null || true
|
||||
if [ "$IS_PIPE" -eq 1 ] && [ -n "$INPUT_JSON" ]; then
|
||||
echo '{"injectSteps":[{"ephemeralMessage":"ℹ️ Submódulo .agent sincronizado com sucesso na branch master (git submodule update --init --recursive --remote)."}]}'
|
||||
else
|
||||
echo "✅ Submódulo .agent sincronizado com sucesso na branch master."
|
||||
fi
|
||||
exit 0
|
||||
else
|
||||
if [ "$IS_PIPE" -eq 1 ] && [ -n "$INPUT_JSON" ]; then
|
||||
echo '{"injectSteps":[{"ephemeralMessage":"⚠️ Não foi possível sincronizar o submódulo .agent com origin/master (sem conexão ou erro de rede). Continuando com versão local."}]}'
|
||||
else
|
||||
echo "⚠️ Não foi possível sincronizar o submódulo .agent com origin/master. Continuando com versão local."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$IS_PIPE" -eq 1 ]; then
|
||||
echo "{}"
|
||||
else
|
||||
echo "ℹ️ Nenhum arquivo .gitmodules detectado."
|
||||
fi
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue