2026-04-06 18:06:28 +00:00
<!-- last - reviewed: f10cdf2c9e44c32308c7ea74fcc3139407703e59 -->
2026-03-21 12:44:23 +00:00
# Dev Agent
**Role**: Implement issues autonomously — write code, push branches, address
CI failures and review feedback.
2026-03-25 00:07:52 +00:00
**Trigger**: `dev-poll.sh` runs every 10 min via cron. Sources `lib/guard.sh` and
calls `check_active dev` first — skips if `$FACTORY_ROOT/state/.dev-active` is
absent. Then performs a direct-merge scan (approved + CI green PRs — including
chore/gardener PRs without issue numbers), then checks the agent lock and scans
for ready issues using a two-tier priority queue: (1) `priority` +`backlog` issues
first (FIFO within tier), then (2) plain `backlog` issues (FIFO). Orphaned
in-progress issues are also picked up. The direct-merge scan runs before the lock
check so approved PRs get merged even while a dev-agent session is active.
2026-03-21 12:44:23 +00:00
**Key files**:
fix: chore: remove dead tmux-based session code (agent-session.sh, phase-handler.sh) (#262)
- Delete lib/agent-session.sh (entirely dead file with no active callers)
- Delete dev/phase-handler.sh (entirely dead file with no active callers)
- Update lib/formula-session.sh to remove tmux-based functions:
- Removed: start_formula_session, run_formula_and_monitor, formula_phase_callback,
write_compact_context, remove_formula_worktree, cleanup_stale_crashed_worktrees
- Kept utility functions: acquire_cron_lock, check_memory, load_formula,
profile_write_journal, formula_prepare_profile_context, build_graph_section, etc.
- Update dev/phase-test.sh to inline read_phase() function (no longer sources agent-session.sh)
- Update documentation: AGENTS.md, lib/AGENTS.md, dev/AGENTS.md, .woodpecker/agent-smoke.sh,
docs/PHASE-PROTOCOL.md, lib/pr-lifecycle.sh
- All 38 phase tests pass
2026-04-05 22:25:53 +00:00
- `dev/dev-poll.sh` — Cron scheduler: finds next ready issue, handles merge/rebase of approved PRs, tracks CI fix attempts. Formula guard skips issues labeled `formula` , `prediction/dismissed` , or `prediction/unreviewed` . **Race prevention** : checks issue assignee before claiming — skips if assigned to a different bot user. **Stale branch abandonment** : closes PRs and deletes branches that are behind `$PRIMARY_BRANCH` (restarts poll cycle for a fresh start). **Stale in-progress recovery** : on each poll cycle, scans for issues labeled `in-progress` with no open PR — removes `in-progress` , adds `blocked` with a human-triage comment (requires maintainer review before re-queuing).
2026-03-21 12:44:23 +00:00
- `dev/dev-agent.sh` — Orchestrator: claims issue, creates worktree + tmux session with interactive `claude` , monitors phase file, injects CI results and review feedback, merges on approval
- `dev/phase-test.sh` — Integration test for the phase protocol
**Environment variables consumed** (via `lib/env.sh` + project TOML):
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
- `FORGE_TOKEN` — Dev-agent token (push, PR creation, merge) — use the dedicated bot account
2026-03-25 12:07:39 +00:00
- `FORGE_REPO` , `FORGE_API` , `FORGE_URL` — Target repository (FORGE_URL used to auto-detect git remote)
2026-03-21 12:44:23 +00:00
- `PROJECT_NAME` , `PROJECT_REPO_ROOT` — Local checkout path
- `PRIMARY_BRANCH` — Branch to merge into (e.g. `main` , `master` )
- `WOODPECKER_REPO_ID` — CI pipeline lookups
- `CLAUDE_TIMEOUT` — Max seconds for a Claude session (default 7200)
2026-03-25 12:07:39 +00:00
**FORGE_REMOTE**: `dev-agent.sh` auto-detects which git remote corresponds to `FORGE_URL` by matching the remote's push URL hostname. This is exported as `FORGE_REMOTE` and used for all git push/pull/worktree operations. Defaults to `origin` if no match found. This ensures correct behaviour when the forge is local Forgejo (remote typically named `forgejo` ) rather than Codeberg (`origin` ).
2026-03-26 18:14:35 +00:00
**Session lock**: fd-based flock — released during idle phases (`awaiting_review` , `awaiting_ci` ) so other agents can proceed; re-acquired before injecting the next prompt. This prevents the lock from blocking the whole factory while the dev session waits.
**Crash recovery**: on `PHASE:crashed` or non-zero exit, the worktree is **preserved** (not destroyed) for debugging. Location logged. Supervisor housekeeping removes stale crashed worktrees older than 24h.
fix: chore: remove dead tmux-based session code (agent-session.sh, phase-handler.sh) (#262)
- Delete lib/agent-session.sh (entirely dead file with no active callers)
- Delete dev/phase-handler.sh (entirely dead file with no active callers)
- Update lib/formula-session.sh to remove tmux-based functions:
- Removed: start_formula_session, run_formula_and_monitor, formula_phase_callback,
write_compact_context, remove_formula_worktree, cleanup_stale_crashed_worktrees
- Kept utility functions: acquire_cron_lock, check_memory, load_formula,
profile_write_journal, formula_prepare_profile_context, build_graph_section, etc.
- Update dev/phase-test.sh to inline read_phase() function (no longer sources agent-session.sh)
- Update documentation: AGENTS.md, lib/AGENTS.md, dev/AGENTS.md, .woodpecker/agent-smoke.sh,
docs/PHASE-PROTOCOL.md, lib/pr-lifecycle.sh
- All 38 phase tests pass
2026-04-05 22:25:53 +00:00
**Lifecycle**: dev-poll.sh (`check_active dev` ) → dev-agent.sh → tmux session → phase file
2026-03-25 00:07:52 +00:00
drives CI/review loop → merge + `mirror_push()` → close issue. On respawn after
`PHASE:escalate` , the stale phase file is cleared first so the session starts
clean; the reinject prompt tells Claude not to re-escalate for the same reason.
On respawn for any active PR, the prompt explicitly tells Claude the PR already
exists and not to create a new one via API.