Skip to content
123 changes: 95 additions & 28 deletions lane-start
Original file line number Diff line number Diff line change
Expand Up @@ -1082,30 +1082,87 @@ fi
# options at `--` like every other POSIX utility, and the step line this
# function produces — `repo repocase → repoCase` — is asserted on the macOS job,
# where an `ls` that refused `--` would leave it silent.
projects_dir_matches() { # <typed repo>
ls -- "$PROJECTS_ROOT" 2>/dev/null |
awk -v want="$1" 'BEGIN { w = tolower(want) } tolower($0) == w { print }' |
while IFS= read -r pdm_m; do
[ -d "$PROJECTS_ROOT/$pdm_m" ] && printf '%s\n' "$pdm_m"
# BEGIN GROUPED PROJECT DISCOVERY
# Self-contained installed commands share this block; a regression test checks
# byte equality. Rows carry name, logical path and physical deduplication key.
# Keep logical paths for estate recognition; never enter a repo, estate or
# supporting checkout collection while looking for grouping folders.
project_directory_walk() {
local base="$1" depth="$2" mode="$3" families="${4-}" child name physical boundary family_container
[ -d "$base" ] || return 0
for child in "$base"/*; do
[ -d "$child" ] || continue
name="${child##*/}"
# Per-lane register clones live beside any workspace as <workspace>-lanes.
case "$name" in workTrees|worktrees|laneWorkspaces|*-lanes|*-lane-registers) continue ;; esac
case "$child" in *$'\t'*|*$'\n'*) continue ;; esac
physical="$(cd -- "$child" 2>/dev/null && pwd -P)" || continue
case "${physical##*/}" in workTrees|worktrees|laneWorkspaces|*-lanes|*-lane-registers) continue ;; esac
case "$physical" in *$'\t'*|*$'\n'*) continue ;; esac
boundary=0; family_container=0
if [ -e "$child/$name/family.yaml" ] || [ -e "$physical/${physical##*/}/family.yaml" ]; then
family_container=1
fi
case $'\n'"$families"$'\n' in *$'\n'"$physical"$'\n'*) boundary=1 ;; esac
if [ -e "$child/.git" ] || [ -e "$child/project.yaml" ] ||
[ -e "$child/family.yaml" ] || [ "$family_container" -eq 1 ] ||
{ [ -f "$child/HEAD" ] && [ -d "$child/objects" ]; }; then
boundary=1
fi
if [ "$mode" = families ]; then
[ "$family_container" -eq 0 ] || printf '%s\n' "$physical"
elif [ "$depth" -eq 0 ] || [ "$boundary" -eq 1 ]; then
printf '%s\t%s\t%s\n' "$name" "$child" "$physical"
fi
if [ "$boundary" -eq 0 ] && [ "$depth" -lt 2 ]; then
project_directory_walk "$child" "$((depth + 1))" "$mode" "$families"
fi
done
}

project_directory_rows() {
local base="$1" families root
shift
[ "$#" -gt 0 ] || set -- "$base"
# Resolve boundaries across every configured root before emitting rows.
# A family alias in another root must also hide this container's members.
families="$(for root in "$@"; do project_directory_walk "$root" 0 families; done)"
project_directory_walk "$base" 0 rows "$families"
}
# END GROUPED PROJECT DISCOVERY

project_matches() {
local match_name match_dir git_dir common_dir canonical_name _logical_dir scope="${2:-grouped}"
while IFS=$'\t' read -r match_name _logical_dir match_dir; do
if [ "$scope" = flat ] && [ "${_logical_dir%/*}" != "$PROJECTS_ROOT" ]; then continue; fi
if [ -f "$match_dir/HEAD" ] && [ -d "$match_dir/objects" ]; then continue; fi
if [ -e "$match_dir/.git" ]; then
git_dir="$(git -C "$match_dir" rev-parse --git-dir 2>/dev/null)" || continue
common_dir="$(git -C "$match_dir" rev-parse --git-common-dir 2>/dev/null)" || continue
[ "$git_dir" = "$common_dir" ] || continue
[ -z "$(git -C "$match_dir" rev-parse --show-superproject-working-tree 2>/dev/null)" ] || continue
fi
canonical_name="${match_dir##*/}"
if [ "$(printf '%s' "$canonical_name" | tr '[:upper:]' '[:lower:]')" = "$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" ]; then
match_name="$canonical_name"
fi
printf '%s\t%s\n' "$match_name" "$match_dir"
done < <(project_directory_rows "$PROJECTS_ROOT" |
awk -F '\t' -v want="$1" 'BEGIN { w = tolower(want) } tolower($1) == w') | awk -F '\t' '!seen[$2]++'
}
projects_dir_matches() {
project_matches "$1" | cut -f1
}

if [ -n "$repo" ] && [ -d "$PROJECTS_ROOT" ]; then
repo_hits="$(projects_dir_matches "$repo" || :)"
repo_hit_n=0
if [ -n "$repo_hits" ]; then repo_hit_n="$(printf '%s\n' "$repo_hits" | grep -c . || :)"; fi
# THE REFUSAL IS FOR A RUN THAT HAS NO OTHER ANSWER, AND `--dir` IS THE OTHER
# ANSWER. Its own remedy names `--dir <path>`, so refusing a run that already
# passed one is refusing the fix it printed: `lane-start --dir /chosen repotwin
# 1` was rejected before the rung that honours the flag (Copilot round 1 on
# openRepoTools#41). With the checkout named, the ambiguity that is left is
# only about the lane-s NAME, which keeps the spelling that was typed and is
# then overruled by the register row-s a few lines below — so this SAYS what
# it did not resolve and carries on.
if [ "$repo_hit_n" -gt 1 ] && [ -z "$dir_override" ]; then
die "$PROJECTS_ROOT holds $repo_hit_n directories whose names differ only by case for '$repo': $(printf '%s\n' "$repo_hits" | tr '\n' ' ')— a lane name is ONE name under any case (Amendment 15(a)), so there is no spelling of '$repo' this can take without choosing which repository the lane is in. Name the checkout yourself with --dir <path>, or rename one of those directories." 2
fi
if [ "$repo_hit_n" -gt 1 ]; then
note "$PROJECTS_ROOT holds $repo_hit_n directories whose names differ only by case for '$repo': $(printf '%s\n' "$repo_hits" | tr '\n' ' ')— --dir has named the checkout, so this run is not ambiguous about WHERE the lane is. Its NAME keeps the '$repo' you typed, and the register row's own spelling wins over that below (Amendment 15(a))."
# A unique physical target supplies canonical spelling. Multiple targets
# wait for the explicit/recorded directory rungs: only a new default must
# refuse to choose among them.
if [ "$repo_hit_n" -gt 1 ] && [ -n "$dir_override" ]; then
note "multiple project targets match '$repo' — --dir has named the checkout, so the explicit directory remains authoritative"
fi
if [ "$repo_hit_n" = 1 ] && [ "$repo_hits" != "$repo" ]; then
step "repo $repo → $repo_hits (Amendment 15(a): the checkout's real directory name under $PROJECTS_ROOT)"
Expand Down Expand Up @@ -1370,10 +1427,25 @@ if [ -n "$DIR" ] && [ ! -d "$DIR" ]; then
die "no such directory: $DIR (from $DIR_SOURCE) — pass --dir <path> if this lane's checkout is somewhere else" 1
fi
if [ -z "$DIR" ]; then
if [ -d "$PROJECTS_ROOT/$repo" ]; then
DIR="$PROJECTS_ROOT/$repo"; DIR_SOURCE="the default \$PROJECTS_ROOT/<repo>"
ls_home=""; ls_rc=0
ls_home="$("$LANES_EDIT" resolve-home "$LANE" 2>/dev/null)" || ls_rc=$?
[ "$ls_rc" = 0 ] || ls_home=""
case "$ls_home" in */*) : ;; *) ls_home="" ;; esac
fi
if [ -z "$DIR" ]; then
# Keep the historical flat default ahead of home-based recovery. Grouped
# name discovery is a new-lane default only: an older home-only record must
# reach rungs 5/6, where origin proves the checkout and rejects imposters.
default_scope=grouped
[ -z "$ls_home" ] || default_scope=flat
default_matches="$(project_matches "$repo" "$default_scope")"
if [ -n "$default_matches" ]; then
default_count="$(printf '%s\n' "$default_matches" | wc -l | tr -d ' ')"
[ "$default_count" -eq 1 ] || die "$PROJECTS_ROOT holds $default_count directories whose names differ only by case or grouping for '$repo': $default_matches — Amendment 15(a) requires one default target; pass --dir <path>" 2
DIR="$(printf '%s\n' "$default_matches" | cut -f2-)"
DIR_SOURCE="grouped project lookup under \$PROJECTS_ROOT"
else
DIR_DEFAULT_TRIED="$PROJECTS_ROOT/$repo"
DIR_DEFAULT_TRIED="$PROJECTS_ROOT/$repo (including grouping folders)"
fi
fi

Expand Down Expand Up @@ -1414,12 +1486,6 @@ fi
#
# BOTH ARE SKIPPED ENTIRELY WHERE THE LANE HAS NO RECORDED HOME, because there
# is then nothing to prove a candidate against and a match would be a guess.
if [ -z "$DIR" ]; then
ls_home=""; ls_rc=0
ls_home="$("$LANES_EDIT" resolve-home "$LANE" 2>/dev/null)" || ls_rc=$?
[ "$ls_rc" = 0 ] || ls_home=""
case "$ls_home" in */*) : ;; *) ls_home="" ;; esac
fi
# Rung 5 — the legs.
if [ -z "$DIR" ] && [ -n "$ls_home" ]; then
for ls_m in "$PROJECTS_ROOT"/*/project.yaml "$PROJECTS_ROOT"/*/*/project.yaml; do
Expand Down Expand Up @@ -1483,6 +1549,7 @@ if [ -z "$DIR" ]; then
ls_where="$PROJECTS_ROOT/$repo"
[ -z "$DIR_DEFAULT_TRIED" ] || ls_where="$DIR_DEFAULT_TRIED"
ls_pos="${LANE##*-}"
ls_repo="${LANE%-*}"
if [ -n "$ls_home" ]; then
ls_tried="the default $ls_where, the project.yaml legs of $ls_home, and a checkout of $ls_home one or two levels under $PROJECTS_ROOT"
else
Expand All @@ -1491,7 +1558,7 @@ if [ -z "$DIR" ]; then
die "lane $LANE has no recorded checkout and none could be PROVED, so nothing was started.
Tried: $ls_tried.
Name it once, and every later start reads it back out of the lane's own log:
lane-start --dir <path> $repo $ls_pos
lane-start --dir <path> $ls_repo $ls_pos
Nothing here guesses. This script writes the lane HOME from the directory's
origin, and a directory that merely has the right name would re-home the lane
for every \`#n\` it writes afterwards (Amendment 11 clause (c); Evidence 7,
Expand Down
144 changes: 114 additions & 30 deletions park
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,85 @@ estate_walk_up() {
return 1
}

# BEGIN GROUPED PROJECT DISCOVERY
# Self-contained installed commands share this block; a regression test checks
# byte equality. Rows carry name, logical path and physical deduplication key.
# Keep logical paths for estate recognition; never enter a repo, estate or
# supporting checkout collection while looking for grouping folders.
project_directory_walk() {
local base="$1" depth="$2" mode="$3" families="${4-}" child name physical boundary family_container
[ -d "$base" ] || return 0
for child in "$base"/*; do
[ -d "$child" ] || continue
name="${child##*/}"
# Per-lane register clones live beside any workspace as <workspace>-lanes.
case "$name" in workTrees|worktrees|laneWorkspaces|*-lanes|*-lane-registers) continue ;; esac
case "$child" in *$'\t'*|*$'\n'*) continue ;; esac
physical="$(cd -- "$child" 2>/dev/null && pwd -P)" || continue
case "${physical##*/}" in workTrees|worktrees|laneWorkspaces|*-lanes|*-lane-registers) continue ;; esac
case "$physical" in *$'\t'*|*$'\n'*) continue ;; esac
boundary=0; family_container=0
if [ -e "$child/$name/family.yaml" ] || [ -e "$physical/${physical##*/}/family.yaml" ]; then
family_container=1
fi
case $'\n'"$families"$'\n' in *$'\n'"$physical"$'\n'*) boundary=1 ;; esac
if [ -e "$child/.git" ] || [ -e "$child/project.yaml" ] ||
[ -e "$child/family.yaml" ] || [ "$family_container" -eq 1 ] ||
{ [ -f "$child/HEAD" ] && [ -d "$child/objects" ]; }; then
Comment thread
brettheap marked this conversation as resolved.
Resolved
boundary=1
fi
if [ "$mode" = families ]; then
[ "$family_container" -eq 0 ] || printf '%s\n' "$physical"
elif [ "$depth" -eq 0 ] || [ "$boundary" -eq 1 ]; then
printf '%s\t%s\t%s\n' "$name" "$child" "$physical"
fi
if [ "$boundary" -eq 0 ] && [ "$depth" -lt 2 ]; then
project_directory_walk "$child" "$((depth + 1))" "$mode" "$families"
fi
done
}

project_directory_rows() {
local base="$1" families root
shift
[ "$#" -gt 0 ] || set -- "$base"
# Resolve boundaries across every configured root before emitting rows.
# A family alias in another root must also hide this container's members.
families="$(for root in "$@"; do project_directory_walk "$root" 0 families; done)"
project_directory_walk "$base" 0 rows "$families"
}
# END GROUPED PROJECT DISCOVERY

estate_directory_rows() {
local dir
for dir in "${PROJECTS_DIRS[@]}"; do
project_directory_rows "$dir" "${PROJECTS_DIRS[@]}"
done
}

# Validate logical family names before deduplicating their physical containers.
recognized_estate_rows() {
local name child physical
while IFS=$'\t' read -r name child physical; do
estate_here "$child" || continue
printf '%s\t%s\t%s\n' "$name" "$child" "$physical"
done < <(estate_directory_rows) | awk -F '\t' '!seen[$3]++'
}

estate_by_name() {
local want="$1" dir
local want="$1" dir name child physical hits candidate
is_safe_folder_name "$want" || return 1
for dir in "${PROJECTS_DIRS[@]}"; do
estate_here "$dir/$want" && return 0
hits="$(while IFS=$'\t' read -r name child physical; do
[ "$name" = "$want" ] || continue
if estate_here "$child"; then printf '%s\t%s\n' "$child" "$physical"; fi
done < <(project_directory_rows "$dir" "${PROJECTS_DIRS[@]}") | awk -F '\t' '!seen[$2]++ {print $1}')"
[ -n "$hits" ] || continue
if [ "$(printf '%s\n' "$hits" | wc -l | tr -d ' ')" -gt 1 ]; then
die "multiple estates named '$want' under $dir; stand in the intended estate and run $SELF_NAME without <Name>: $hits"
fi
candidate="$hits"
estate_here "$candidate" && return 0
done
return 1
}
Expand All @@ -410,18 +484,15 @@ estate_by_name() {
# a refusal to print: a person who typed the command in the wrong folder needs
# the names, not an instruction to go and look for them.
list_estates() {
local dir child
for dir in "${PROJECTS_DIRS[@]}"; do
[ -d "$dir" ] || continue
for child in "$dir"/*; do
local _grouped_name child _physical
while IFS=$'\t' read -r _grouped_name child _physical; do
[ -d "$child" ] || continue
if is_family_folder "$child"; then
printf ' family %-20s %s\n' "${child##*/}" "$child"
elif is_project_root "$child"; then
printf ' project %-20s %s\n' "${child##*/}" "$child"
fi
done
done
done < <(recognized_estate_rows)
}

estates_or_none() {
Expand Down Expand Up @@ -454,12 +525,12 @@ estates_or_none() {
# shellcheck disable=SC2329 # `park` never asks: it files the record, and
# never looks a holder up by it. The block is byte-identical by design.
family_folders_with_id() {
local want="$1" dir child prior dup
local want="$1" dir child prior dup _grouped_name _physical
local -a found=()
[ -n "$want" ] || return 0
for dir in "${PROJECTS_DIRS[@]}"; do
[ -d "$dir" ] || continue
for child in "$dir"/*; do
while IFS=$'\t' read -r _grouped_name child _physical; do
[ -d "$child" ] || continue
is_family_folder "$child" || continue
yaml_scalar "$child/${child##*/}/family.yaml" id || continue
Expand All @@ -471,7 +542,7 @@ family_folders_with_id() {
[ "$dup" -eq 0 ] || continue
found+=("$child")
printf '%s\n' "$child"
done
done < <(project_directory_rows "$dir" "${PROJECTS_DIRS[@]}")
done
}

Expand Down Expand Up @@ -522,28 +593,42 @@ repo_slug_of() {
printf '%s/%s\n' "$owner" "$name"
}

# The clone under the projects directory whose `origin` IS that repository -
# ruling 1. Two levels deep, because the estates this standard places are
# `<projects>/<Project>` and `<projects>/<Family>/<Project>`.
# Match origins only in discovered development checkouts, including a
# family's direct sibling checkouts. Never descend into pinned Git members.
clone_with_origin() {
local want dir candidate origin found
local want candidate origin found hits child name physical git_dir common_dir git_physical rank
want="$(lower "$1")"
for dir in "${PROJECTS_DIRS[@]}"; do
[ -d "$dir" ] || continue
for candidate in "$dir"/*/ "$dir"/*/*/; do
candidate="${candidate%/}"
hits="$(while IFS=$'\t' read -r name child physical; do
for candidate in "$child" "$child"/*; do
if [ "$candidate" != "$child" ]; then
is_family_folder "$child" || continue
fi
case "$candidate" in *$'\t'*|*$'\n'*) continue ;; esac
[ -e "$candidate/.git" ] || continue
git_dir="$(git -C "$candidate" rev-parse --git-dir 2>/dev/null)" || continue
common_dir="$(git -C "$candidate" rev-parse --git-common-dir 2>/dev/null)" || continue
[ "$git_dir" = "$common_dir" ] || continue
[ -z "$(git -C "$candidate" rev-parse --show-superproject-working-tree 2>/dev/null)" ] || continue
origin="$(git -C "$candidate" remote get-url origin 2>/dev/null || true)"
[ -n "$origin" ] || continue
found="$(repo_slug_of "$origin" || true)"
[ -n "$found" ] || continue
if [ "$(lower "$found")" = "$want" ]; then
printf '%s\n' "$candidate"
return 0
git_physical="$(cd -- "$candidate" && pwd -P)" || continue
rank=1
estate_walk_up "$candidate" && rank=0
printf '%s\t%s\t%s\n' "$git_physical" "$rank" "$candidate"
fi
done
done
return 1
done < <(estate_directory_rows) |
LC_ALL=C sort -s -t $'\t' -k1,1 -k2,2n |
awk -F '\t' '!seen[$1]++ {print $3}')"
[ -n "$hits" ] || return 1
if [ "$(printf '%s\n' "$hits" | wc -l | tr -d ' ')" -gt 1 ]; then
printf 'multiple development checkouts have origin %s; stand in the intended checkout: %s\n' "$1" "$hits" >&2
return 2
fi
printf '%s\n' "$hits"
}

# The family's members, by the same ` - project: <Project>` row `family.py`
Expand Down Expand Up @@ -931,16 +1016,13 @@ run_one_estate() {
# `members/<X>` copy (three levels down) and a linked feature worktree
# (rejected by `is_project_root` itself).
all_estate_dirs() {
local dir child
for dir in "${PROJECTS_DIRS[@]}"; do
[ -d "$dir" ] || continue
for child in "$dir"/*; do
local _grouped_name child _physical
while IFS=$'\t' read -r _grouped_name child _physical; do
[ -d "$child" ] || continue
if is_family_folder "$child" || is_project_root "$child"; then
printf '%s\t%s\n' "${child##*/}" "$child"
fi
done
done | LC_ALL=C sort -t $'\t' -k1,1
done < <(recognized_estate_rows) | LC_ALL=C sort -t $'\t' -k1,1
}

# Does this root carry the Speckit git overlay its own `make park` requires?
Expand Down Expand Up @@ -1243,7 +1325,9 @@ elif [ -n "$REPO_SLUG" ]; then
url spelling of one (https://…/<owner>/<name>.git, git@host:<owner>/<name>).
A family's members may live in another organisation, so there is no owner
to assume, and a path on disk has none to read."
MATCH="$(clone_with_origin "$REPO_SLUG" || true)"
LOOKUP_RC=0
MATCH="$(clone_with_origin "$REPO_SLUG")" || LOOKUP_RC=$?
[ "$LOOKUP_RC" -ne 2 ] || die "ambiguous repository lookup; no checkout was selected"
[ -n "$MATCH" ] || die "no clone under your projects directory has origin $REPO_SLUG.
\`--repo\` names a clone you ALREADY HAVE; it never clones one (RULING
2026-09-09 ruling 1). Get it, or bring the whole estate back from its
Expand Down
Loading
Loading