Decisions

  • Pending: Branch naming convention — flat or nested?
  • Pending: Squash commits per agent stage or preserve full history?
  • Pending: Conflict resolution — auto-rebase, manual, or abort?

User Tasks


Summary

Automate the git workflow for coding agents: branch creation per FR, structured commits, PR creation via GitHub API, and merge management — so agents can deliver code changes end-to-end without manual git operations.

Problem / Motivation

Coding agents in the pipeline (FR-056) produce code changes in sandboxed worktrees (FR-055). But getting those changes from a worktree into a mergeable PR requires manual git operations:

  • Creating a branch with the right name
  • Committing with a meaningful message
  • Pushing to the remote
  • Creating a PR with description, labels, and linked FR
  • Handling merge conflicts with main
  • Cleaning up after merge

Without automation, every completed pipeline requires human intervention for git housekeeping. This blocks the “wake up to completed PRs” vision.

Proposed Solution

A src/opus/git/ module with:

  1. Branch Manager: Creates branches per FR with consistent naming, manages branch lifecycle.
  2. Commit Builder: Generates structured commit messages from agent context (FR title, phase, changes).
  3. PR Creator: Creates GitHub PRs via API with description generated from FR spec + changes.
  4. Merge Manager: Detects and resolves conflicts, manages merge after approval.

Open Questions

1. Branch Naming Convention

Question: What branch naming format should agents use?

OptionDescription
A) Flat: opus/FR-058-llm-providerSimple, readable, easy to filter with opus/ prefix
B) Nested: opus/coder/FR-058-llm-providerIncludes agent role. More info but longer names
C) Job-based: opus/job-12345Tied to job ID, not FR. Harder to associate with features

Recommendation: Option A — flat with opus/ prefix is clean and filterable. The FR number already identifies the work.

Decision:

2. Commit Strategy

Question: Should agents squash commits per pipeline stage or preserve full history?

OptionDescription
A) One commit per stagePlanner: 1 commit, Coder: 1 commit, Fix: 1 commit. Clean but loses granularity
B) Squash on PRAgents commit freely during work, squash to single commit on merge. Best of both
C) Preserve all commitsFull history of agent work. Noisy but complete audit trail

Recommendation: Option B — agents commit as they work (useful for crash recovery), squash on merge keeps main history clean.

Decision:

3. Conflict Resolution

Question: How should agents handle merge conflicts with main?

OptionDescription
A) Auto-rebase and retryAgent rebases on main, re-runs tests. Works for simple conflicts
B) Auto-rebase for simple, escalate complexTry auto-rebase. If conflicts remain, escalate to human with conflict details
C) Always escalateAny conflict goes to human. Safest but slowest

Recommendation: Option B — most conflicts from concurrent agents are trivial (different files). Escalate only when auto-resolution fails.

Decision:


Phase Overview

PhaseDescriptionStatus
Phase 1Branch-per-FR creation, commit conventions, automatic staging
Phase 2PR creation via GitHub API
Phase 3Conflict detection, resolution, merge management

Phase 1: Branch + Commit Automation —

Goal: Automate branch creation and structured commits for agent work.

File / FeatureDetailsOwnerStatus
src/opus/git/branch.pyBranchManager: create, checkout, push, delete branches. Naming convention enforcementopus
src/opus/git/commit.pyCommitBuilder: generate commit messages from agent context (FR ID, phase, summary)opus
src/opus/git/models.pyBranchInfo, CommitInfo dataclassesopus
Branch namingConvention: opus/FR-{id}-{slug} (e.g., opus/FR-058-llm-provider)opus
Commit message format[FR-{id}] {summary} with body containing phase and detailsopus
Auto-stagingStage all changes in worktree before commit (agent controls which files via sandbox)opus
Unit testsBranch creation, naming validation, commit message generationmv

Phase 2: PR Creation —

Goal: Automatically create GitHub PRs with rich descriptions generated from FR context.

File / FeatureDetailsOwnerStatus
src/opus/git/pr.pyPRCreator: create PR via GitHub API (using gh CLI or PyGithub)opus
PR titleFormat: [FR-{id}] {FR title}opus
PR descriptionAuto-generated from: FR summary, phases completed, files changed, test resultsmv
PR labelsAuto-label with opus-agent, FR priority, complexity tieropus
FR linkingReference FR file path and ID in PR descriptionopus
Draft PRsCreate as draft by default, mark ready-for-review after all checks passmv
Integration with FR-018Use GitHub integration (FR-018) for API accessopus
Integration testsCreate PR from test branch, verify description and labelsmv

Phase 3: Conflict Resolution + Merge —

Goal: Handle merge conflicts and manage the merge lifecycle.

File / FeatureDetailsOwnerStatus
src/opus/git/merge.pyMergeManager: rebase on main, detect conflicts, attempt auto-resolutionopus
Conflict detectionBefore PR creation: check if branch can be cleanly mergedopus
Auto-rebaseRebase agent branch on latest main, re-run tests after rebasemv
Complex conflict escalationIf auto-rebase fails: create PR with conflict markers, notify humanmv
Post-merge cleanupDelete remote branch, clean up local worktree, update FR statusopus
Stale branch detectionFlag branches that haven’t been updated in > 24 hoursopus
Integration testsCreate conflicting branches, verify auto-rebase, verify escalationmv

Prerequisites / Gap Analysis

Requirements

RequirementDescription
REQ-0Coding agency design doc reviewed and approved
REQ-1Python project scaffold (FR-009) — git module is Python code
REQ-2GitHub integration (FR-018) — API access for PR creation
REQ-3Sandboxed execution (FR-055) — git ops happen in worktrees

Current State

ComponentStatusDetails
Python scaffoldFR-009 not started
GitHub integrationin-progressFR-018 Phase 1 done (repo + remote)
Git worktreesFR-055 not started

Gap (What’s missing?)

GapEffortBlocker?
Python scaffold (FR-009)MedYes — code needs a home
GitHub API access (FR-018)LowPartially done — need PR creation API
Sandbox worktrees (FR-055)MedYes — git ops happen in worktrees

Test

Manual tests

TestExpectedActualLast
Complex conflict escalates to humanPR created with conflict note, human notifiedpending-

AI-verified tests

ScenarioExpected behaviorVerification method

E2E tests

ScenarioAssertion

Integration tests

ComponentCoverage

Unit tests

ComponentTestsCoverage

History

DateEventDetails
2026-03-12CreatedPart of autonomous coding agency architecture

References

  • FR-018 (GitHub Integration) — API access for PR operations
  • FR-009 (Python Project Scaffold) — code infrastructure prerequisite
  • FR-055 (Sandboxed Code Execution) — git operations happen in worktrees
  • FR-056 (Autonomous Coding Orchestrator) — orchestrator triggers git workflow at pipeline end
  • FR-057 (Code Review Pipeline) — review happens on the diff before PR creation
  • vault/00_system/designs/drafts/autonomous-coding-agency.md — architecture overview