You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Keep overlapping agent integration off the protected base branch (#232)
Guardex needs a managed merge lane when multiple agent branches touch the same files. This adds the agent-branch-merge workflow, wires gx merge into setup-managed files and package scripts, and makes overlap/conflict handling resumable without merging directly onto main.
Constraint: Protected base branches must remain untouched while overlapping agent work is integrated
Rejected: Merge helper branches directly onto main | breaks the sandboxed integration workflow
Confidence: high
Scope-risk: moderate
Directive: Keep conflict stops resumable and do not auto-resolve overlapping merges beyond ordered git merge behavior
Tested: node --test test/merge-workflow.test.js
Tested: node --check bin/multiagent-safety.js
Tested: openspec validate agent-codex-merge-overlapping-agent-branches-2026-04-21-14-28 --type change --strict
Tested: openspec validate --specs
Tested: git diff --check
Not-tested: npm test still hangs after early passing output in this environment
Co-authored-by: NagyVikt <nagy.viktordp@gmail.com>
- GitGuardex currently finishes one `agent/*` branch into the base branch at a time, but it does not provide an integration workflow for the common case where multiple agent worktrees touched the same implementation files.
4
+
- In that situation users end up staring at several parallel worktrees with overlapping edits and no first-class Guardex command that creates the right integration branch/worktree, reports overlap, and gives a safe place to resolve conflicts.
5
+
- OpenSpec already treats implementation as owner/helper lanes with durable artifacts, so the merge workflow should preserve that model instead of pushing users back to ad hoc manual git work on the protected base.
6
+
7
+
## What Changes
8
+
9
+
- Add a first-class `gx merge` command plus a managed `scripts/agent-branch-merge.sh` workflow.
10
+
- Let the workflow either create a fresh integration `agent/*` branch/worktree from the configured base branch or merge helper branches into an existing owner branch via `--into`.
11
+
- Report overlapping changed files across the requested source branches before merging so users can see where collisions are expected, especially inside shared implementation files and OpenSpec surfaces.
12
+
- Merge branches in explicit order, stop on conflicts without touching the protected base branch, and print resumable instructions that keep conflict resolution inside the integration worktree.
13
+
- Ship the new script through the setup/templates/package metadata path so downstream repos get the same capability.
- Risk: merge automation is sensitive to dirty worktrees and stale branches, so the implementation needs strict preflight checks and clear conflict-stop behavior.
19
+
- Rollout: local CLI/script addition only; no data migration.
### Requirement: integration merge runs inside an agent worktree
4
+
GitGuardex SHALL merge overlapping `agent/*` branches inside an integration `agent/*` branch/worktree instead of merging directly on the protected base branch.
5
+
6
+
#### Scenario: create a fresh integration lane
7
+
-**WHEN** a user runs `gx merge` with one or more `--branch agent/...` inputs and no `--into`
8
+
-**THEN** the system creates a new integration `agent/*` branch/worktree from the configured base branch
9
+
-**AND** all requested merges run inside that integration worktree
10
+
-**AND** the command prints the integration branch and worktree path.
11
+
12
+
#### Scenario: reuse an existing owner lane
13
+
-**WHEN** a user runs `gx merge --into <agent-branch>` with additional source branches
14
+
-**THEN** the system reuses that owner branch as the merge target
15
+
-**AND** it refuses to proceed if the target worktree has uncommitted changes or an in-progress merge operation.
16
+
17
+
### Requirement: overlapping file edits are reported before merge
18
+
GitGuardex SHALL detect and report files changed by more than one requested source branch before applying the merges.
-**WHEN** two or more requested source branches changed the same file relative to the merge base
22
+
-**THEN** the command prints each overlapping file
23
+
-**AND** it identifies the source branches that changed that file
24
+
-**AND** it still allows the user to continue into the integration lane unless another hard preflight check fails.
25
+
26
+
### Requirement: conflicts stop with resumable guidance
27
+
GitGuardex SHALL stop on merge conflicts inside the integration worktree and provide resumable next-step guidance without mutating the protected base branch.
28
+
29
+
#### Scenario: sequential merge hits a conflict
30
+
-**WHEN**`gx merge` successfully merges earlier source branches and then encounters a conflict on a later source branch
31
+
-**THEN** the command exits non-zero
32
+
-**AND** it prints the target integration branch/worktree, the source branch that conflicted, and the conflicting files
33
+
-**AND** it tells the user how to resolve or abort the conflict inside the integration worktree
34
+
-**AND** it prints the remaining branches so the merge sequence can be resumed intentionally afterward.
35
+
36
+
### Requirement: setup-managed repos receive the merge workflow
37
+
GitGuardex setup/doctor SHALL install the managed merge workflow files and package script entry needed to run `gx merge`.
38
+
39
+
#### Scenario: setup bootstraps a repo
40
+
-**WHEN**`gx setup` or `gx doctor --repair` installs managed workflow files
41
+
-**THEN** the repo contains `scripts/agent-branch-merge.sh`
42
+
-**AND** the repo package scripts include a stable merge entry point for the managed workflow.
-[x] 1.1 Finalize acceptance criteria for the overlapping-agent merge workflow.
4
+
-[x] 1.2 Define normative requirements for integration-branch creation, overlap reporting, and conflict-stop behavior.
5
+
6
+
## 2. Implementation
7
+
8
+
-[x] 2.1 Add a managed `agent-branch-merge` script that can create or reuse an integration worktree and merge multiple `agent/*` branches in order.
9
+
-[x] 2.2 Add `gx merge` CLI wiring, package metadata, and template/setup propagation for the new workflow.
10
+
-[x] 2.3 Keep the protected base branch untouched while merging and print resumable instructions for conflict resolution.
11
+
12
+
## 3. Verification
13
+
14
+
-[x] 3.1 Add/update focused regression coverage for clean merges, overlap reporting, and conflict-stop behavior.
15
+
-[ ] 3.2 Run `npm test`. BLOCKED: full suite produced early passing output but then stayed silent/hung in this environment; focused `node --test test/merge-workflow.test.js` passed.
16
+
-[x] 3.3 Run `node --check bin/multiagent-safety.js`.
17
+
-[x] 3.4 Run `openspec validate agent-codex-merge-overlapping-agent-branches-2026-04-21-14-28 --type change --strict`.
18
+
-[x] 3.5 Run `openspec validate --specs`.
19
+
-[x] 3.6 Run `git diff --check`.
20
+
21
+
## 4. Completion
22
+
23
+
-[ ] 4.1 Finish the agent branch via PR merge + cleanup (`gx finish --via-pr --wait-for-merge --cleanup` or `bash scripts/agent-branch-finish.sh --branch <agent-branch> --base <base-branch> --via-pr --wait-for-merge --cleanup`).
24
+
-[ ] 4.2 Record PR URL + final `MERGED` state in the completion handoff.
25
+
-[ ] 4.3 Confirm sandbox cleanup (`git worktree list`, `git branch -a`) or capture a `BLOCKED:` handoff if merge/cleanup is pending.
0 commit comments