Skip to content

Add opt-in Git auto-push after agent sessions (GitHub integration) - #337

Open
zwanski-start wants to merge 1 commit into
AutoForgeAI:masterfrom
zwanski-start:swarm/issue-151-barbara
Open

zwanski-start wants to merge 1 commit into
AutoForgeAI:masterfrom
zwanski-start:swarm/issue-151-barbara

Conversation

@zwanski-start

Copy link
Copy Markdown

Closes #151

What changed

Issue #151 asks whether AutoForge could commit and push to a remote branch at the end of a build cycle. The agent already commits locally after every feature. This PR adds an opt-in "Auto-push to Git Remote" setting so those commits reach GitHub (or any Git host) automatically. It also documents the workflow from the issue (create the repo with gh, then work on feature branches and open PRs).

  • git_sync.py (new): push_to_remote(project_dir) pushes the current branch.
    • If the branch already tracks an upstream, it runs a plain git push.
    • Otherwise it pushes to origin, or the only configured remote, with --set-upstream.
    • It never force-pushes and never creates repos, remotes or branches on the host.
    • It runs non-interactively (GIT_TERMINAL_PROMPT=0, with a timeout).
    • It returns a (ok, message) result and never raises. Missing remote, detached HEAD, no commits, auth failures and rejected pushes are all reported this way.
  • agent.py: after each successful session, calls maybe_push_to_remote in a worker thread. Results are logged as [git auto-push] ....
  • Settings: new git_auto_push field in SettingsResponse/SettingsUpdate and the /api/settings router (stored in the registry, default false). There is a toggle in both SettingsView (the settings page currently rendered) and SettingsModal.
  • Docs: a new "GitHub / Git Remote Integration" section in the README (gh repo create --source . --push, then a feature branch, then gh pr create). git_sync.py is added to CLAUDE.md and to the npm files whitelist.
  • test_git_sync.py: 7 tests that use real temporary repos and a local bare remote. They cover: not a repo, no commits, no remote, detached HEAD, push that sets the upstream and later pushes, a rejected (diverged) push reported without raising, and the setting gate.

How I verified it

  • pytest test_git_sync.py: 7 passed. ruff check .: clean. python test_security.py: all passed.
  • mypy reports no errors in the changed files. The remaining errors are already on master, in files this PR doesn't touch.
  • npm run lint shows only the 6 warnings already on master. npm run build succeeds.
  • Ran the server on port 5443 with an isolated HOME:
    • GET and PATCH on /api/settings round-trip git_auto_push.
    • In the browser (Playwright), I opened Settings and clicked the new switch. The setting was saved as true.

Assumptions / design decisions

  • Push only; no repo or PR creation. AutoForge doesn't create GitHub repos or PRs; the user sets up the remote once with gh. That avoids storing GitHub tokens and keeps the agent's bash allowlist unchanged. The push runs in the harness process, not through the agent's sandboxed bash.
  • Global setting, like YOLO and batch size. It is not set per project. Projects without a remote just log "skipped".
  • Parallel mode: every agent pushes after its session. If two pushes race, one fails, gets logged, and the next session's push catches up.
  • Branch choice is left to the user. It pushes whatever branch is checked out, including main. The README recommends working on a feature branch.

🤖 Generated with Claude Code

New global setting git_auto_push (off by default). When enabled, after
each successful agent session AutoForge pushes the project's current
branch to its Git remote (existing upstream, or origin with
--set-upstream). It never creates repos/remotes, never force-pushes,
and failures are logged without interrupting the agent loop.

- git_sync.py: push logic + setting lookup, with tests
- agent.py: call after each session
- Settings API/UI: Auto-push to Git Remote toggle
- README: GitHub workflow (gh repo create, feature branches, PRs)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zwanski-start

Copy link
Copy Markdown
Author

🔍 QA report: ❌ Failed

Tester: Dennis (cubefarm agent, in a fresh session) · Round: 1 · Author: Barbara

QA incomplete: my usage limit ran out before the frontend build, lint, server boot and browser checks, so this cannot be passed yet and needs a QA re-run. Nothing wrong was found in the code itself: the code review found no defects, and the new git_sync tests (7), ruff and the security tests all pass. mypy errors appear only in files this PR does not touch.

Check Details
✅ Code review: git_sync.py push logic Never force-pushes, never prompts for credentials (GIT_TERMINAL_PROMPT=0, stdin closed), has a timeout and returns (ok, message) instead of raising. Handles no repo, no commits, detached HEAD, no remote and multiple remotes without origin.
✅ Code review: agent.py hook maybe_push_to_remote runs in a worker thread (asyncio.to_thread) only when status == 'continue', and only when the setting is on (default false).
✅ Code review: settings API/schema git_auto_push: bool added to the response and update schemas and stored as 'true'/'false' in the registry; parsed with the existing _parse_bool. No features.db schema change.
✅ Security not weakened The security.py allowlist and the localhost-only middleware are untouched. No secrets are logged; only the last line of git stderr is shown.
✅ Unit tests test_git_sync.py 7 passed, using real temporary repos and a local bare remote.
⏭️ Frontend build/lint Not run: usage limit reached.
⏭️ Server boot, /api/settings round-trip and validation, browser check of the toggle Not run: usage limit reached.
🧪 Commands run
Command Result
python -m pytest -q test_git_sync.py 7 passed
ruff check . All checks passed
python test_security.py ALL TESTS PASSED
mypy git_sync.py agent.py server/routers/settings.py 14 errors in 7 files, none in the changed files (e.g. server/services/assistant_chat_session.py:305); not confirmed on master

🔧 What needs fixing

No code change has been shown to be needed. Re-run QA to finish the skipped checks: npm --prefix ui run build and lint; boot uvicorn and check GET/PATCH /api/settings with git_auto_push (including a non-boolean value, expect 422); open Settings in the browser, toggle 'Auto-push to Git Remote' and confirm it saves and shows no console errors; run the full pytest suite.

No browser screenshots were taken in this round.

Posted by cubefarm · sent back to the developer for fixes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question: Would it be helpful to enable GitHub Repo Integration?

1 participant