Skip to content

Commit dc80c78

Browse files
authored
Merge pull request #11 from maxritter/claude/fix-install-script-issues-01PJ1BfTKYiz6xXrhMntfmqP
fix: improve install script compatibility and error handling
2 parents d7bacbc + e3f53e4 commit dc80c78

4 files changed

Lines changed: 61 additions & 30 deletions

File tree

scripts/build-rules.sh

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# Reads rules from .claude/rules/ and generates:
77
# - Slash commands in .claude/commands/
88
# - Skills in .claude/skills/*/SKILL.md
9+
#
10+
# Compatible with Bash 3.2+ (default on macOS)
911
# =============================================================================
1012

1113
set -e
@@ -34,8 +36,11 @@ RULES_DIR="$CLAUDE_DIR/rules"
3436
COMMANDS_DIR="$CLAUDE_DIR/commands"
3537
SKILLS_DIR="$CLAUDE_DIR/skills"
3638

37-
# Associative arrays for rules and skills
38-
declare -A RULES
39+
# Use temp directory for storing rules (Bash 3.2 compatible)
40+
TEMP_RULES_DIR=$(mktemp -d)
41+
trap 'rm -rf "$TEMP_RULES_DIR"' EXIT
42+
43+
# Array for available skills
3944
declare -a AVAILABLE_SKILLS
4045

4146
# -----------------------------------------------------------------------------
@@ -70,7 +75,8 @@ load_rules() {
7075
while IFS= read -r -d '' md_file; do
7176
local rule_id
7277
rule_id=$(basename "$md_file" .md)
73-
RULES["$rule_id"]=$(cat "$md_file")
78+
# Store rule content in temp file instead of associative array
79+
cat "$md_file" > "$TEMP_RULES_DIR/$rule_id"
7480
log_success "Loaded $category/$(basename "$md_file")"
7581
((rule_count++)) || true
7682
done < <(find "$category_dir" -maxdepth 1 -name "*.md" -print0 2>/dev/null)
@@ -236,35 +242,31 @@ build_commands() {
236242
local command_count=0
237243

238244
while IFS='|' read -r cmd_name description model inject_skills rules_list; do
239-
local output_parts=()
245+
local command_file="$COMMANDS_DIR/${cmd_name}.md"
240246

241-
# Add frontmatter
242-
output_parts+=("---")
243-
output_parts+=("description: $description")
244-
output_parts+=("model: $model")
245-
output_parts+=("---")
247+
# Write frontmatter
248+
{
249+
echo "---"
250+
echo "description: $description"
251+
echo "model: $model"
252+
echo "---"
253+
} > "$command_file"
246254

247255
# Add rules content
248256
for rule_id in $rules_list; do
249-
if [[ -n "${RULES[$rule_id]}" ]]; then
250-
output_parts+=("${RULES[$rule_id]}")
251-
output_parts+=("")
257+
if [[ -f "$TEMP_RULES_DIR/$rule_id" ]]; then
258+
cat "$TEMP_RULES_DIR/$rule_id" >> "$command_file"
259+
echo "" >> "$command_file"
252260
else
253261
log_warning "Rule '$rule_id' not found"
254262
fi
255263
done
256264

257265
# Add skills section if needed
258266
if [[ "$inject_skills" == "True" || "$inject_skills" == "true" ]]; then
259-
local skills_section
260-
skills_section=$(format_skills_section)
261-
[[ -n "$skills_section" ]] && output_parts+=("$skills_section")
267+
format_skills_section >> "$command_file"
262268
fi
263269

264-
# Write command file
265-
local command_file="$COMMANDS_DIR/${cmd_name}.md"
266-
printf "%s\n" "${output_parts[@]}" > "$command_file"
267-
268270
if [[ "$inject_skills" == "True" || "$inject_skills" == "true" ]]; then
269271
log_success "Generated ${cmd_name}.md (with skills)"
270272
else
@@ -296,13 +298,13 @@ build_skills() {
296298
local rule_id
297299
rule_id=$(basename "$md_file" .md)
298300

299-
[[ -z "${RULES[$rule_id]}" ]] && continue
301+
[[ ! -f "$TEMP_RULES_DIR/$rule_id" ]] && continue
300302

301303
local skill_dir="$SKILLS_DIR/$rule_id"
302304
mkdir -p "$skill_dir"
303305

304306
local skill_file="$skill_dir/SKILL.md"
305-
echo "${RULES[$rule_id]}" > "$skill_file"
307+
cat "$TEMP_RULES_DIR/$rule_id" > "$skill_file"
306308

307309
log_success "Generated $rule_id/SKILL.md"
308310
((skill_count++)) || true

scripts/install.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,16 @@ trap cleanup EXIT
9494
build_rules() {
9595
print_status "Building Claude Code commands and skills..."
9696

97-
if [[ -f "$PROJECT_DIR/scripts/build-rules.sh" ]]; then
98-
bash "$PROJECT_DIR/scripts/build-rules.sh"
97+
if [[ ! -f "$PROJECT_DIR/scripts/build-rules.sh" ]]; then
98+
print_warning "build-rules.sh not found, skipping"
99+
return
100+
fi
101+
102+
if bash "$PROJECT_DIR/scripts/build-rules.sh"; then
99103
print_success "Built commands and skills"
100104
else
101-
print_warning "build-rules.sh not found, skipping"
105+
print_error "Failed to build commands and skills"
106+
print_warning "You may need to run 'bash scripts/build-rules.sh' manually"
102107
fi
103108
}
104109

scripts/lib/dependencies.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,21 @@ install_cipher() {
155155
fi
156156

157157
print_status "Installing Cipher..."
158-
npm install -g @byterover/cipher
159158

160-
print_success "Installed Cipher"
159+
if npm install -g @byterover/cipher; then
160+
# Verify installation was successful
161+
if command -v cipher &>/dev/null; then
162+
print_success "Installed Cipher"
163+
else
164+
print_warning "Cipher was installed but command not found in PATH"
165+
print_warning "You may need to restart your shell or add npm global bin to PATH"
166+
echo " Run: npm config get prefix"
167+
echo " Then add <prefix>/bin to your PATH"
168+
fi
169+
else
170+
print_error "Failed to install Cipher"
171+
print_warning "You can install it manually later with: npm install -g @byterover/cipher"
172+
fi
161173
}
162174

163175
# Install Newman (Postman CLI)

scripts/lib/shell.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,22 @@ add_shell_alias() {
2020

2121
# Check if this specific project alias exists
2222
if grep -q "# Claude CodePro alias - $PROJECT_DIR" "$shell_file"; then
23-
# Update existing alias for this project
24-
sed -i.bak "/# Claude CodePro alias - ${PROJECT_DIR//\//\\/}/,/^alias ${alias_name}=/c\\
25-
# Claude CodePro alias - $PROJECT_DIR\\
26-
$alias_cmd" "$shell_file" && rm -f "${shell_file}.bak"
23+
# Update existing alias for this project - create temp file for better compatibility
24+
local temp_file="${shell_file}.tmp"
25+
local in_section=0
26+
while IFS= read -r line; do
27+
if [[ "$line" == "# Claude CodePro alias - $PROJECT_DIR" ]]; then
28+
in_section=1
29+
echo "# Claude CodePro alias - $PROJECT_DIR" >> "$temp_file"
30+
echo "$alias_cmd" >> "$temp_file"
31+
elif [[ $in_section -eq 1 ]] && [[ "$line" =~ ^alias\ ${alias_name}= ]]; then
32+
in_section=0
33+
continue
34+
else
35+
echo "$line" >> "$temp_file"
36+
fi
37+
done < "$shell_file"
38+
mv "$temp_file" "$shell_file"
2739
print_success "Updated alias '$alias_name' in $shell_name"
2840
elif grep -q "^alias ${alias_name}=" "$shell_file"; then
2941
print_warning "Alias '$alias_name' already exists in $shell_name (skipped)"

0 commit comments

Comments
 (0)