Task-scoped git execution contract: create or reuse one branch/worktree per TASK_ID, prepare PR content, handle merge conflicts, and run wave integration gate. Designed for WAVE-based orchestration.
Enforce one git branch and one worktree per active TASK_ID.
Keep parallel writes isolated by task ownership.
Standardize PR creation, PR content, and conflict handling.
Define and run the Wave Integration Gate after branch merges.
Activation rule
Valid triggers:
The user explicitly requests branch/worktree/PR flow.
The orchestrating agent receives a wave of tasks that require isolated execution.
TASK_ID contract
TASK_ID is the identifier used for branch/worktree naming.
WAVE naming: W1A, W1B, W2A, etc. (wave number + task letter).
Fallback: short explicit identifier assigned at delegation time.
Naming contract
Task branch: wave/{TASK_ID}
Worktree path: .apm/worktrees/{TASK_ID}
Reuse existing task branch/worktree if already initialized.
相关技能
Required setup workflow
Identify TASK_ID:
from active memory_bank/specs/SPEC_{TASK_ID}.md, or
from an explicit identifier provided by the user or orchestrator.
Detect base branch (usually current integration branch, e.g., main).
Ensure .apm/worktrees/ exists.
Create or reuse task branch:
if branch exists, reuse;
if not, create from base branch.
Create or reuse task worktree under .apm/worktrees/{TASK_ID}.
If memory_bank/tasks/{TASK_ID}.md exists and the user wants git traceability in task notes, record compact git context there:
Base branch
Task branch
Worktree path
Worktree resource management
Git worktrees check out only tracked files. Heavy untracked resources (virtual environments, datasets, model artifacts, caches) are absent in a new worktree by default.
Resource classification
Category
Examples
Worktree strategy
Shared runtime (single per repo)
.venv, node_modules
Use the shared runtime from the main tree (no per-worktree envs)
Shared data
data/raw/, data/external/, data/processed/
Reference the main-tree data (do not copy)
Read-reference artifacts
Existing trained models needed for fine-tuning or inference
Subagent references via project structure or absolute path
Task-local outputs
New models, checkpoints, experiment results, logs
Created locally in worktree
Shared runtime protocol (default)
Default policy: keep a single repo-level runtime and reuse it across all worktrees. Do not create a separate .venv (or separate node_modules) per worktree.
If your environment/tooling expects paths to exist inside the worktree, you may create convenience symlinks after step 5 (worktree creation):
Adapt paths to the project layout documented in memory_bank/ARCHITECTURE.md. If the project uses DVC, dvc checkout inside the worktree resolves data references from the shared DVC cache automatically.
Dependency change handling (safe updates)
When a task changes dependencies (pyproject.toml, requirements*.txt, package.json, lockfiles), update the shared runtime using a managed toolchain:
Prefer a lockfile-driven approach (e.g., uv.lock, pnpm-lock.yaml, etc.).
Apply changes via safe sync tools (e.g., uv sync, package-manager install) to update the shared .venv / node_modules.
Serialize updates: do not run concurrent dependency updates across parallel tasks.
After sync, run a short verification relevant to the task scope.
Artifact integration after merge
After merging a task branch into the base branch, untracked task-local artifacts (new models, reports, generated data) remain only in the worktree directory. Before git worktree remove:
Copy new untracked artifacts from the worktree to the corresponding locations in the main tree.
Projects may override the default symlink list via memory_bank/ARCHITECTURE.md (section "Shared resources" or equivalent). If present, follow the project-specific list instead of the defaults above.
Wave Integration Gate
Run after all task branches in a wave are merged and artifacts are migrated. This gate validates the integrated codebase before proceeding to the next wave or final handoff.
Gate steps
Build/compile check: run the project's build or import validation (language-appropriate). For Python: verify all imports resolve (python -c "import <main_module>").
Type check: if contract/Protocol files exist, run the project's type checker (e.g., mypy, pyright). Focus on contract-defined interfaces.
Test suite: run tests in layer order — unit tests first, then contract tests, then cross-task integration tests. If pipeline/E2E tests exist, run those last. If no tests exist yet (e.g., Wave 1 greenfield), note it and skip gracefully.
Dependency audit: verify the lockfile is consistent and no per-worktree runtime was created (no .venv or node_modules inside .apm/worktrees/).
Environment hygiene: confirm all worktrees are cleaned up. No orphan branches remain.
Gate outcome
Pass: all checks succeed (or are gracefully skipped with justification). Proceed to next wave or final handoff.
Fail: fix the failure, re-run the failing check. Do not proceed until the gate passes.
PR contract
Create PR when:
the task is complete, or
the user explicitly requests PR creation.
PR body must include:
Task context (TASK_ID and objective)
What changed
Verification evidence
Risks / deferred items
Conflict notes (if conflicts were resolved)
If PR cannot be opened automatically (missing remote/permissions/tooling):
prepare a PR package (title + full body + verification summary + diff summary),
return it to the user and wait for further instruction.