2026-04-15 10:07:41 +00:00
<!-- last - reviewed: be463c5b439aec1ef0d4acfafc47e94896f5dc57 -->
2026-03-21 12:44:23 +00:00
# Gardener Agent
**Role**: Backlog grooming — detect duplicate issues, missing acceptance
2026-03-21 18:07:37 +00:00
criteria, oversized issues, stale issues, and circular dependencies. Enforces
the quality gate: strips the `backlog` label from issues that lack acceptance
criteria checkboxes (`- [ ]` ) or an `## Affected files` section. Invokes
2026-03-26 10:32:04 +00:00
Claude to fix what it can; files vault items for what it cannot.
2026-03-21 12:44:23 +00:00
2026-04-10 08:35:19 +00:00
**Trigger**: `gardener-run.sh` is invoked by the polling loop in `docker/agents/entrypoint.sh`
every 6 hours (iteration math at line 182-194). Sources `lib/guard.sh` and calls
`check_active gardener` first — skips if `$FACTORY_ROOT/state/.gardener-active` is absent.
**Early-exit optimization**: if no issues, PRs, or repo files have changed since the last
run (checked via Forgejo API and `git diff` ), the model is not invoked — the run exits
immediately (no tmux session, no tokens consumed). Otherwise, creates a tmux session with
`claude --model sonnet` , injects `formulas/run-gardener.toml` as context, monitors the
phase file, and cleans up on completion or timeout (2h max session). No action issues —
the gardener runs as part of the polling loop alongside the planner, predictor, and supervisor.
2026-03-21 12:44:23 +00:00
**Key files**:
2026-04-10 08:35:19 +00:00
- `gardener/gardener-run.sh` — Polling loop participant + orchestrator: lock, memory guard,
2026-03-26 10:32:04 +00:00
sources disinto project config, creates tmux session, injects formula prompt,
monitors phase file via custom `_gardener_on_phase_change` callback (passed to
`run_formula_and_monitor` ). Stays alive through CI/review/merge cycle after
`PHASE:awaiting_ci` — injects CI results and review feedback, re-signals
`PHASE:awaiting_ci` after fixes, signals `PHASE:awaiting_review` on CI pass.
Executes pending-actions manifest after PR merge.
2026-04-01 19:36:04 +00:00
- `formulas/run-gardener.toml` — Execution spec: preflight, grooming, dust-bundling,
agents-update, commit-and-pr
2026-03-22 23:58:50 +00:00
- `gardener/pending-actions.json` — Manifest of deferred repo actions (label changes,
closures, comments, issue creation). Written during grooming steps, committed to the
PR, reviewed alongside AGENTS.md changes, executed by gardener-run.sh after merge.
2026-03-21 12:44:23 +00:00
**Environment variables consumed**:
2026-04-15 08:06:14 +00:00
- `FORGE_TOKEN` , `FORGE_GARDENER_TOKEN` (falls back to FORGE_TOKEN), `FORGE_REPO` , `FORGE_API` , `PROJECT_NAME` , `PROJECT_REPO_ROOT` . `FORGE_TOKEN_OVERRIDE` is exported to `$FORGE_GARDENER_TOKEN` before sourcing env.sh so the gardener-bot identity survives re-sourcing (#762 ).
fix: gardener migration — run-gardener.toml via direct cron, remove legacy scripts (#490)
Rewrite gardener-run.sh as direct cron runner (matching supervisor/planner/
predictor pattern): lock guard, memory check, worktree, tmux session with
Claude sonnet + formulas/run-gardener.toml, phase monitoring, cleanup.
- Delete gardener-poll.sh and gardener-agent.sh (superseded)
- Extract consume_escalation_reply() to lib/formula-session.sh (shared
by gardener and supervisor, eliminates duplicate blocks)
- Update AGENTS.md, gardener/AGENTS.md, lib/AGENTS.md, CI smoke test,
and cross-references
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 13:09:17 +00:00
- `PRIMARY_BRANCH` , `CLAUDE_MODEL` (set to sonnet by gardener-run.sh)
2026-04-10 08:35:19 +00:00
**Lifecycle**: gardener-run.sh (invoked by polling loop every 6h, `check_active gardener` ) →
lock + memory guard → load formula + context → create tmux session →
2026-03-22 23:58:50 +00:00
Claude grooms backlog (writes proposed actions to manifest), bundles dust,
2026-04-01 19:36:04 +00:00
updates AGENTS.md, commits manifest + docs to PR →
2026-03-23 00:11:06 +00:00
`PHASE:awaiting_ci` (stays alive) → CI pass → `PHASE:awaiting_review` →
review feedback → address + re-signal → merge → gardener-run.sh executes
2026-03-26 10:32:04 +00:00
manifest actions via API → `PHASE:done` . When blocked on external resources
or human decisions, files a vault item instead of escalating.