Skip to content

Commit c0c77b2

Browse files
feat(docs): add Git Worktrees documentation and update agent workflow overview
1 parent 6373290 commit c0c77b2

3 files changed

Lines changed: 206 additions & 82 deletions

File tree

docs/Agents/Git-Worktrees.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Git Worktrees
2+
3+
All repositories are set up as **bare clones with worktrees**. This enables parallel work — multiple agents (or a human and an agent) can work on different issues in the same repository simultaneously without conflicts, stashing, or context-switching.
4+
5+
## Why worktrees
6+
7+
| Problem with traditional clones | How worktrees solve it |
8+
| -------------------------------------------- | --------------------------------------------------------- |
9+
| Only one branch checked out at a time | Each issue gets its own worktree — parallel by default |
10+
| Switching branches requires clean state | Worktrees are independent — no stashing or committing WIP |
11+
| Agent work blocks human work on same repo | Different worktrees, no interference |
12+
| Default branch gets dirty during development | `main/` worktree is always a clean reference |
13+
14+
## Repository layout
15+
16+
```text
17+
<repo-root>/
18+
├── .bare/ # bare git data (the actual repository)
19+
├── .git # file containing: gitdir: ./.bare
20+
├── main/ # worktree: default branch (always clean, never worked in directly)
21+
├── 42-add-pagination/ # worktree: issue #42 in progress
22+
└── 99-fix-null-ref/ # worktree: issue #99 in progress
23+
```
24+
25+
- **`.bare/`** — the shared git object store. All worktrees share this.
26+
- **`.git`** — a file (not a directory) that points git tooling to `.bare/`.
27+
- **`main/`** — the default branch worktree. Kept as a clean reference. Used for diffing, reading docs, running comparisons. Never directly committed to.
28+
- **`<N>-<slug>/`** — one worktree per issue in flight. Named by issue number and a short slug. Branch name matches the folder name.
29+
30+
## Remotes
31+
32+
Every repository has exactly two remotes (or one, if it is not a fork):
33+
34+
| Remote | Points to | Required | Purpose |
35+
| -------------- | ---------------------------- | -------- | ------------------------------------------------ |
36+
| **`origin`** | Our copy on the server | Always | Push branches, open PRs, CI runs against this. |
37+
| **`upstream`** | The parent repo (forks only) | Forks | Track upstream changes, sync the default branch. |
38+
39+
No other remotes are added. This keeps the model simple and predictable for both humans and agents.
40+
41+
### How it works in practice
42+
43+
- **Non-fork repos** — only `origin` exists. Branches are pushed to `origin`, PRs are opened against `origin`.
44+
- **Forked repos**`origin` is our fork, `upstream` is the original repository. The default branch tracks `upstream` for syncing; feature branches are pushed to `origin` and PRs are opened from `origin` into `upstream`.
45+
46+
### Fetch configuration
47+
48+
Both remotes are configured with full refspecs so `git fetch --all --prune` keeps everything current:
49+
50+
```text
51+
[remote "origin"]
52+
fetch = +refs/heads/*:refs/remotes/origin/*
53+
54+
[remote "upstream"] # forks only
55+
fetch = +refs/heads/*:refs/remotes/upstream/*
56+
```
57+
58+
## Setup (one-time per repository)
59+
60+
```powershell
61+
# Clone as bare into .bare/
62+
git clone --bare https://github.com/<owner>/<repo>.git .bare
63+
64+
# Create the .git pointer file
65+
Set-Content .git "gitdir: ./.bare" -NoNewline
66+
67+
# Configure fetch refspec (bare clones don't set this automatically)
68+
git -C .bare config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
69+
70+
# Fetch remote branches
71+
git -C .bare fetch origin
72+
73+
# Create the default branch worktree
74+
git -C .bare worktree add ../main main
75+
```
76+
77+
> The [Checkout-GitHubRepo](https://github.com/MariusStorhaug/.dev/blob/main/.github/Checkout-GitHubRepo.ps1) script automates this for all repositories.
78+
79+
## Working on an issue
80+
81+
```powershell
82+
# From the repo root (where .bare/ lives)
83+
git -C .bare worktree add ../42-add-pagination -b 42-add-pagination main
84+
85+
# Open in VS Code
86+
code 42-add-pagination
87+
```
88+
89+
Then follow the normal Implement flow: initial commit → push → draft PR → build → finalize.
90+
91+
## Cleanup after merge
92+
93+
```powershell
94+
# Remove the worktree
95+
git -C .bare worktree remove 42-add-pagination
96+
97+
# Prune if needed (removes stale worktree references)
98+
git -C .bare worktree prune
99+
```
100+
101+
The sync script handles this automatically — worktrees whose branch no longer exists on any remote are removed during the next sync.
102+
103+
## Parallel agents
104+
105+
The worktree model enables multiple agents to work in the same repository at the same time:
106+
107+
- Each agent operates in its own worktree (its own issue folder).
108+
- No merge conflicts during development — conflicts only surface at PR merge time.
109+
- The default branch worktree provides a stable reference for all agents to read from.
110+
- CI runs independently per PR, so agents don't block each other.
111+
112+
```text
113+
Agent A: working in 42-add-pagination/
114+
Agent B: working in 43-fix-auth-flow/
115+
Human: reviewing in main/ or reading docs
116+
```
117+
118+
## VS Code integration
119+
120+
- **Open the worktree folder directly** — VS Code's Git extension auto-detects the git context.
121+
- **Multi-root workspace** — add multiple worktrees to one window (`File → Add Folder to Workspace`) to reference `main/` while coding in another.
122+
- **Terminal cwd** — ensure the integrated terminal is in the worktree folder, not the bare root.
123+
124+
## Rules
125+
126+
1. **Never commit directly to the default branch worktree.** It exists for reference only.
127+
2. **One worktree per issue.** The folder name matches the branch name: `<N>-<slug>`.
128+
3. **Clean up after merge.** Remove the worktree and let the sync script prune stale branches.
129+
4. **All git config lives in `.bare/`** — it applies to every worktree automatically.
130+
5. **Only `origin` and `upstream` remotes.** No other remotes. `upstream` only exists for forks.

docs/Agents/Workflow.md

Lines changed: 69 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,74 @@ How the agent roles connect across the **Context Development Lifecycle (CDLC)**
77
The CDLC and the SDLC run side by side. The CDLC keeps **context** evergreen — issues, decisions, READMEs, docs. The SDLC delivers **software** — code, tests, releases. Each iteration of one feeds the other.
88

99
```text
10-
┌────────────────────────────────────────────────────────────┐
11-
│ Context Development Lifecycle │
12-
│ │
13-
│ ideator → clarifier → planner │
14-
│ ▲ │ │
15-
│ │ ▼ │
16-
│ (capture) (decide) │
17-
│ │ │
18-
└──────────────────────────────────┼──────────────────────────┘
19-
20-
21-
┌──────────────────────────────────┼──────────────────────────┐
22-
│ │ │
23-
│ Software Development Lifecycle │
24-
│ │
25-
│ builder → shipper → reviewer │
26-
│ ▲ │ │
27-
│ │ ▼ │
28-
│ (respond) ◄── responder │
29-
│ │
30-
└─────────────────────────────────────────────────────────────┘
31-
32-
33-
Run / operate
34-
(DevOps + SRE loop)
35-
36-
37-
Signals, errors, feedback
38-
39-
40-
ideator (again)
10+
┌───────────────────────────────────────────────────────┐
11+
│ Context Development Lifecycle │
12+
│ │
13+
│ Define │
14+
│ (capture → refine → plan) │
15+
│ │ │
16+
│ ┌──────────────┼──────────────┐ │
17+
│ ▼ ▼ ▼ │
18+
│ simple task sub-issues checklist │
19+
│ │
20+
└───────────────────────┼───────────────────────────────┘
21+
22+
23+
┌───────────────────────┼───────────────────────────────┐
24+
│ │ │
25+
│ Software Development Lifecycle │
26+
│ │
27+
│ Implement │
28+
│ (branch → draft PR → build → finalize) │
29+
│ │ │
30+
│ ▼ │
31+
│ Reviewer │
32+
│ │ │
33+
│ fixes needed? → Implement (respond) │
34+
│ │
35+
└───────────────────────────────────────────────────────┘
36+
37+
38+
Run / operate
39+
(DevOps + SRE loop)
40+
41+
42+
Signals, errors, feedback
43+
44+
45+
Define (again)
4146
```
4247

43-
> A richer visual version of this diagram lives in Figma (linked from the homepage). Mermaid covers the structure; the Figma version covers the relationships between CDLC, SDLC, and operations.
48+
## The agents
4449

45-
## The roles in order
50+
### Define
4651

47-
### 1. Capture — Ideator
52+
Combines **capture**, **refine**, and **plan** into a single flow. Takes any input — a desire, a bug, a signal — and produces a planned, actionable issue.
4853

49-
A desire becomes a real, actionable item. Could be a feature request, a bug, an improvement, a triaged piece of external feedback, or a signal from production. Output: an issue with Section 1 only.
54+
**Output is one of:**
5055

51-
### 2. Refine — Clarifier
56+
- A single Task with Sections 1–3 (context, decisions, checklist).
57+
- A decomposed PBI or Epic with structured sub-issues, each scoped to one PR.
5258

53-
The desire is grounded. Assumptions surfaced. Acceptance criteria sharpened to be testable. Section 1 becomes unambiguous. No solutioning yet.
59+
See [Issue Format](Issue-Format.md) and [Issue Hierarchy](Issue-Hierarchy.md) for the structure.
5460

55-
### 3. Plan — Planner
61+
### Implement
5662

57-
The work is decided and (often) decomposed.
63+
Takes a planned issue and delivers a merge-ready pull request. Owns the full loop:
5864

59-
- **Task** — one deliverable, one PR. Sections 2 and 3 populated.
60-
- **Product Backlog Item (PBI)** — several Tasks. Section 2 documents decomposition; Section 3 lists children.
61-
- **Epic** — several PBIs. Top-level co-planning artifact, often paired with an OKR.
65+
1. **Orient** — read the issue, README, contribution guide, and standards.
66+
2. **Branch and draft PR** — create a [worktree](Git-Worktrees.md) for the issue, push early so CI attaches and progress is visible. Assign to the user. Link to the issue.
67+
3. **Build** — micro-commits, one logical change each. Update the issue as each task completes (not in bulk).
68+
4. **Respond** — process reviewer feedback and CI failures. One thread at a time.
69+
5. **Finalize** — update PR title, labels, and description as a user-facing release note.
6270

63-
Issue hierarchy is described in [Issue Hierarchy](Issue-Hierarchy.md).
71+
See [Git Worktrees](Git-Worktrees.md), [PR Format](PR-Format.md), [Commit Conventions](Commit-Conventions.md), and [Standards](Standards/index.md).
6472

65-
### 4. Build — Builder
73+
### Reviewer
6674

67-
Code is written. The Task issue is the contract. Standards come from [Standards](Standards/index.md); linter rules in the repo win. Commits are small and descriptive.
75+
Reviews someone else's PR. Checks delivery against the linked issue, good taste, security, and undiscussed decisions.
6876

69-
### 5. Ship — Shipper
70-
71-
The branch becomes a draft PR with a release-note style description. Issue linked, labels applied, reviewers requested.
72-
73-
### 6. Review — Reviewer
74-
75-
Someone other than the author reads the PR with intent: does it deliver the issue, is the code in good taste, are the security best practices respected, are there undiscussed decisions hiding in the diff?
76-
77-
### 7. Respond — Responder
78-
79-
The author closes the loop. One thread at a time: read, evaluate, fix or defer, reply, resolve. CI failures handled similarly. Repeat until the loop converges.
80-
81-
After merge, the change runs in production. Signals — errors, logs, user feedback, alerts — feed back into the Ideator. The loop never really stops.
77+
See [Review Etiquette](Review-Etiquette.md).
8278

8379
## Three horizons of planning
8480

@@ -96,18 +92,19 @@ Borrowed from [Principles → Roadmapping](Principles.md#roadmapping). The plann
9692

9793
## Where the principles show up
9894

99-
| Principle | Most relevant phase |
95+
| Principle | Most relevant agent |
10096
| ------------------------------- | ---------------------------------- |
101-
| Golden Circle (Why / How / What)| Capture, Plan |
102-
| OKRs | Plan (especially Epic-level) |
103-
| YAGNI / Lean | Plan, Build |
104-
| Test-Driven Development | Build |
105-
| Clean Code | Build, Review |
106-
| Evolutionary Architecture | Plan, Build, Review |
107-
| 4-eyes | Review |
108-
| README-Driven Context | Build, Ship |
109-
| GTD ("write it down") | All phases |
110-
| Determinism over intelligence | Build |
97+
| Golden Circle (Why / How / What)| Define |
98+
| OKRs | Define (especially Epic-level) |
99+
| YAGNI / Lean | Define, Implement |
100+
| Test-Driven Development | Implement |
101+
| Clean Code | Implement, Reviewer |
102+
| Evolutionary Architecture | Define, Implement, Reviewer |
103+
| 4-eyes | Reviewer |
104+
| README-Driven Context | Implement |
105+
| GTD ("write it down") | All agents |
106+
| Determinism over intelligence | Implement |
107+
| Git Worktrees (parallel work) | Implement |
111108
| Dogfooding | Run / operate phase |
112109

113110
See [Principles](Principles.md) for the full set.
@@ -116,9 +113,9 @@ See [Principles](Principles.md) for the full set.
116113

117114
The agent workflow is itself a series of loops at different speeds.
118115

119-
- **Innermost** — editor + tests + the Builder. Sub-minute.
120-
- **Inner** — push + CI + Reviewer + Responder. Minutes to hours.
121-
- **Outer** — issue lifecycle, decomposition refinement, planning review. Days.
116+
- **Innermost** — editor + tests + Implement (build). Sub-minute.
117+
- **Inner** — push + CI + Reviewer + Implement (respond). Minutes to hours.
118+
- **Outer** — issue lifecycle, decomposition, Define. Days.
122119
- **Outermost** — strategy, OKR check-ins, vision adjustments. Weeks to quarters.
123120

124121
Each agent operates at its own loop. Keep work close to the loop where it is cheapest to iterate.

docs/Agents/index.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ This matters because:
1717
## The lifecycle
1818

1919
```text
20-
ideatorclarifierplanner → builder → shipper → reviewer
21-
22-
└─ responder ◄┘
20+
DefineImplementReviewer
21+
22+
└── (respond) ◄┘
2323
```
2424

25-
Each role is a small, focused agent. Standards are referenced, not embedded.
25+
Each role is a focused agent. Standards are referenced, not embedded.
2626

2727
| Role | Phase | Purpose |
2828
| ----------- | ---------------- | ----------------------------------------------------------------------- |
29-
| Ideator | Capture | Capture a desire for change as an actionable issue. |
30-
| Clarifier | Refine | Ground the issue in the real problem. Validate acceptance criteria. |
31-
| Planner | Plan | Decide and decompose. Choose Epic / PBI / Task. Resolve open decisions. |
32-
| Builder | Build | Implement the task. Reference standards. Micro-iterative commits. |
33-
| Shipper | Ship | Package the work into a PR with a release-note style description. |
29+
| Define | Capture + Refine + Plan | Capture a desire, ground it, and produce a planned issue or sub-issues. |
30+
| Implement | Build + Ship + Respond | Branch, draft PR, code, micro-commit, track progress, finalize PR. |
3431
| Reviewer | Review | Review someone else's PR for delivery, taste, and security. |
35-
| Responder | Respond | Author-side: act on reviewer feedback and CI. Close the loop. |
3632

3733
## What lives here
3834

@@ -44,6 +40,7 @@ Each role is a small, focused agent. Standards are referenced, not embedded.
4440
- **[Commit Conventions](Commit-Conventions.md)** — How we write commit messages.
4541
- **[Review Etiquette](Review-Etiquette.md)** — Tone, scope, and how to disagree well.
4642
- **[README-Driven Context](Readme-Driven-Context.md)** — Why the README is the front door and the contract.
43+
- **[Git Worktrees](Git-Worktrees.md)** — Bare-clone + worktree layout for parallel work with agents.
4744
- **[Standards](Standards/index.md)** — Per-language and per-platform standards referenced by the agents.
4845

4946
## Guiding intent

0 commit comments

Comments
 (0)