mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-17 07:13:07 -07:00
182 lines
6.7 KiB
YAML
182 lines
6.7 KiB
YAML
name: '🧠 Gemini CLI Bot: Brain'
|
|
|
|
on:
|
|
schedule:
|
|
- cron: '0 0 * * *' # Every 24 hours
|
|
workflow_dispatch:
|
|
inputs:
|
|
clear_memory:
|
|
description: 'Clear memory (drops learnings from previous runs)'
|
|
type: 'boolean'
|
|
default: false
|
|
enable_prs:
|
|
description: 'Enable PRs (automatically promote changes to PRs)'
|
|
type: 'boolean'
|
|
default: false
|
|
|
|
concurrency:
|
|
group: '${{ github.workflow }}-${{ github.ref }}'
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
reasoning:
|
|
name: 'Brain (Reasoning Layer)'
|
|
runs-on: 'ubuntu-latest'
|
|
if: "github.repository == 'google-gemini/gemini-cli'"
|
|
# The reasoning phase is strictly readonly.
|
|
permissions:
|
|
contents: 'read'
|
|
issues: 'read'
|
|
pull-requests: 'read'
|
|
actions: 'read'
|
|
env:
|
|
GEMINI_CLI_TRUST_WORKSPACE: 'true'
|
|
steps:
|
|
- name: 'Checkout'
|
|
uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: 'Setup Node.js'
|
|
uses: 'actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020' # ratchet:actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
cache: 'npm'
|
|
|
|
- name: 'Install dependencies'
|
|
run: 'npm ci'
|
|
|
|
- name: 'Build Gemini CLI'
|
|
run: 'npm run bundle'
|
|
|
|
- name: 'Download Previous State'
|
|
env:
|
|
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
|
run: |
|
|
if [ "${{ github.event.inputs.clear_memory }}" = "true" ]; then
|
|
echo "Memory clear requested. Skipping previous state download."
|
|
exit 0
|
|
fi
|
|
|
|
# Find the last successful run of this workflow
|
|
LAST_RUN_ID=$(gh run list --workflow "${{ github.workflow }}" --status success --limit 1 --json databaseId --jq '.[0].databaseId')
|
|
|
|
if [ -n "$LAST_RUN_ID" ]; then
|
|
echo "Found previous successful run: $LAST_RUN_ID"
|
|
|
|
# Download brain memory (lessons learned and scripts)
|
|
gh run download "$LAST_RUN_ID" -n lessons-learned -D tools/gemini-cli-bot/ || echo "lessons-learned not found"
|
|
gh run download "$LAST_RUN_ID" -n brain-scripts -D tools/gemini-cli-bot/reflexes/scripts/ || echo "brain-scripts not found"
|
|
else
|
|
echo "No previous successful run found."
|
|
fi
|
|
|
|
- name: 'Collect Current Metrics'
|
|
env:
|
|
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
|
run: 'npx tsx tools/gemini-cli-bot/metrics/index.ts'
|
|
|
|
- name: 'Prepare Metrics'
|
|
run: |
|
|
if [ -f "tools/gemini-cli-bot/history/metrics-before.csv" ]; then
|
|
mv tools/gemini-cli-bot/history/metrics-before.csv tools/gemini-cli-bot/history/metrics-before-prev.csv
|
|
fi
|
|
|
|
- name: 'Run Brain Phases'
|
|
env:
|
|
GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}'
|
|
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
|
GEMINI_MODEL: 'gemini-3-flash-preview'
|
|
ENABLE_PRS: "${{ github.event.inputs.enable_prs || 'false' }}"
|
|
run: 'node bundle/gemini.js --policy tools/gemini-cli-bot/ci-policy.toml tools/gemini-cli-bot/brain/metrics.md'
|
|
|
|
- name: 'Generate Patch'
|
|
if: "${{ github.event.inputs.enable_prs == 'true' }}"
|
|
run: |
|
|
git add .
|
|
git diff --staged > bot-changes.patch
|
|
# Ensure file exists even if empty so upload-artifact doesn't fail if we decide to upload it
|
|
touch bot-changes.patch
|
|
touch pr-description.md
|
|
|
|
- name: 'Stash Brain Outputs'
|
|
uses: 'actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02' # ratchet:actions/upload-artifact@v4
|
|
with:
|
|
name: 'brain-outputs'
|
|
path: |
|
|
tools/gemini-cli-bot/lessons-learned.md
|
|
tools/gemini-cli-bot/reflexes/scripts/
|
|
bot-changes.patch
|
|
pr-description.md
|
|
retention-days: 1
|
|
|
|
publish:
|
|
name: 'Publish Artifacts (Archive Layer)'
|
|
needs: reasoning
|
|
runs-on: 'ubuntu-latest'
|
|
if: "github.repository == 'google-gemini/gemini-cli'"
|
|
# The publish phase is for archiving artifacts and optionally creating PRs.
|
|
permissions:
|
|
contents: 'write'
|
|
pull-requests: 'write'
|
|
actions: 'write'
|
|
steps:
|
|
- name: 'Checkout'
|
|
uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: 'Download Brain Outputs'
|
|
uses: 'actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093' # ratchet:actions/download-artifact@v4
|
|
with:
|
|
name: 'brain-outputs'
|
|
path: 'temp_outputs/'
|
|
|
|
- name: 'Create PR from Patch'
|
|
if: "${{ github.event.inputs.enable_prs == 'true' }}"
|
|
env:
|
|
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
|
run: |
|
|
if [ -s temp_outputs/bot-changes.patch ]; then
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
BRANCH_NAME="bot/productivity-updates-$(date +'%Y%m%d%H%M%S')"
|
|
git checkout -b "$BRANCH_NAME"
|
|
|
|
git apply temp_outputs/bot-changes.patch
|
|
git add .
|
|
|
|
if [ -s temp_outputs/pr-description.md ]; then
|
|
git commit -F temp_outputs/pr-description.md
|
|
else
|
|
git commit -m "🤖 Gemini Bot Productivity Optimizations"
|
|
fi
|
|
|
|
git push origin "$BRANCH_NAME"
|
|
|
|
PR_TITLE="🤖 Gemini Bot Productivity Optimizations"
|
|
if [ -s temp_outputs/pr-description.md ]; then
|
|
PR_TITLE=$(head -n 1 temp_outputs/pr-description.md)
|
|
fi
|
|
|
|
gh pr create --draft --title "$PR_TITLE" --body-file temp_outputs/pr-description.md --head "$BRANCH_NAME" --base main || \
|
|
gh pr create --draft --title "🤖 Gemini Bot Productivity Optimizations" --body "Automated changes generated by Gemini CLI Bot." --head "$BRANCH_NAME" --base main
|
|
else
|
|
echo "No patch found or patch is empty. Skipping PR creation."
|
|
fi
|
|
|
|
- name: 'Archive Lessons Learned'
|
|
uses: 'actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02' # ratchet:actions/upload-artifact@v4
|
|
with:
|
|
name: 'lessons-learned'
|
|
path: 'temp_outputs/lessons-learned.md'
|
|
retention-days: 90
|
|
|
|
- name: 'Archive Brain Scripts'
|
|
uses: 'actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02' # ratchet:actions/upload-artifact@v4
|
|
with:
|
|
name: 'brain-scripts'
|
|
path: 'temp_outputs/reflexes/scripts/'
|
|
retention-days: 90
|