-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-symlinks.sh
More file actions
290 lines (250 loc) · 8.54 KB
/
Copy pathinstall-symlinks.sh
File metadata and controls
290 lines (250 loc) · 8.54 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
#!/usr/bin/env bash
# ==============================================================================
# Ring - Claude Code Symlinks Installer
# ==============================================================================
# Creates symlinks from ~/.claude/{agents,commands,skills} to the Ring repo,
# enabling all Ring agents, commands, and skills in your Claude Code environment.
#
# Usage:
# bash install-symlinks.sh # Auto-detects Ring repo from script location
# bash install-symlinks.sh /path/to/ring # Explicit Ring repo path
# bash install-symlinks.sh --remove # Remove all Ring symlinks
#
# Requirements:
# - Claude Code CLI installed
# - Ring repository cloned locally
# ==============================================================================
set -euo pipefail
# --- Colors ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# --- Globals ---
CLAUDE_DIR="$HOME/.claude"
FACTORY_DIR="$HOME/.factory"
RING_DIR=""
INSTALL_CLAUDE=true
INSTALL_FACTORY=false
CREATED=0
SKIPPED=0
ERRORS=0
REMOVED=0
# --- Functions ---
print_banner() {
echo -e "${CYAN}"
echo " ╔══════════════════════════════════════════════════╗"
echo " ║ Ring - Claude Code Symlinks Installer ║"
echo " ╚══════════════════════════════════════════════════╝"
echo -e "${NC}"
}
log_info() { echo -e " ${BLUE}INFO${NC} $1"; }
log_success() { echo -e " ${GREEN}OK${NC} $1"; }
log_skip() { echo -e " ${YELLOW}SKIP${NC} $1"; }
log_error() { echo -e " ${RED}ERROR${NC} $1"; }
log_section() { echo -e "\n ${BOLD}${CYAN}── $1 ──${NC}\n"; }
resolve_ring_dir() {
if [[ -n "${1:-}" && "$1" != "--remove" && "$1" != "--factory" && "$1" != "--all" && "$1" != "--claude" ]]; then
RING_DIR="$(cd "$1" && pwd)"
else
# Auto-detect from script location
RING_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi
# Validate Ring repo
if [[ ! -f "$RING_DIR/CLAUDE.md" ]]; then
log_error "Not a Ring repository: $RING_DIR"
log_error "CLAUDE.md not found. Please provide the correct path."
exit 1
fi
if [[ ! -d "$RING_DIR/default/agents" ]]; then
log_error "Missing default/agents directory in: $RING_DIR"
exit 1
fi
}
create_directories() {
local base_dirs=("agents" "commands" "skills")
if [[ "$INSTALL_CLAUDE" == true ]]; then
for subdir in "${base_dirs[@]}"; do
local dir="$CLAUDE_DIR/$subdir"
if [[ ! -d "$dir" ]]; then
mkdir -p "$dir"
log_info "Created directory: $dir"
fi
done
fi
if [[ "$INSTALL_FACTORY" == true ]]; then
for subdir in "${base_dirs[@]}"; do
local dir="$FACTORY_DIR/$subdir"
if [[ ! -d "$dir" ]]; then
mkdir -p "$dir"
log_info "Created directory: $dir"
fi
done
fi
}
create_symlink() {
local source="$1"
local target="$2"
local name
name="$(basename "$target")"
if [[ -L "$target" ]]; then
local existing
existing="$(readlink "$target")"
if [[ "$existing" == "$source" ]]; then
SKIPPED=$((SKIPPED + 1))
return
else
# Symlink exists but points elsewhere - update it
rm "$target"
ln -s "$source" "$target"
log_success "$name (updated)"
CREATED=$((CREATED + 1))
return
fi
elif [[ -e "$target" ]]; then
log_error "$name already exists as a regular file (not a symlink). Skipping."
ERRORS=$((ERRORS + 1))
return
fi
ln -s "$source" "$target"
CREATED=$((CREATED + 1))
}
link_agents() {
local plugin="$1"
local target_dir="$2"
local agents_dir="$RING_DIR/$plugin/agents"
[[ ! -d "$agents_dir" ]] && return
for agent in "$agents_dir"/*.md; do
[[ ! -f "$agent" ]] && continue
local name
name="$(basename "$agent")"
create_symlink "$agent" "$target_dir/agents/$name"
done
}
link_commands() {
local plugin="$1"
local target_dir="$2"
local commands_dir="$RING_DIR/$plugin/commands"
[[ ! -d "$commands_dir" ]] && return
for cmd in "$commands_dir"/*.md; do
[[ ! -f "$cmd" ]] && continue
local name
name="$(basename "$cmd")"
create_symlink "$cmd" "$target_dir/commands/$name"
done
}
link_skills() {
local plugin="$1"
local target_dir="$2"
local skills_dir="$RING_DIR/$plugin/skills"
[[ ! -d "$skills_dir" ]] && return
for skill in "$skills_dir"/*/; do
[[ ! -d "$skill" ]] && continue
local name
name="$(basename "$skill")"
# Skip shared-patterns directories (internal to each plugin, not standalone skills)
[[ "$name" == "shared-patterns" ]] && continue
create_symlink "$skill" "$target_dir/skills/$name"
done
}
install_symlinks() {
local plugins=("default" "dev-team" "pm-team" "pmo-team" "finops-team" "tw-team")
for plugin in "${plugins[@]}"; do
log_section "$plugin"
if [[ "$INSTALL_CLAUDE" == true ]]; then
link_agents "$plugin" "$CLAUDE_DIR"
link_commands "$plugin" "$CLAUDE_DIR"
link_skills "$plugin" "$CLAUDE_DIR"
fi
if [[ "$INSTALL_FACTORY" == true ]]; then
link_agents "$plugin" "$FACTORY_DIR"
link_commands "$plugin" "$FACTORY_DIR"
link_skills "$plugin" "$FACTORY_DIR"
fi
done
}
remove_symlinks() {
log_section "Removing Ring symlinks"
for dir in agents commands skills; do
local target_dir="$CLAUDE_DIR/$dir"
[[ ! -d "$target_dir" ]] && continue
for item in "$target_dir"/*; do
[[ ! -L "$item" ]] && continue
local link_target
link_target="$(readlink "$item")"
# Only remove symlinks that point to the Ring repo
if [[ "$link_target" == *"/ring/"* ]]; then
rm "$item"
log_success "Removed: $dir/$(basename "$item")"
REMOVED=$((REMOVED + 1))
fi
done
done
echo ""
echo -e " ${GREEN}${BOLD}Done!${NC} Removed ${REMOVED} symlinks."
}
print_summary() {
echo ""
echo -e " ${BOLD}════════════════════════════════════════${NC}"
echo -e " ${GREEN}Created:${NC} $CREATED symlinks"
echo -e " ${YELLOW}Skipped:${NC} $SKIPPED (already correct)"
if [[ $ERRORS -gt 0 ]]; then
echo -e " ${RED}Errors:${NC} $ERRORS"
fi
echo -e " ${BOLD}════════════════════════════════════════${NC}"
echo ""
echo -e " ${CYAN}Ring repo:${NC} $RING_DIR"
[[ "$INSTALL_CLAUDE" == true ]] && echo -e " ${CYAN}Claude dir:${NC} $CLAUDE_DIR"
[[ "$INSTALL_FACTORY" == true ]] && echo -e " ${CYAN}Factory dir:${NC} $FACTORY_DIR"
echo ""
local total=$((CREATED + SKIPPED))
if [[ $total -gt 0 ]]; then
local target_names=""
[[ "$INSTALL_CLAUDE" == true ]] && target_names="Claude Code"
[[ "$INSTALL_FACTORY" == true ]] && { [[ -n "$target_names" ]] && target_names="$target_names and Factory AI" || target_names="Factory AI"; }
echo -e " ${GREEN}${BOLD}Ring is ready!${NC} Open $target_names to use all skills, agents, and commands."
echo ""
echo -e " Try these commands:"
echo -e " ${BOLD}/ring:brainstorm${NC} - Socratic design refinement"
echo -e " ${BOLD}/ring:dev-cycle${NC} - 10-gate development cycle"
echo -e " ${BOLD}/ring:pre-dev-feature${NC} - Lightweight pre-dev workflow"
echo -e " ${BOLD}/ring:codereview${NC} - Parallel code review (7 reviewers)"
echo ""
fi
}
# --- Main ---
print_banner
if [[ "${1:-}" == "--remove" ]]; then
resolve_ring_dir "${2:-}"
remove_symlinks
exit 0
fi
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
echo " Usage:"
echo " bash install-symlinks.sh # Install for Claude Code (default)"
echo " bash install-symlinks.sh --factory # Install for Factory AI"
echo " bash install-symlinks.sh --all # Install for both Claude Code and Factory AI"
echo " bash install-symlinks.sh /path/to/ring # Explicit path"
echo " bash install-symlinks.sh --remove # Remove Ring symlinks"
echo ""
exit 0
fi
if [[ "${1:-}" == "--factory" ]]; then
INSTALL_CLAUDE=false
INSTALL_FACTORY=true
shift
elif [[ "${1:-}" == "--all" ]]; then
INSTALL_CLAUDE=true
INSTALL_FACTORY=true
shift
fi
resolve_ring_dir "${1:-}"
log_info "Ring repo: $RING_DIR"
[[ "$INSTALL_CLAUDE" == true ]] && log_info "Claude dir: $CLAUDE_DIR"
[[ "$INSTALL_FACTORY" == true ]] && log_info "Factory dir: $FACTORY_DIR"
create_directories
install_symlinks
print_summary