fix(kyberforge): stop dotfiles-repo $HOME from shadowing user scope
new-agent.sh's walk-up checked for a .git directory before checking whether it had reached $HOME, so a dotfiles-managed home directory (e.g. `~/.git` from yadm or a bare-repo checkout) made `new-agent.sh <name> ~` silently resolve to project scope instead of user scope, writing .github/agents/ instead of ~/.copilot/agents/. Check the $HOME boundary before the .git check so it can no longer be shadowed. Found via post-implementation review of issue #89.
This commit is contained in:
@@ -91,6 +91,9 @@ ROOT="$(cd "$ROOT" && pwd)"
|
|||||||
# (plugin/APM scope) — stop and return it.
|
# (plugin/APM scope) — stop and return it.
|
||||||
# - an apm.yml with no `type:` field is a marketplace-only manifest — skip
|
# - an apm.yml with no `type:` field is a marketplace-only manifest — skip
|
||||||
# it, keep walking up.
|
# it, keep walking up.
|
||||||
|
# - reaching $HOME marks the user-scope boundary — stop, even if $HOME is
|
||||||
|
# itself a .git-tracked dotfiles directory (checked before the .git test
|
||||||
|
# below, so a dotfiles repo at $HOME can't shadow user scope).
|
||||||
# - a .git directory marks the project-scope boundary — stop.
|
# - a .git directory marks the project-scope boundary — stop.
|
||||||
# - filesystem root reached with neither found — boundary-reached.
|
# - filesystem root reached with neither found — boundary-reached.
|
||||||
find_package_root() {
|
find_package_root() {
|
||||||
@@ -101,6 +104,11 @@ find_package_root() {
|
|||||||
echo "$current"
|
echo "$current"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
if [[ "$current" == "$HOME" ]]; then
|
||||||
|
echo "user"
|
||||||
|
echo "$current"
|
||||||
|
return
|
||||||
|
fi
|
||||||
if [[ -d "$current/.git" ]]; then
|
if [[ -d "$current/.git" ]]; then
|
||||||
echo "project"
|
echo "project"
|
||||||
echo "$current"
|
echo "$current"
|
||||||
@@ -127,17 +135,16 @@ case "$WALK_KIND" in
|
|||||||
SCOPE="plugin"
|
SCOPE="plugin"
|
||||||
PACKAGE_ROOT="$WALK_ROOT"
|
PACKAGE_ROOT="$WALK_ROOT"
|
||||||
;;
|
;;
|
||||||
|
user)
|
||||||
|
SCOPE="user"
|
||||||
|
;;
|
||||||
project)
|
project)
|
||||||
SCOPE="project"
|
SCOPE="project"
|
||||||
;;
|
;;
|
||||||
boundary-reached)
|
boundary-reached)
|
||||||
if [[ "$ROOT" == "$HOME" ]]; then
|
# Default fallback, same as the pre-walk-up script: no plugin/APM
|
||||||
SCOPE="user"
|
# marker, no $HOME boundary, and no .git means project scope.
|
||||||
else
|
SCOPE="project"
|
||||||
# Default fallback, same as the pre-walk-up script: no plugin/APM
|
|
||||||
# marker and not exactly $HOME means project scope.
|
|
||||||
SCOPE="project"
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|||||||
@@ -211,6 +211,17 @@ teardown() {
|
|||||||
rm -rf "$FAKE_HOME"
|
rm -rf "$FAKE_HOME"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "user scope: \$HOME being a dotfiles .git repo does not shadow user scope" {
|
||||||
|
FAKE_HOME="$(mktemp -d)"
|
||||||
|
mkdir "$FAKE_HOME/.git"
|
||||||
|
run env HOME="$FAKE_HOME" bash "$SCRIPT" my-agent "~"
|
||||||
|
assert_success
|
||||||
|
assert [ -f "$FAKE_HOME/.claude/agents/my-agent.md" ]
|
||||||
|
assert [ -f "$FAKE_HOME/.copilot/agents/my-agent.agent.md" ]
|
||||||
|
refute [ -d "$FAKE_HOME/.github" ]
|
||||||
|
rm -rf "$FAKE_HOME"
|
||||||
|
}
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Name validation
|
# Name validation
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user