teqo/.github/workflows/agent-pool.yml
Francisco Solla f357fcd780 fix(agent-pool): tick falhava em ERR_MODULE_NOT_FOUND (dotenv) (#72)
Os scripts do pool NAO sao dependency-free: agent-pool.mjs -> agent-github.mjs
-> scripts/lib/cli.mjs -> dotenv. O workflow agora instala deps como os irmaos
(pnpm/action-setup + cache + pnpm install --frozen-lockfile). Guard adicional:
pull_request closed sem merge nao dispara o tick (ruido em todo PR de stage).

Verificado localmente: o script carrega e para na leitura estrita de variables
(fail-closed desenhado; em GHA o GITHUB_TOKEN tem actions:write).

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-07-30 23:41:59 -03:00

80 lines
2.7 KiB
YAML

# Agent pool supervisor (docs/plans/agent-pool-orchestrator.md).
#
# Stateless tick: reconciles pool claims and spawns Cursor Cloud workers up to
# POOL_MAX_SLOTS over `ready` autonomous-eligible issues. Three triggers:
# - workflow_dispatch — the canonical human channel (start/stop/pause/resume)
# - schedule */10min — the periodic reconcile (default branch only)
# - pull_request closed on stage — immediate slot replenish after a merge
# Schedule and PR triggers only run from the default branch: they activate
# after the human promote to main; until then dispatch on the branch works.
#
# Secrets: CURSOR_API_KEY (repo secret) — Cursor Cloud Agents API key.
# GITHUB_TOKEN needs actions: write (pool state lives in repo variables).
name: Agent pool supervisor
on:
schedule:
- cron: '*/10 * * * *'
pull_request:
types: [closed]
branches: [stage]
workflow_dispatch:
inputs:
action:
description: 'Ação do pool'
required: true
type: choice
options:
- start
- stop
- pause
- resume
- tick
- status
maxSlots:
description: 'Slots simultâneos (só com action=start; default 5, máx 8)'
required: false
type: string
# Single-allocator invariant: ticks never overlap.
concurrency:
group: agent-pool
cancel-in-progress: false
permissions:
actions: write
contents: read
issues: write
pull-requests: read
jobs:
tick:
runs-on: ubuntu-latest
timeout-minutes: 10
# pull_request closed WITHOUT merge is not a replenish signal — skip.
if: github.event_name != 'pull_request' || github.event.pull_request.merged == true
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
# The pool scripts import scripts/lib/cli.mjs (dotenv) via agent-github —
# they are NOT dependency-free, so install like every sibling workflow.
- run: pnpm install --frozen-lockfile
- name: agent:pool workflow
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
ACTION: ${{ inputs.action }}
MAX_SLOTS: ${{ inputs.maxSlots }}
run: |
# schedule / pull_request merged → reconcile tick; dispatch → the chosen action.
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
args=(--action "$ACTION" --actor "$GITHUB_ACTOR")
if [ -n "$MAX_SLOTS" ]; then args+=(--max-slots "$MAX_SLOTS"); fi
else
args=(--action tick --actor "$GITHUB_ACTOR")
fi
node scripts/agent-pool.mjs workflow "${args[@]}"