teqo/scripts/agent-claim.mjs
Francisco Solla c90f70aab4 ops(OPS76): tracker de Issues migra do Forgejo para o GitHub — GitHub como host único
Decisão (2026-08-21): o GitHub passa a ser a fonte única — main, branches,
PRs, CI via Actions E tracker de Issues. O Forgejo deixa de ser canal ativo
(git.e issue tracker congelados pós-convergência).

Data: 17 issues migradas do Forgejo para o GitHub (frontmatter id/depends/
serializes/priority/model preservados, labels mapeados, comment de origem
em cada uma; tabela Forgejo→GitHub registrada).

Tooling: github-api.mjs estendido com a camada de issues/labels/comments/
close/workflow-dispatch/contents (mesmo shape normalizado do forgejo-api);
18 scripts trocam o transporte forgejo-api → github-api; forgejo-api.mjs e
seu teste (961 linhas) removidos; teste githubApi.unit.spec.ts novo (7 casos);
issue-transition-on-merge.mjs renomeado e reapontado.

Flips pós-merge: issue-done e plan-issue-ready agora usam o GITHUB_TOKEN com
issues:write no repo (sem FORGEJO_API_TOKEN) e fecham/flipam Issues no GitHub.

Docs: AGENTS.md, AGENT-OPS.md e skills do fluxo vivo (work-issue, plan-issue,
project-status, capture-review-debts, worktree-next-issue, agent-work-issue)
apontam o tracker para github.com/fsolla/teqo/issues.

Gates: tsc/lint/format/knip/cycles/unit 2416 verdes.
2026-08-21 08:19:06 -03:00

65 lines
2.5 KiB
JavaScript

/**
* `pnpm agent:claim` — claim the next trackable issue for this agent run.
*
* Queue: open issues labeled `ready`, filtered to UNBLOCKED (every frontmatter
* `depends` id is closed or labeled `done`/`in-prod`), ordered by `prio:P0..P3`
* then oldest first. `--dry-run` prints the queue without claiming.
*
* Lock otimista: re-reads the issue right before flipping labels, refuses if
* someone else already took it (`in-progress` present / `ready` gone), then
* swaps ready→in-progress and leaves a claim comment with the run timestamp.
*
* Output: the brief on stdout (issue, id, priority, plan/spec body) — the
* agent reads it and starts; it does NOT create the branch (Cursor worktrees
* own that) and it never merges anywhere. PRs go `--base main`.
*/
import {
buildClaimQueue,
claimBriefLines,
claimIssue,
dieAgent,
issuesById,
parseArgs,
} from './lib/agent-forgejo.mjs'
import { githubApi as api } from './lib/github-api.mjs'
const die = dieAgent('claim')
const { flags } = parseArgs(process.argv.slice(2), new Set(['issue']))
const openReady = await api.listIssues({ state: 'open', labels: 'ready', limit: 200 })
// Queue builder lives in agent-forgejo.mjs (shared with the agent pool —
// identical ordering/filtering, pinned by agentPoolEligibility.unit.spec.ts).
const queue = buildClaimQueue(openReady, await issuesById())
if (flags['dry-run'] || flags['dryrun']) {
console.log(`[agent:claim] ${queue.length} unblocked ready issue(s):`)
for (const entry of queue) {
const model = entry.meta.model ? ` model:${entry.meta.model}` : ''
console.log(` #${entry.issue.number} [${entry.priority}]${model} ${entry.issue.title}`)
}
process.exit(0)
}
const pick = flags.issue
? queue.find((entry) => entry.issue.number === Number(flags.issue))
: queue[0]
if (!pick) {
die(
flags.issue
? `Issue #${flags.issue} is not claimable (missing, not ready, or blocked by deps).`
: 'Nothing to claim — no unblocked issues labeled `ready`. Run with --dry-run to inspect.',
)
}
// Optimistic lock: re-read right before flipping (shared with `worktree next`).
await claimIssue(pick, die)
console.log(`\n[agent:claim] Claimed #${pick.issue.number} — ${pick.issue.title}`)
for (const line of claimBriefLines(pick)) console.log(line)
console.log(
'\n[agent:claim] Fluxo: claim feito fora da sessão → abra a sessão de trabalho no worktree (skill `work-issue`, humano; no pool, o prompt do worker aponta `agent-work-issue`) → gates → PR Ready --base main (Closes #' +
`${pick.issue.number}) → auto-merge.`,
)