refactor(agents-init): use the shared repo helpers

Renames _agents_init_install_tools to _agents_repo_install_tools now that
the vault shares it, collapses the two duplicated root-symlink blocks into
one loop, and routes the auto-commit through _agents_repo_sync so a failed
rebase can no longer be committed as conflict markers.
This commit is contained in:
2026-09-03 18:56:45 -04:00
parent b5d2c9ba87
commit b0585d00ad
2 changed files with 42 additions and 57 deletions
@@ -2,31 +2,32 @@
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
# SYNOPSIS # SYNOPSIS
# _agents_init_install_tools <agents_dir> # _agents_repo_install_tools <repo_dir>
# #
# DESCRIPTION # DESCRIPTION
# Copies the canonical version-bump script and git hook shims from # Copies the canonical version-bump script and git hook shims from
# fish-config's scripts/agents-tools/ into <agents_dir>/.agents-tools/, # fish-config's scripts/agents-tools/ into <repo_dir>/.agents-tools/,
# refreshing them when the shipped agents-tools-version: marker is newer # refreshing them when the shipped agents-tools-version: marker is newer
# than the installed copy. Files are made executable. Idempotent: prints # than the installed copy. Files are made executable. Idempotent: prints
# nothing when the installed tooling is already current, or a short summary # nothing when the installed tooling is already current, or a short summary
# line when it installed or updated the tooling. # line when it installed or updated the tooling. Shared by agents-init and
# agents-vault.
# #
# ARGUMENTS # ARGUMENTS
# agents_dir Absolute path to the AGENTS/ sub-repo root # repo_dir Absolute path to the git repo root to install tooling into
# #
# EXIT STATUS # EXIT STATUS
# 0 Tooling is current or was installed/updated successfully # 0 Tooling is current or was installed/updated successfully
# 1 Canonical source missing or a copy failed # 1 Canonical source missing or a copy failed
# #
# EXAMPLE # EXAMPLE
# set -l msg (_agents_init_install_tools /path/to/AGENTS) # set -l msg (_agents_repo_install_tools /path/to/AGENTS)
# test -n "$msg"; and echo $msg # test -n "$msg"; and echo $msg
function _agents_init_install_tools --argument-names agents_dir function _agents_repo_install_tools --argument-names repo_dir
test -n "$agents_dir"; or return 1 test -n "$repo_dir"; or return 1
set -l src (path resolve (status dirname)/../scripts/agents-tools) set -l src (path resolve (status dirname)/../scripts/agents-tools)
test -f "$src/version-bump"; or return 1 test -f "$src/version-bump"; or return 1
set -l dest "$agents_dir/.agents-tools" set -l dest "$repo_dir/.agents-tools"
set -l want (command grep -m1 -oE 'agents-tools-version: *[0-9]+' "$src/version-bump" 2>/dev/null | command grep -oE '[0-9]+$') set -l want (command grep -m1 -oE 'agents-tools-version: *[0-9]+' "$src/version-bump" 2>/dev/null | command grep -oE '[0-9]+$')
set -l have "" set -l have ""
+33 -49
View File
@@ -4,6 +4,9 @@
# CATEGORY # CATEGORY
# 12-ai-and-developer-tools # 12-ai-and-developer-tools
# #
# DEPENDENCIES
# _agents_repo_install_tools, _agents_repo_sync, _agents_init_ensure_gitignore
#
# SYNOPSIS # SYNOPSIS
# agents-init [-a | --agents] [-p | --plugins] [-v | --verbose] # agents-init [-a | --agents] [-p | --plugins] [-v | --verbose]
# [-q | --quiet] [-s | --silent] [-h | --help] # [-q | --quiet] [-s | --silent] [-h | --help]
@@ -165,7 +168,7 @@ function agents-init --description 'scaffold AGENTS/ sub-repo with agent spec fi
test $verbose -eq 1; and echo "$c_ok→ Created AGENTS/.version (1.0.0)$c_reset" test $verbose -eq 1; and echo "$c_ok→ Created AGENTS/.version (1.0.0)$c_reset"
end end
set -l _tools (_agents_init_install_tools "$agents_dir") set -l _tools (_agents_repo_install_tools "$agents_dir")
if test -n "$_tools" if test -n "$_tools"
set changed 1 set changed 1
test $verbose -eq 1; and echo "$c_ok$_tools$c_reset" test $verbose -eq 1; and echo "$c_ok$_tools$c_reset"
@@ -259,38 +262,26 @@ function agents-init --description 'scaffold AGENTS/ sub-repo with agent spec fi
test $verbose -eq 1; and echo "$c_ok→ Linked AGENTS/CLAUDE.md → AGENTS/AGENTS.md$c_reset" test $verbose -eq 1; and echo "$c_ok→ Linked AGENTS/CLAUDE.md → AGENTS/AGENTS.md$c_reset"
end end
# ── Root symlink: AGENTS.md → AGENTS/AGENTS.md ─────────────────────── # Root symlinks point at files, not directories, so they cannot use
set -l _need_link 0 # _agents_repo_ensure_symlink (which is directory-only by design).
if not test -L "$root/AGENTS.md" for pair in "AGENTS.md:AGENTS/AGENTS.md" "CLAUDE.md:AGENTS/CLAUDE.md"
set _need_link 1 set -l name (string split -f1 ':' -- $pair)
else if test (readlink "$root/AGENTS.md") != AGENTS/AGENTS.md set -l want (string split -f2 ':' -- $pair)
rm -f "$root/AGENTS.md" set -l need 0
set _need_link 1 if not test -L "$root/$name"
end set need 1
if test $_need_link -eq 1 else if test (readlink "$root/$name") != "$want"
if not ln -s AGENTS/AGENTS.md "$root/AGENTS.md" rm -f "$root/$name"
echo "$c_err""Error: could not create AGENTS.md symlink$c_reset" >&2 set need 1
return 1
end end
set changed 1 if test $need -eq 1
test $verbose -eq 1; and echo "$c_ok→ Linked AGENTS.md → AGENTS/AGENTS.md$c_reset" if not ln -s "$want" "$root/$name"
end echo "$c_err""Error: could not create $name symlink$c_reset" >&2
return 1
# ── Root symlink: CLAUDE.md → AGENTS/CLAUDE.md ─────────────────────── end
set -l _need_link 0 set changed 1
if not test -L "$root/CLAUDE.md" test $verbose -eq 1; and echo "$c_ok→ Linked $name$want$c_reset"
set _need_link 1
else if test (readlink "$root/CLAUDE.md") != AGENTS/CLAUDE.md
rm -f "$root/CLAUDE.md"
set _need_link 1
end
if test $_need_link -eq 1
if not ln -s AGENTS/CLAUDE.md "$root/CLAUDE.md"
echo "$c_err""Error: could not create CLAUDE.md symlink$c_reset" >&2
return 1
end end
set changed 1
test $verbose -eq 1; and echo "$c_ok→ Linked CLAUDE.md → AGENTS/CLAUDE.md$c_reset"
end end
# ── .gitignore ──────────────────────────────────────────────────────── # ── .gitignore ────────────────────────────────────────────────────────
@@ -461,24 +452,17 @@ function agents-init --description 'scaffold AGENTS/ sub-repo with agent spec fi
end end
# ──────────────────────── Auto-commit AGENTS/ ──────────────────────────── # ──────────────────────── Auto-commit AGENTS/ ────────────────────────────
# Pull first when an upstream is configured so the local .version reflects # Pulls first when an upstream is configured (no-op for local-only repos)
# any remote bumps before we add to it (no-op for local-only repos). # and refuses to commit a failed rebase's conflict markers.
if git -C "$agents_dir" rev-parse --abbrev-ref --symbolic-full-name '@{u}' >/dev/null 2>&1 set -l msg "chore: sync AGENTS repository"
git -C "$agents_dir" pull --rebase --autostash -q 2>/dev/null test $did_init -eq 1; and set msg "chore: initialize AGENTS repository"
end set -l sync_out (_agents_repo_sync "$agents_dir" "$msg")
git -C "$agents_dir" add -A 2>/dev/null set -l sync_rc $status
set -l status_out (git -C "$agents_dir" status --porcelain 2>/dev/null) if test $sync_rc -eq 2
if test -n "$status_out" echo "$c_warn→ AGENTS/ has an unresolved rebase conflict; nothing committed$c_reset" >&2
set -l msg "chore: sync AGENTS repository" else if test -n "$sync_out"
test $did_init -eq 1; and set msg "chore: initialize AGENTS repository" set changed 1
if git -C "$agents_dir" -c commit.gpgsign=false commit -q -m "$msg" 2>/dev/null test $verbose -eq 1; and echo "$c_ok$sync_out$c_reset"
set changed 1
if test $verbose -eq 1
set -l sha (git -C "$agents_dir" rev-parse --short HEAD 2>/dev/null)
set -l realmsg (git -C "$agents_dir" log -1 --pretty=%s 2>/dev/null)
echo "$c_ok→ Committed AGENTS/ ($sha) $c_dim$realmsg$c_reset"
end
end
end end
# Quiet summary: one line at the end, only if something actually changed # Quiet summary: one line at the end, only if something actually changed