feat(agents-init): honor agents-init.disabled / .agents-disabled, add --enable

This commit is contained in:
2026-09-30 16:52:01 -04:00
parent a90b1ad923
commit 6ff5546f09
2 changed files with 88 additions and 5 deletions
+44 -5
View File
@@ -11,8 +11,8 @@
# self-limiting(rm,mkdir,grep), bypasses-shadow(mv), manual-section(16-agent-tooling)
#
# SYNOPSIS
# agents-init [-a | --agents] [-p | --plugins] [-v | --verbose]
# [-q | --quiet] [-s | --silent] [-h | --help]
# agents-init [-a | --agents] [-p | --plugins] [-e | --enable]
# [-v | --verbose] [-q | --quiet] [-s | --silent] [-h | --help]
#
# DESCRIPTION
# Scaffolds an AGENTS/ sub-repository inside a project directory. Creates
@@ -35,6 +35,13 @@
# no-op, so running an agent CLI in an arbitrary directory does not
# create a repository there.
#
# A project marked disabled is skipped entirely. agents-cleanup sets the
# per-clone git config key agents-init.disabled; a .agents-disabled file
# in the project root, which a team may commit, has the same effect.
# Either one turns every wrapper launch into a silent no-op there.
# --enable clears the git key and scaffolds; the file has to be deleted
# by hand, because it is a decision shared with every clone.
#
# File layout after setup:
# AGENTS/AGENTS.md canonical root agent spec (real file)
# AGENTS/<subdir>/AGENTS.md canonical spec for any subdir with its own
@@ -95,6 +102,8 @@
# -a, --agents Set up AGENTS/ repo + AGENTS.md symlinks (root and every
# discovered subdirectory) only
# -p, --plugins Set up AGENTS/ repo + plans/specs/devlogs dirs + docs/ symlinks only
# -e, --enable Clear the git key agents-cleanup set, then scaffold as
# normal (refused while .agents-disabled exists)
# -v, --verbose Print all per-step output (default)
# -q, --quiet Print one summary line only if changes were made
# -s, --silent Suppress all output; errors only (standard UNIX convention)
@@ -103,7 +112,8 @@
# EXIT STATUS
# 0 Setup completed successfully
# 1 Fatal error (git init failed, move failed, the AGENTS/ commit was
# rejected, or an unresolved rebase blocked it)
# rejected, or an unresolved rebase blocked it), or --enable refused
# because .agents-disabled exists
#
# EXAMPLE
# agents-init
@@ -122,11 +132,11 @@
function agents-init --description 'scaffold AGENTS/ sub-repo with agent spec files and plugin dirs'
__fish_palette
argparse h/help a/agents p/plugins v/verbose q/quiet s/silent -- $argv
argparse h/help a/agents p/plugins e/enable v/verbose q/quiet s/silent -- $argv
or return 1
if set -q _flag_help
echo "$c_head""Usage:$c_reset $c_cmd""agents-init$c_reset $c_flag""[-a] [-p] [-v] [-q] [-s] [-h | --help]$c_reset"
echo "$c_head""Usage:$c_reset $c_cmd""agents-init$c_reset $c_flag""[-a] [-p] [-e] [-v] [-q] [-s] [-h | --help]$c_reset"
echo
echo " Scaffold an AGENTS/ sub-repository for tracking agent specifications."
echo
@@ -134,6 +144,7 @@ function agents-init --description 'scaffold AGENTS/ sub-repo with agent spec fi
echo " $c_flag-h$c_reset, $c_flag--help$c_reset Show this help message"
echo " $c_flag-a$c_reset, $c_flag--agents$c_reset Set up AGENTS.md symlinks only"
echo " $c_flag-p$c_reset, $c_flag--plugins$c_reset Set up plans/specs/devlogs dirs and docs/ symlinks only"
echo " $c_flag-e$c_reset, $c_flag--enable$c_reset Re-enable a project agents-cleanup disabled"
echo " $c_flag-v$c_reset, $c_flag--verbose$c_reset Print all per-step output (default)"
echo " $c_flag-q$c_reset, $c_flag--quiet$c_reset Print one summary line only if changes were made"
echo " $c_flag-s$c_reset, $c_flag--silent$c_reset Suppress all output; only errors are printed"
@@ -179,6 +190,34 @@ function agents-init --description 'scaffold AGENTS/ sub-repo with agent spec fi
end
end
# ─────────────────────────── Opt-out marker ───────────────────────────
# agents-cleanup marks a project it has undone so launches stop
# re-scaffolding it: a per-clone git config key, or a .agents-disabled
# file a team may commit. The file is a shared decision, so --enable
# refuses rather than silently overriding it.
set -l marker_file "$root/.agents-disabled"
set -l key_set 0
if test $in_git -eq 1
set -l key (git -C "$root" config --type=bool --get agents-init.disabled 2>/dev/null)
test "$key" = true; and set key_set 1
end
if set -q _flag_enable
if test -e "$marker_file"
echo "$c_err""Error: .agents-disabled disables agents-init for every clone; delete it (and commit the deletion) to re-enable$c_reset" >&2
return 1
end
if test $in_git -eq 1; and git -C "$root" config --local --get agents-init.disabled >/dev/null 2>&1
git -C "$root" config --local --unset agents-init.disabled
test $verbose -eq 1; and echo "$c_ok→ Re-enabled agents-init (unset git config agents-init.disabled)$c_reset"
end
else if test -e "$marker_file"
test $verbose -eq 1; and echo "$c_dim→ agents-init is disabled here by .agents-disabled; delete that file to re-enable$c_reset"
return 0
else if test $key_set -eq 1
test $verbose -eq 1; and echo "$c_dim→ agents-init is disabled here (git config agents-init.disabled); run agents-init --enable to re-enable$c_reset"
return 0
end
set -l agents_dir "$root/AGENTS"
set -l plugins_dir "$agents_dir/plugins"
+44
View File
@@ -477,5 +477,49 @@ ln -s x $pf/nested/link
check "find: only the unpruned symlink" $pf/src/link (_agents_init_find $pf -type l -print | string join ,)
check "find: no root -> status 1" 1 (_agents_init_find ""; echo $status)
echo ""
echo "== agents-init: opt-out marker =="
set -l m1 (new_repo)
git -C $m1 config agents-init.disabled true
pushd $m1 >/dev/null
set -l mrc1 (agents-init --silent 2>/dev/null; echo $status)
popd >/dev/null
check "git key: exits 0" 0 "$mrc1"
check "git key: nothing scaffolded" false (test -e $m1/AGENTS -o -L $m1/AGENTS.md; and echo true; or echo false)
set -l m2 (new_repo)
touch $m2/.agents-disabled
pushd $m2 >/dev/null
set -l mrc2 (agents-init --silent 2>/dev/null; echo $status)
popd >/dev/null
check "marker file: exits 0" 0 "$mrc2"
check "marker file: nothing scaffolded" false (test -e $m2/AGENTS -o -L $m2/AGENTS.md; and echo true; or echo false)
set -l m3 (new_repo)
git -C $m3 config agents-init.disabled true
pushd $m3 >/dev/null
set -l mrc3 (agents-init --enable --silent 2>/dev/null; echo $status)
popd >/dev/null
check "--enable: exits 0" 0 "$mrc3"
check "--enable: git key unset" 1 (git -C $m3 config --get agents-init.disabled >/dev/null; echo $status)
check "--enable: scaffold created" AGENTS/AGENTS.md (readlink $m3/AGENTS.md)
set -l m4 (new_repo)
touch $m4/.agents-disabled
pushd $m4 >/dev/null
set -l mrc4 (agents-init --enable --silent 2>/dev/null; echo $status)
popd >/dev/null
check "--enable with marker file: exits 1" 1 "$mrc4"
check "--enable with marker file: nothing scaffolded" false (test -e $m4/AGENTS -o -L $m4/AGENTS.md; and echo true; or echo false)
check "--enable with marker file: file kept" true (test -e $m4/.agents-disabled; and echo true; or echo false)
set -l m5 (new_repo)
git -C $m5 config agents-init.disabled true
pushd $m5 >/dev/null
set -l mout5 (agents-init 2>/dev/null)
popd >/dev/null
check "git key, verbose: note names the marker" true (string match -q -- '*agents-init.disabled*' "$mout5"; and echo true; or echo false)
cleanup
report