forked from eferro/augmentedcode-configuration
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-symlinks.sh
More file actions
executable file
·479 lines (426 loc) · 15.8 KB
/
setup-symlinks.sh
File metadata and controls
executable file
·479 lines (426 loc) · 15.8 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
#!/bin/bash
# Setup and Validate Symlinks for AI Tool Configuration
# Establishes ~/.cursor/, ~/.claude/, and other AI tool config as symlinks to this repo
set -e
REPO_DIR="$HOME/saski/augmentedcode-configuration"
# Dev/AI tools under ~ that get a direct "$HOME/$tool/skills" symlink.
# Cursor and Codex are handled separately due tool-specific directory layouts.
# Add or remove dot-dir names to cover any dev tool config (e.g. .copilot, .kiro).
TOOLS_WITH_SKILLS=".antigravity .gemini .langflow"
backup_and_remove_if_not_symlink() {
local path="$1"
local label="$2"
if [ -e "$path" ] && [ ! -L "$path" ]; then
local backup_path="${path}.backup.$(date +%Y%m%d-%H%M%S)"
mv "$path" "$backup_path"
echo "⚠️ Backed up existing $label to $backup_path"
fi
}
usage() {
cat << EOF
Usage: $(basename $0) [command]
Commands:
setup - Create all symlinks (first-time setup or repair)
validate - Verify all symlinks are correct
status - Show git status of config changes
commit - Stage, commit, and push config changes
help - Show this help message
Examples:
$(basename $0) setup # Initial setup on new machine
$(basename $0) validate # Check symlinks are intact
$(basename $0) commit # Commit and push config changes
EOF
exit 1
}
# Verify we're in the right place
check_environment() {
if [ ! -d "$REPO_DIR" ]; then
echo "❌ Repository not found at $REPO_DIR"
exit 1
fi
if [ ! -d "$REPO_DIR/.cursor" ]; then
echo "❌ .cursor directory not found in repo"
exit 1
fi
if [ ! -f "$REPO_DIR/.agents/mcp.json" ]; then
echo "❌ .agents/mcp.json not found in repo"
exit 1
fi
if [ ! -f "$REPO_DIR/.cursor/cli-config.json" ]; then
echo "❌ .cursor/cli-config.json not found in repo"
exit 1
fi
if [ ! -f "$REPO_DIR/.codex/config.toml" ]; then
echo "❌ .codex/config.toml not found in repo"
exit 1
fi
if [ ! -f "$REPO_DIR/.agents/rules/codex-default.rules" ]; then
echo "❌ .agents/rules/codex-default.rules not found in repo"
exit 1
fi
if [ ! -f "$REPO_DIR/GEMINI.md" ]; then
echo "❌ GEMINI.md not found in repo"
exit 1
fi
}
# Create all symlinks
setup_symlinks() {
echo "🔗 Setting up symlinks..."
# Backup existing if not symlinks
if [ -d ~/.cursor/rules ] && [ ! -L ~/.cursor/rules ]; then
echo "⚠️ Found existing ~/.cursor/rules (not a symlink)"
echo " Create backup with: ./backup-cursor-config.sh"
exit 1
fi
# Ensure managed locations can be replaced with symlinks on macOS
# where ln -sfn does not replace existing directories in-place.
backup_and_remove_if_not_symlink "$HOME/.cursor/skills-cursor" "~/.cursor/skills-cursor"
backup_and_remove_if_not_symlink "$HOME/.claude" "~/.claude"
# Create .cursor symlinks (skills → canonical .agents/skills)
mkdir -p ~/.cursor
ln -sfn "$REPO_DIR/.cursor/rules" ~/.cursor/rules
ln -sfn "$REPO_DIR/.cursor/commands" ~/.cursor/commands
ln -sfn "$REPO_DIR/.agents/skills" ~/.cursor/skills
ln -sfn "$REPO_DIR/.cursor/skills-cursor" ~/.cursor/skills-cursor
ln -sfn "$REPO_DIR/.agents" ~/.cursor/.agents
ln -sfn "$REPO_DIR/.agents/mcp.json" ~/.cursor/mcp.json
ln -sfn "$REPO_DIR/.cursor/cli-config.json" ~/.cursor/cli-config.json
# Codex keeps local system skills under ~/.codex/skills/.system.
# Link shared skills and shared rules into ~/.codex.
mkdir -p "$HOME/.codex/skills" "$HOME/.codex/rules"
ln -sfn "$REPO_DIR/.agents/skills" "$HOME/.codex/skills/skills"
ln -sfn "$REPO_DIR/.codex/config.toml" "$HOME/.codex/config.toml"
ln -sfn "$REPO_DIR/.agents/rules/codex-default.rules" "$HOME/.codex/rules/default.rules"
ln -sfn "$REPO_DIR/AGENTS.md" "$HOME/.codex/AGENTS.md"
# Other dev/AI tools: point skills at canonical .agents/skills
for tool in $TOOLS_WITH_SKILLS; do
mkdir -p "$HOME/$tool"
ln -sfn "$REPO_DIR/.agents/skills" "$HOME/$tool/skills"
done
# Gemini: use shared MCP config, commands, and workflows from canonical .agents path.
mkdir -p "$HOME/.gemini/antigravity"
ln -sfn "$REPO_DIR/.agents/mcp.json" "$HOME/.gemini/antigravity/mcp_config.json"
ln -sfn "$REPO_DIR/GEMINI.md" "$HOME/.gemini/GEMINI.md"
ln -sfn "$REPO_DIR/.agents/workflows" "$HOME/.gemini/antigravity/workflows"
ln -sfn "$REPO_DIR/.agents/commands" "$HOME/.gemini/antigravity/commands"
# Home-level .agents should always resolve to canonical repo .agents
# so there is no divergent local skill source.
if [ -d "$HOME/.agents" ] && [ ! -L "$HOME/.agents" ]; then
echo "⚠️ Found existing ~/.agents directory (not a symlink)"
echo " Please move it to a backup location, then rerun setup."
exit 1
fi
ln -sfn "$REPO_DIR/.agents" "$HOME/.agents"
# Create .claude symlink
ln -sfn "$REPO_DIR/.claude" ~/.claude
# Create root-level config symlinks
ln -sfn "$REPO_DIR/CLAUDE.md" ~/CLAUDE.md
ln -sfn "$REPO_DIR/AGENTS.md" ~/AGENTS.md
ln -sfn "$REPO_DIR/GEMINI.md" ~/GEMINI.md
echo "✅ Symlinks created"
}
# Validate all symlinks
validate_symlinks() {
echo "🔍 Validating symlinks..."
local errors=0
# Check .cursor symlinks
for link in rules commands skills skills-cursor .agents; do
local path="$HOME/.cursor/$link"
if [ ! -L "$path" ]; then
echo "❌ $path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$path" ]; then
echo "❌ $path is a broken symlink"
errors=$((errors + 1))
else
local target
target=$(readlink "$path")
if [ "$link" = "skills" ] && [[ "$target" != *".agents/skills" ]]; then
echo "❌ $path should point to .agents/skills, got: $target"
errors=$((errors + 1))
else
echo "✓ ~/.cursor/$link → $target"
fi
fi
done
# Check Cursor managed config files
for file in cli-config.json; do
local path="$HOME/.cursor/$file"
if [ ! -L "$path" ]; then
echo "❌ $path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$path" ]; then
echo "❌ $path is a broken symlink"
errors=$((errors + 1))
else
local target
target=$(readlink "$path")
if [[ "$target" != *".cursor/$file" ]]; then
echo "❌ $path should point to repo .cursor/$file, got: $target"
errors=$((errors + 1))
else
echo "✓ $path → $target"
fi
fi
done
# Check Cursor shared MCP config symlink
local cursor_mcp_path="$HOME/.cursor/mcp.json"
if [ ! -L "$cursor_mcp_path" ]; then
echo "❌ $cursor_mcp_path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$cursor_mcp_path" ]; then
echo "❌ $cursor_mcp_path is a broken symlink"
errors=$((errors + 1))
else
local cursor_mcp_target
cursor_mcp_target=$(readlink "$cursor_mcp_path")
if [[ "$cursor_mcp_target" != *".agents/mcp.json" ]]; then
echo "❌ $cursor_mcp_path should point to repo .agents/mcp.json, got: $cursor_mcp_target"
errors=$((errors + 1))
else
echo "✓ $cursor_mcp_path → $cursor_mcp_target"
fi
fi
# Check Codex skills symlink (nested path due ~/.codex/skills/.system)
local codex_path="$HOME/.codex/skills/skills"
if [ ! -L "$codex_path" ]; then
echo "❌ $codex_path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$codex_path" ]; then
echo "❌ $codex_path is a broken symlink"
errors=$((errors + 1))
else
local codex_target
codex_target=$(readlink "$codex_path")
if [[ "$codex_target" != *".agents/skills" ]]; then
echo "❌ $codex_path should point to .agents/skills, got: $codex_target"
errors=$((errors + 1))
else
echo "✓ $codex_path → .agents/skills"
fi
fi
# Check Codex managed config file
local codex_config_path="$HOME/.codex/config.toml"
if [ ! -L "$codex_config_path" ]; then
echo "❌ $codex_config_path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$codex_config_path" ]; then
echo "❌ $codex_config_path is a broken symlink"
errors=$((errors + 1))
else
local codex_config_target
codex_config_target=$(readlink "$codex_config_path")
if [[ "$codex_config_target" != *".codex/config.toml" ]]; then
echo "❌ $codex_config_path should point to repo .codex/config.toml, got: $codex_config_target"
errors=$((errors + 1))
else
echo "✓ $codex_config_path → $codex_config_target"
fi
fi
# Check Codex shared rules symlink
local codex_rules_path="$HOME/.codex/rules/default.rules"
if [ ! -L "$codex_rules_path" ]; then
echo "❌ $codex_rules_path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$codex_rules_path" ]; then
echo "❌ $codex_rules_path is a broken symlink"
errors=$((errors + 1))
else
local codex_rules_target
codex_rules_target=$(readlink "$codex_rules_path")
if [[ "$codex_rules_target" != *".agents/rules/codex-default.rules" ]]; then
echo "❌ $codex_rules_path should point to repo .agents/rules/codex-default.rules, got: $codex_rules_target"
errors=$((errors + 1))
else
echo "✓ $codex_rules_path → $codex_rules_target"
fi
fi
# Check Codex instructions symlink
local codex_agents_path="$HOME/.codex/AGENTS.md"
if [ ! -L "$codex_agents_path" ]; then
echo "❌ $codex_agents_path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$codex_agents_path" ]; then
echo "❌ $codex_agents_path is a broken symlink"
errors=$((errors + 1))
else
local codex_agents_target
codex_agents_target=$(readlink "$codex_agents_path")
if [[ "$codex_agents_target" != *"/AGENTS.md" ]]; then
echo "❌ $codex_agents_path should point to repo AGENTS.md, got: $codex_agents_target"
errors=$((errors + 1))
else
echo "✓ $codex_agents_path → $codex_agents_target"
fi
fi
# Check skills symlinks for other dev tools (must point to repo .agents/skills)
for tool in $TOOLS_WITH_SKILLS; do
local path="$HOME/$tool/skills"
if [ ! -L "$path" ]; then
echo "❌ $path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$path" ]; then
echo "❌ $path is a broken symlink"
errors=$((errors + 1))
else
local target
target=$(readlink "$path")
if [[ "$target" != *".agents/skills" ]]; then
echo "❌ $path should point to .agents/skills, got: $target"
errors=$((errors + 1))
else
echo "✓ $path → .agents/skills"
fi
fi
done
# Check .claude
if [ ! -L ~/.claude ]; then
echo "❌ ~/.claude is not a symlink"
errors=$((errors + 1))
else
echo "✓ ~/.claude → $(readlink ~/.claude)"
fi
# Check Gemini MCP config symlink
local gemini_mcp_path="$HOME/.gemini/antigravity/mcp_config.json"
if [ ! -L "$gemini_mcp_path" ]; then
echo "❌ $gemini_mcp_path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$gemini_mcp_path" ]; then
echo "❌ $gemini_mcp_path is a broken symlink"
errors=$((errors + 1))
else
local gemini_mcp_target
gemini_mcp_target=$(readlink "$gemini_mcp_path")
if [[ "$gemini_mcp_target" != *".agents/mcp.json" ]]; then
echo "❌ $gemini_mcp_path should point to repo .agents/mcp.json, got: $gemini_mcp_target"
errors=$((errors + 1))
else
echo "✓ $gemini_mcp_path → $gemini_mcp_target"
fi
fi
# Check Gemini commands and workflows symlinks
for dir in workflows commands; do
local path="$HOME/.gemini/antigravity/$dir"
if [ ! -L "$path" ]; then
echo "❌ $path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$path" ]; then
echo "❌ $path is a broken symlink"
errors=$((errors + 1))
else
local target
target=$(readlink "$path")
if [[ "$target" != *".agents/$dir" ]]; then
echo "❌ $path should point to repo .agents/$dir, got: $target"
errors=$((errors + 1))
else
echo "✓ $path → $target"
fi
fi
done
# Check Gemini instructions symlink
local gemini_rules_path="$HOME/.gemini/GEMINI.md"
if [ ! -L "$gemini_rules_path" ]; then
echo "❌ $gemini_rules_path is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$gemini_rules_path" ]; then
echo "❌ $gemini_rules_path is a broken symlink"
errors=$((errors + 1))
else
local gemini_rules_target
gemini_rules_target=$(readlink "$gemini_rules_path")
if [[ "$gemini_rules_target" != *"/GEMINI.md" ]]; then
echo "❌ $gemini_rules_path should point to repo GEMINI.md, got: $gemini_rules_target"
errors=$((errors + 1))
else
echo "✓ $gemini_rules_path → $gemini_rules_target"
fi
fi
# Check ~/.agents canonical link
if [ ! -L "$HOME/.agents" ]; then
echo "❌ ~/.agents is not a symlink"
errors=$((errors + 1))
elif [ ! -e "$HOME/.agents" ]; then
echo "❌ ~/.agents is a broken symlink"
errors=$((errors + 1))
else
local agents_target
agents_target=$(readlink "$HOME/.agents")
if [[ "$agents_target" != *"augmentedcode-configuration/.agents" ]]; then
echo "❌ ~/.agents should point to repo .agents, got: $agents_target"
errors=$((errors + 1))
else
echo "✓ ~/.agents → $agents_target"
fi
fi
# Check root configs
for config in CLAUDE.md AGENTS.md GEMINI.md; do
local path="$HOME/$config"
if [ ! -L "$path" ]; then
echo "❌ ~/$config is not a symlink"
errors=$((errors + 1))
else
echo "✓ ~/$config → $(readlink $path)"
fi
done
if [ $errors -eq 0 ]; then
echo ""
echo "✅ All symlinks valid"
return 0
else
echo ""
echo "❌ Found $errors symlink issues"
return 1
fi
}
# Show git status
show_status() {
echo "📊 Configuration changes:"
cd "$REPO_DIR"
git status --short .cursor/ .codex/ .gemini/ .agents/ *.md 2>/dev/null || true
}
# Commit and push changes
commit_changes() {
cd "$REPO_DIR"
if git diff --quiet .cursor/ .codex/ .gemini/ .agents/ *.md 2>/dev/null; then
echo "ℹ️ No config changes to commit"
exit 0
fi
echo "📝 Changes to commit:"
git status --short .cursor/ .codex/ .gemini/ .agents/ *.md
echo ""
read -p "Commit message: " -r message
if [ -z "$message" ]; then
echo "❌ Commit message required"
exit 1
fi
git add .cursor/ .codex/ .gemini/ .agents/ *.md
git commit -m "$message"
read -p "Push to remote? (y/n): " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
git push
echo "✅ Changes pushed"
else
echo "ℹ️ Changes committed locally (not pushed)"
fi
}
# Main
check_environment
case "${1:-help}" in
setup)
setup_symlinks
;;
validate)
validate_symlinks
;;
status)
show_status
;;
commit)
commit_changes
;;
help|*)
usage
;;
esac