From 2dbda7a7831f7b37ca1b554536adc8497b252e2a Mon Sep 17 00:00:00 2001 From: Rudy Date: Wed, 4 Nov 2026 14:12:25 +0100 Subject: [PATCH 1/3] fix: git worktrees are one repository in the scan; clones of one remote are not a link; test files are not evidence --- internal/scan/links.go | 6 +++++- internal/scan/scan.go | 44 +++++++++++++++++++++++++++++++++++++- internal/scan/scan_test.go | 25 ++++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/internal/scan/links.go b/internal/scan/links.go index 75b1591..8ca0b20 100644 --- a/internal/scan/links.go +++ b/internal/scan/links.go @@ -29,7 +29,7 @@ type Link struct { const minNameLength = 4 // generated or vendored files say nothing about what a person works with. -var excluded = []string{":!graphify-out", ":!node_modules", ":!vendor", ":!*.lock", ":!package-lock.json", ":!go.sum", ":!*.min.js", ":!*.svg"} +var excluded = []string{":!graphify-out", ":!node_modules", ":!vendor", ":!*.lock", ":!package-lock.json", ":!go.sum", ":!*.min.js", ":!*.svg", ":!*_test.go", ":!testdata", ":!*.test.*", ":!*.spec.*"} // Links returns the mentions between the repositories, strongest first. A repository is never linked // to itself. @@ -40,6 +40,10 @@ func Links(repos []Repo) []Link { if a.Path == b.Path { continue } + // Two clones of the same remote are one project, not a dependency. + if a.Slug != "" && a.Slug == b.Slug { + continue + } l := Link{From: a.Name, To: b.Name} strong := map[string]bool{} if b.Slug != "" { diff --git a/internal/scan/scan.go b/internal/scan/scan.go index af1dec4..233ec37 100644 --- a/internal/scan/scan.go +++ b/internal/scan/scan.go @@ -26,6 +26,9 @@ type Repo struct { Agents bool `json:"agents"` // has AGENTS.md or CLAUDE.md LastCommit string `json:"last_commit"` // YYYY-MM-DD Slug string `json:"slug,omitempty"` // owner/name of the origin remote, when it has one + // Worktrees are the other working copies of this same repository found in the scanned folder + // (git worktrees). They are one repository, not several. + Worktrees []string `json:"worktrees,omitempty"` } // Find returns the git repositories directly inside dir (and dir itself if it is one), sorted by name. @@ -96,13 +99,14 @@ func FindDepth(dir string, depth int) ([]Repo, error) { } else { walk(abs, 1) } + paths, wt := mergeWorktrees(paths) var out []Repo for _, p := range paths { name := filepath.Base(p) if rel, err := filepath.Rel(abs, p); err == nil && rel != "." && strings.Contains(rel, string(filepath.Separator)) { name = filepath.ToSlash(rel) } - r := Repo{Name: name, Path: p} + r := Repo{Name: name, Path: p, Worktrees: wt[p]} r.Relai = exists(filepath.Join(p, "relai.yaml")) r.Tracker = exists(filepath.Join(p, ".beads")) r.OpenSpec = exists(filepath.Join(p, "openspec")) @@ -120,6 +124,44 @@ func FindDepth(dir string, depth int) ([]Repo, error) { return out, nil } +// mergeWorktrees keeps one path per repository: the working copies sharing a git directory (git +// worktrees) are one project. The main working copy wins (its .git is a folder); with only linked +// copies the first path in name order stays. The others are returned under the kept path. +func mergeWorktrees(paths []string) ([]string, map[string][]string) { + group := map[string][]string{} + var order []string + for _, p := range paths { + key := git(p, "rev-parse", "--path-format=absolute", "--git-common-dir") + if key == "" { + key = p + } + if _, ok := group[key]; !ok { + order = append(order, key) + } + group[key] = append(group[key], p) + } + var kept []string + extra := map[string][]string{} + for _, k := range order { + ps := group[k] + sort.Strings(ps) + main := ps[0] + for _, p := range ps { + if st, err := os.Stat(filepath.Join(p, ".git")); err == nil && st.IsDir() { + main = p + break + } + } + kept = append(kept, main) + for _, p := range ps { + if p != main { + extra[main] = append(extra[main], p) + } + } + } + return kept, extra +} + func isRepo(p string) bool { return exists(filepath.Join(p, ".git")) } func exists(p string) bool { _, err := os.Stat(p); return err == nil } diff --git a/internal/scan/scan_test.go b/internal/scan/scan_test.go index c0305ea..844363d 100644 --- a/internal/scan/scan_test.go +++ b/internal/scan/scan_test.go @@ -241,3 +241,28 @@ func TestWeakMentionsInConfigFilesCountMoreThanInDocuments(t *testing.T) { t.Error("--min-weak 3 should make three documents enough") } } + +func TestWorktreesAreOneRepo(t *testing.T) { + root := t.TempDir() + main := filepath.Join(root, "app") + run := func(dir string, args ...string) { + t.Helper() + c := exec.Command("git", append([]string{"-C", dir, "-c", "user.name=t", "-c", "user.email=t@t"}, args...)...) + if out, err := c.CombinedOutput(); err != nil { + t.Fatalf("git %v: %v %s", args, err, out) + } + } + if err := os.MkdirAll(main, 0o755); err != nil { + t.Fatal(err) + } + run(main, "init", "-q") + run(main, "commit", "-q", "--allow-empty", "-m", "x") + run(main, "worktree", "add", "-q", filepath.Join(root, "app-feature"), "-b", "feature") + repos, err := Find(root) + if err != nil { + t.Fatal(err) + } + if len(repos) != 1 || repos[0].Name != "app" || len(repos[0].Worktrees) != 1 { + t.Fatalf("want one repo app with one worktree, got %+v", repos) + } +} From e2b96568fde3b3d1571ec300e1d37765285f3fdc Mon Sep 17 00:00:00 2001 From: Rudy Date: Wed, 4 Nov 2026 14:18:04 +0100 Subject: [PATCH 2/3] fix: tidy closes only on a keyword directly followed by task ids, says when closures wait for the merge; post-merge hook gets a watchdog without timeout(1) --- cmd/relai/main.go | 5 ++++- internal/initrepo/initrepo.go | 6 +++++- internal/tidy/tidy.go | 16 ++++++++++++++-- internal/tidy/tidy_test.go | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cmd/relai/main.go b/cmd/relai/main.go index f4fe711..5a78edb 100644 --- a/cmd/relai/main.go +++ b/cmd/relai/main.go @@ -263,7 +263,10 @@ func main() { for _, n := range r.Notes { fmt.Println("note:", n) } - if !*quiet && len(r.Closed)+len(r.DeletedBranches) == 0 && len(r.Notes) == 0 { + if !*quiet && p.Deferred > 0 { + fmt.Printf("%d task(s) have a closing commit on this branch; they will be closed once it is merged into %s.\n", p.Deferred, p.Default) + } + if !*quiet && len(r.Closed)+len(r.DeletedBranches) == 0 && len(r.Notes) == 0 && p.Deferred == 0 { fmt.Println("nothing to do.") } case "workspace": diff --git a/internal/initrepo/initrepo.go b/internal/initrepo/initrepo.go index 8c548e2..39b49aa 100644 --- a/internal/initrepo/initrepo.go +++ b/internal/initrepo/initrepo.go @@ -143,7 +143,11 @@ limit=${RELAI_HOOK_TIMEOUT:-60} if command -v timeout >/dev/null 2>&1; then timeout "$limit" relai tidy --apply --quiet || true else - relai tidy --apply --quiet || true + # no timeout(1) (macOS): a watchdog stops relai if it takes too long + relai tidy --apply --quiet >/dev/null 2>&1 & pid=$! + ( sleep "$limit"; kill "$pid" 2>/dev/null ) >/dev/null 2>&1 & dog=$! + wait "$pid" 2>/dev/null + kill "$dog" 2>/dev/null fi exit 0 ` diff --git a/internal/tidy/tidy.go b/internal/tidy/tidy.go index 5d82f88..de1f778 100644 --- a/internal/tidy/tidy.go +++ b/internal/tidy/tidy.go @@ -34,6 +34,9 @@ type Plan struct { Close []Closure `json:"close"` Named []Closure `json:"named_not_closed"` // open tasks named in a commit without a closing keyword Branches []string `json:"merged_branches"` + // Deferred counts the tasks a commit of the current (not default) branch says it closes; they are + // closed after the merge, not before. + Deferred int `json:"deferred_closures,omitempty"` } // Result is what Apply did. @@ -98,6 +101,7 @@ func Build(dir string, limit int) (Plan, error) { } if !p.OnDefault { // Work on a feature branch is not merged yet: closing its tasks now would be wrong. + p.Deferred = len(p.Close) p.Close = nil } if out, err := git(dir, "branch", "--merged", p.Default, "--format=%(refname:short)"); err == nil { @@ -112,7 +116,10 @@ func Build(dir string, limit int) (Plan, error) { } func closes(msg, id string) bool { - re := regexp.MustCompile(`(?i)\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\b[:\s]+(?:[^\n]*?[\s,]|)#?` + regexp.QuoteMeta(id) + `\b`) + // The keyword must be followed directly by task ids ("Closes a-1, a-2 and a-3"), never by free text: + // "Fixes typo in docs, see a-1" mentions a-1, it does not close it. + tok := `#?(?:[A-Za-z0-9]+(?:[.-][A-Za-z0-9]+)+|\d+)` + re := regexp.MustCompile(`(?im)\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\b:?[ \t]+(?:` + tok + `(?:[ \t]*(?:,|&|\band\b)?[ \t]+))*#?` + regexp.QuoteMeta(id) + `(?:[^A-Za-z0-9_-]|$)`) return re.MatchString(msg) } @@ -197,8 +204,13 @@ func exportTasks(dir string) error { func (p Plan) Text() string { var b strings.Builder fmt.Fprintf(&b, "tidy (default branch: %s%s)\n", p.Default, map[bool]string{true: "", false: "; you are on another branch, so no task is closed from here"}[p.OnDefault]) + if p.Deferred > 0 { + fmt.Fprintf(&b, "%d task(s) have a closing commit on this branch; they will be closed once it is merged into %s.\n", p.Deferred, p.Default) + } if len(p.Close) == 0 && len(p.Named) == 0 && len(p.Branches) == 0 { - b.WriteString("nothing to do.\n") + if p.Deferred == 0 { + b.WriteString("nothing to do.\n") + } return b.String() } for _, c := range p.Close { diff --git a/internal/tidy/tidy_test.go b/internal/tidy/tidy_test.go index f89527f..4586d05 100644 --- a/internal/tidy/tidy_test.go +++ b/internal/tidy/tidy_test.go @@ -150,3 +150,22 @@ func mustLook(n string) string { } return p } + +func TestClosesNeedsKeywordThenIds(t *testing.T) { + yes := []string{"Closes p-4", "closes: p-4", "Fixes p-1, p-4", "Resolves p-1 and p-4", "feat: x\n\nCloses #p-4", "Closes relai-a7o.2", "Fix p-4."} + no := []string{"Fixes typo in docs, see p-4", "Closes the loop, p-4 is next", "see p-4", "Fixed a bug related to p-4", "Closes p-44"} + for _, m := range yes { + id := "p-4" + if strings.Contains(m, "a7o") { + id = "relai-a7o.2" + } + if !closes(m, id) { + t.Errorf("%q should close %s", m, id) + } + } + for _, m := range no { + if closes(m, "p-4") { + t.Errorf("%q must not close p-4", m) + } + } +} From c23bc6b7f2294575b8abc13c69e2e7203ebf0b8c Mon Sep 17 00:00:00 2001 From: Rudy Date: Wed, 4 Nov 2026 14:18:31 +0100 Subject: [PATCH 3/3] docs: say who gets what (solo with agents today, team layer when parallelism arrives) --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 747a1ae..a950325 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,12 @@ the handoff is being evaluated with real agents in [`eval/`](eval/README.md). Made to be easy: one binary, no server, nothing but git. Useful on day one for a single person or a small team; the multi-project features (index, conventions) are optional layers. +**Who gets what.** Measured on a real set of 16 repositories of one developer working alone with agents: +`relai workspace` (the overview of every project, about 400 tokens) and the handoff are what pay off today. +The team board ([RELAI-TEAM](https://github.com/ECG-Rudy-Glt/RELAI-TEAM)) answers a problem that starts when +several people or agents work in parallel on the same projects; with a single human it adds little. Savings +were measured once per case: treat them as indications, not as a guarantee. + ## How it fits together ```mermaid