Skip to content

Commit d3ce033

Browse files
committed
docs: strengthen worktree requirements with validation script
Multiple agents were working in the main worktree, causing branch conflicts. This commit makes the worktree requirement impossible to miss: - CLAUDE.md: Added prominent pre-flight check at the top - AGENTS.md: Moved worktree section to position 2 with stronger warnings - scripts/validate-worktree.sh: New validation script for agents to run The main worktree must always stay on 'main' branch. All feature work must happen in separate worktrees created as sibling directories. Related incident: Agents working on PR #2107 and stacked work were both using main worktree, risking conflicts and lost commits.
1 parent 5d01af0 commit d3ce033

File tree

2 files changed

+92
-8
lines changed

2 files changed

+92
-8
lines changed

AGENTS.md

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,53 @@
33
## Project Overview
44
Freenet Core is the peer-to-peer runtime that underpins applications in the Freenet ecosystem. The crates in this workspace implement the networking stack, contract execution environment, and developer tooling used by higher-level projects such as River.
55

6+
## ⚠️ CRITICAL: Git Worktree Requirement
7+
8+
**BEFORE STARTING ANY WORK, verify your working directory:**
9+
10+
```bash
11+
pwd # Must be ~/code/freenet/freenet-core/<branch-name>
12+
# NOT ~/code/freenet/freenet-core/main
13+
git branch --show-current # Should be your feature branch, NOT 'main'
14+
```
15+
16+
### ❌ DO NOT work in ~/code/freenet/freenet-core/main
17+
18+
The main worktree should **always** remain on the `main` branch. Multiple agents working in main will conflict and corrupt branches.
19+
20+
### ✅ Creating a Worktree for Your Branch
21+
22+
1. Create a worktree as a sibling directory:
23+
```bash
24+
cd ~/code/freenet/freenet-core/main
25+
git worktree add ../fix-<issue-number> <your-branch-name>
26+
cd ../fix-<issue-number>
27+
```
28+
29+
2. Verify you're in the correct location:
30+
```bash
31+
pwd # Should show .../freenet-core/fix-<issue-number>
32+
git branch --show-current # Should show your branch
33+
```
34+
35+
3. Now you can safely commit and push from this worktree.
36+
37+
### Worktree Naming Convention
38+
39+
Include the issue or PR number for clarity:
40+
- `fix-2107` for PR #2107
41+
- `issue-2092` for issue #2092
42+
- `fix-i2021-blocked-peers` for issue #2021 with descriptive name
43+
44+
### Managing Worktrees
45+
46+
```bash
47+
git worktree list # See all active worktrees
48+
git worktree remove ../fix-2107 # Remove when branch merges
49+
```
50+
51+
**After a PR merges, remove the worktree** to free disk space (each worktree has its own `target/` directory consuming 10-50GB).
52+
653
## Repository Layout
754
- `crates/` – core libraries, binaries, and developer tooling (`core`, `gateway`, `fdev`, etc.)
855
- `apps/` – integration binaries (benchmarks, diagnostic tools)
@@ -12,14 +59,6 @@ Freenet Core is the peer-to-peer runtime that underpins applications in the Free
1259

1360
Refer to `README.md` for a more detailed component map.
1461

15-
## Working with Git Worktrees
16-
- Keep a checkout on the `main` branch (for example, this directory) and create per-branch worktrees as siblings:
17-
```bash
18-
git worktree add ../my-feature-branch feature/my-feature-branch
19-
```
20-
- Run `git worktree list` to see active worktrees and `git worktree remove ../my-feature-branch` when a branch merges.
21-
- Avoid committing from the `main` checkout; perform branch work inside the corresponding worktree directory to prevent conflicts between contributors.
22-
2362
## Bootstrapping & Tooling
2463
```bash
2564
git submodule update --init --recursive

scripts/validate-worktree.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# Validates that current directory is not the main worktree
3+
# Usage: ./scripts/validate-worktree.sh
4+
5+
set -e
6+
7+
CURRENT_DIR=$(pwd)
8+
CURRENT_BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
9+
10+
# Check if we're in the main worktree directory
11+
if [[ "$CURRENT_DIR" == */freenet-core/main ]]; then
12+
echo "❌ ERROR: You are in the main worktree!"
13+
echo ""
14+
echo "Current directory: $CURRENT_DIR"
15+
echo "Current branch: $CURRENT_BRANCH"
16+
echo ""
17+
echo "The main worktree should stay on 'main' branch for reference."
18+
echo "Multiple agents working in main will conflict and corrupt branches."
19+
echo ""
20+
echo "To fix this:"
21+
echo " 1. Create a worktree for your branch:"
22+
echo " cd ~/code/freenet/freenet-core/main"
23+
echo " git worktree add ../fix-<issue-number> <your-branch-name>"
24+
echo ""
25+
echo " 2. Switch to the new worktree:"
26+
echo " cd ../fix-<issue-number>"
27+
echo ""
28+
echo " 3. Continue your work there"
29+
echo ""
30+
exit 1
31+
fi
32+
33+
# Verify we're in a freenet-core worktree (but not main)
34+
if [[ "$CURRENT_DIR" == */freenet-core/* ]] && [[ "$CURRENT_DIR" != */freenet-core/main ]]; then
35+
echo "✅ OK: Working in separate worktree"
36+
echo " Directory: $CURRENT_DIR"
37+
echo " Branch: $CURRENT_BRANCH"
38+
exit 0
39+
fi
40+
41+
# If we're somewhere else entirely, warn but don't fail
42+
echo "⚠️ WARNING: Not in a freenet-core directory"
43+
echo " Current: $CURRENT_DIR"
44+
echo " Expected: ~/code/freenet/freenet-core/<branch-name>"
45+
exit 0

0 commit comments

Comments
 (0)