Repository navigation
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·170 lines (158 loc) · 7.39 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·170 lines (158 loc) · 7.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
# Bootstrap ai-config: register skills.json and plugins.json for Antigravity,
# wire every agent's user-level config, and run machine-specific dotfile
# installers.
#
# Note: Global symlink installations for Claude Code, Codex, and Cursor have
# been removed. Claude Code and Cursor install this repo as a native plugin;
# Codex has no replacement install path for skills yet (see ai-config#2352);
# scripts/wire-user-config.py (run below) links ~/.codex/AGENTS.md so Codex
# at least loads the rules, and wires Claude Code's user settings, Gemini
# CLI's GEMINI.md and opencode's instructions the same way (ai-config#4206).
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GEMINI_DIR="${GEMINI_HOME:-$HOME/.gemini}"
GEMINI_CONFIG_DIR="${GEMINI_CONFIG_HOME:-$GEMINI_DIR/config}"
# Note: scripts/lib/link-one.sh (the symlink helper) is not sourced here.
# Nothing below uses it -- each dotfiles/*/install.sh that needs it sources
# its own copy with its own LINK_ONE_FIX_HINT, since a collision at
# e.g. ~/bin needs different advice than one under ~/.gemini would.
# --- Gemini CLI & Antigravity skills: register skills.json ---
if [ -d "$SCRIPT_DIR/skills" ]; then
printf '\n--- Gemini CLI & Antigravity skills ---\n'
mkdir -p "$GEMINI_CONFIG_DIR"
SKILLS_JSON="$GEMINI_CONFIG_DIR/skills.json"
if [ ! -f "$SKILLS_JSON" ]; then
ALIAS_PATTERNS=""
for _skill_dir in "$SCRIPT_DIR"/skills/*/; do
[ -f "$_skill_dir/SKILL.md" ] || continue
_skill_name=$(basename "$_skill_dir")
if head -8 "$_skill_dir/SKILL.md" | grep -qiE '^description: *"?([→]|->|Alias for\b)'; then
[ -z "$ALIAS_PATTERNS" ] || ALIAS_PATTERNS="$ALIAS_PATTERNS,
"
ALIAS_PATTERNS="$ALIAS_PATTERNS$(printf ' "^%s$"' "$_skill_name")"
fi
done
cat <<EOF > "$SKILLS_JSON"
{
"entries": [
{
"path": "$SCRIPT_DIR/skills",
"exclude": [
$ALIAS_PATTERNS
]
}
]
}
EOF
printf 'write skills.json (%s) -> %s/skills\n' "$SKILLS_JSON" "$SCRIPT_DIR"
elif grep -q "$SCRIPT_DIR/skills" "$SKILLS_JSON" 2>/dev/null; then
printf 'ok skills.json (%s/skills already registered)\n' "$SCRIPT_DIR"
elif grep -q "$GEMINI_DIR/skills" "$SKILLS_JSON" 2>/dev/null; then
printf 'skip skills.json (%s still names the old %s/skills symlink destination -- delete it and rerun to migrate to the checkout path)\n' "$SKILLS_JSON" "$GEMINI_DIR"
else
printf 'skip skills.json (%s exists but does not register %s/skills)\n' "$SKILLS_JSON" "$SCRIPT_DIR"
fi
fi
if [ -d "$SCRIPT_DIR/plugins/ai-config" ]; then
printf '\n--- Antigravity plugins ---\n'
mkdir -p "$GEMINI_CONFIG_DIR"
PLUGINS_JSON="$GEMINI_CONFIG_DIR/plugins.json"
PLUGIN_STAGING_DIR="$GEMINI_CONFIG_DIR/plugins/ai-config"
# Establish a staging directory so Antigravity runtime rewrites do not dirty
# the canonical git checkout.
if [ -L "$PLUGIN_STAGING_DIR" ]; then
rm -f "$PLUGIN_STAGING_DIR"
fi
mkdir -p "$PLUGIN_STAGING_DIR"
# Copy the canonical plugin manifest to the staging runtime directory.
cp -f "$SCRIPT_DIR/plugins/ai-config/plugin.json" "$PLUGIN_STAGING_DIR/plugin.json"
# hooks.json is RENDERED rather than copied. The canonical file stays in the
# portable POSIX form (`python3 ~/.gemini/...`), which Antigravity resolves
# on macOS and Linux and cmd.exe resolves on neither count. Copying it
# verbatim left the Windows install needing a hand repair, and that repair
# introduced the quoting that broke every run_command hook (https://github.com/Morrison-Lab/ai-config/issues/3091).
# The renderer refuses to emit a command carrying the quoting or the
# unresolved prefix that broke the install; it does not check that the
# interpreter it names exists, which check-agy-hook-commands.py does.
# A failure here leaves hooks.json missing on a first install, or leaves
# whatever the last successful render wrote on a re-run. It is warned
# about and not fatal, so the installer loop and the symlinks below still
# run. The checker and doctor.py report the missing case; neither
# compares a present manifest against the canonical one, so a stale but
# valid manifest is caught only by this warning.
python3 "$SCRIPT_DIR/scripts/render-agy-hooks.py" --output "$PLUGIN_STAGING_DIR/hooks.json" ||
printf 'warn %s exited %d\n' "scripts/render-agy-hooks.py" "$?"
# Symlink executable scripts and repository directories
ln -sfn "$SCRIPT_DIR/plugins/ai-config/claude-hook-adapter.py" "$PLUGIN_STAGING_DIR/claude-hook-adapter.py"
ln -sfn "$SCRIPT_DIR/plugins/ai-config/enforce-mwc-review-gate.py" "$PLUGIN_STAGING_DIR/enforce-mwc-review-gate.py"
ln -sfn "$SCRIPT_DIR/hooks" "$PLUGIN_STAGING_DIR/hooks"
ln -sfn "$SCRIPT_DIR/scripts" "$PLUGIN_STAGING_DIR/scripts"
ln -sfn "$SCRIPT_DIR/skills" "$PLUGIN_STAGING_DIR/skills"
ln -sfn "$SCRIPT_DIR/shared" "$PLUGIN_STAGING_DIR/shared"
if [ -d "$SCRIPT_DIR/plugins/ai-config/rules" ]; then
ln -sfn "$SCRIPT_DIR/plugins/ai-config/rules" "$PLUGIN_STAGING_DIR/rules"
fi
if [ ! -f "$PLUGINS_JSON" ]; then
cat <<EOF > "$PLUGINS_JSON"
{
"entries": [
{ "path": "$PLUGIN_STAGING_DIR" }
]
}
EOF
printf 'write plugins.json (%s) -> %s\n' "$PLUGINS_JSON" "$PLUGIN_STAGING_DIR"
elif grep -q "$PLUGIN_STAGING_DIR" "$PLUGINS_JSON" 2>/dev/null; then
printf 'ok plugins.json (%s already registered)\n' "$PLUGIN_STAGING_DIR"
elif grep -q "$SCRIPT_DIR/plugins/ai-config" "$PLUGINS_JSON" 2>/dev/null; then
python3 -c "
import json, sys
p = '$PLUGINS_JSON'
try:
with open(p, 'r', encoding='utf-8') as f:
d = json.load(f)
entries = d.get('entries', [])
updated = False
for e in entries:
if e.get('path') == '$SCRIPT_DIR/plugins/ai-config':
e['path'] = '$PLUGIN_STAGING_DIR'
updated = True
if not updated:
entries.append({'path': '$PLUGIN_STAGING_DIR'})
d['entries'] = entries
with open(p, 'w', encoding='utf-8') as f:
json.dump(d, f, indent=2)
except Exception:
sys.exit(1)
" 2>/dev/null && printf 'migrated plugins.json (%s checkout path -> %s staging path)\n' "$SCRIPT_DIR" "$PLUGIN_STAGING_DIR" || printf 'skip plugins.json (%s exists but could not migrate)\n' "$PLUGINS_JSON"
else
python3 -c "
import json, sys
p = '$PLUGINS_JSON'
try:
with open(p, 'r', encoding='utf-8') as f:
d = json.load(f)
entries = d.get('entries', [])
if not any(e.get('path') == '$PLUGIN_STAGING_DIR' for e in entries):
entries.append({'path': '$PLUGIN_STAGING_DIR'})
d['entries'] = entries
with open(p, 'w', encoding='utf-8') as f:
json.dump(d, f, indent=2)
except Exception:
sys.exit(1)
" 2>/dev/null && printf 'updated plugins.json (registered %s)\n' "$PLUGIN_STAGING_DIR" || printf 'skip plugins.json (%s exists)\n' "$PLUGINS_JSON"
fi
fi
# Wire ai-config into each agent's user-level config (Claude Code plugin,
# Codex and Gemini global instruction files, opencode instructions), so a
# session in ANY repo on this machine loads the rules (ai-config#4206).
printf '\n--- user-level agent config ---\n'
python3 "$SCRIPT_DIR/scripts/wire-user-config.py" ||
printf 'warn %s exited %d\n' "scripts/wire-user-config.py" "$?"
# --- Machine-specific dotfiles ---
shopt -s nullglob
for installer in "$SCRIPT_DIR"/dotfiles/*/install.sh; do
[ -x "$installer" ] || continue
printf '\n--- dotfiles/%s ---\n' "$(basename "$(dirname "$installer")")"
"$installer" || printf 'warn %s exited %d\n' "$installer" "$?"
done