Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions scripts/build-rules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# Reads rules from .claude/rules/ and generates:
# - Slash commands in .claude/commands/
# - Skills in .claude/skills/*/SKILL.md
#
# Compatible with Bash 3.2+ (default on macOS)
# =============================================================================

set -e
Expand Down Expand Up @@ -34,8 +36,11 @@ RULES_DIR="$CLAUDE_DIR/rules"
COMMANDS_DIR="$CLAUDE_DIR/commands"
SKILLS_DIR="$CLAUDE_DIR/skills"

# Associative arrays for rules and skills
declare -A RULES
# Use temp directory for storing rules (Bash 3.2 compatible)
TEMP_RULES_DIR=$(mktemp -d)
trap 'rm -rf "$TEMP_RULES_DIR"' EXIT

# Array for available skills
declare -a AVAILABLE_SKILLS

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

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

# Add frontmatter
output_parts+=("---")
output_parts+=("description: $description")
output_parts+=("model: $model")
output_parts+=("---")
# Write frontmatter
{
echo "---"
echo "description: $description"
echo "model: $model"
echo "---"
} > "$command_file"

# Add rules content
for rule_id in $rules_list; do
if [[ -n "${RULES[$rule_id]}" ]]; then
output_parts+=("${RULES[$rule_id]}")
output_parts+=("")
if [[ -f "$TEMP_RULES_DIR/$rule_id" ]]; then
cat "$TEMP_RULES_DIR/$rule_id" >> "$command_file"
echo "" >> "$command_file"
else
log_warning "Rule '$rule_id' not found"
fi
done

# Add skills section if needed
if [[ "$inject_skills" == "True" || "$inject_skills" == "true" ]]; then
local skills_section
skills_section=$(format_skills_section)
[[ -n "$skills_section" ]] && output_parts+=("$skills_section")
format_skills_section >> "$command_file"
fi

# Write command file
local command_file="$COMMANDS_DIR/${cmd_name}.md"
printf "%s\n" "${output_parts[@]}" > "$command_file"

if [[ "$inject_skills" == "True" || "$inject_skills" == "true" ]]; then
log_success "Generated ${cmd_name}.md (with skills)"
else
Expand Down Expand Up @@ -296,13 +298,13 @@ build_skills() {
local rule_id
rule_id=$(basename "$md_file" .md)

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

local skill_dir="$SKILLS_DIR/$rule_id"
mkdir -p "$skill_dir"

local skill_file="$skill_dir/SKILL.md"
echo "${RULES[$rule_id]}" > "$skill_file"
cat "$TEMP_RULES_DIR/$rule_id" > "$skill_file"

log_success "Generated $rule_id/SKILL.md"
((skill_count++)) || true
Expand Down
11 changes: 8 additions & 3 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ trap cleanup EXIT
build_rules() {
print_status "Building Claude Code commands and skills..."

if [[ -f "$PROJECT_DIR/scripts/build-rules.sh" ]]; then
bash "$PROJECT_DIR/scripts/build-rules.sh"
if [[ ! -f "$PROJECT_DIR/scripts/build-rules.sh" ]]; then
print_warning "build-rules.sh not found, skipping"
return
fi

if bash "$PROJECT_DIR/scripts/build-rules.sh"; then
print_success "Built commands and skills"
else
print_warning "build-rules.sh not found, skipping"
print_error "Failed to build commands and skills"
print_warning "You may need to run 'bash scripts/build-rules.sh' manually"
fi
}

Expand Down
16 changes: 14 additions & 2 deletions scripts/lib/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,21 @@ install_cipher() {
fi

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

print_success "Installed Cipher"
if npm install -g @byterover/cipher; then
# Verify installation was successful
if command -v cipher &>/dev/null; then
print_success "Installed Cipher"
else
print_warning "Cipher was installed but command not found in PATH"
print_warning "You may need to restart your shell or add npm global bin to PATH"
echo " Run: npm config get prefix"
echo " Then add <prefix>/bin to your PATH"
fi
else
print_error "Failed to install Cipher"
print_warning "You can install it manually later with: npm install -g @byterover/cipher"
fi
}

# Install Newman (Postman CLI)
Expand Down
20 changes: 16 additions & 4 deletions scripts/lib/shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@ add_shell_alias() {

# Check if this specific project alias exists
if grep -q "# Claude CodePro alias - $PROJECT_DIR" "$shell_file"; then
# Update existing alias for this project
sed -i.bak "/# Claude CodePro alias - ${PROJECT_DIR//\//\\/}/,/^alias ${alias_name}=/c\\
# Claude CodePro alias - $PROJECT_DIR\\
$alias_cmd" "$shell_file" && rm -f "${shell_file}.bak"
# Update existing alias for this project - create temp file for better compatibility
local temp_file="${shell_file}.tmp"
local in_section=0
while IFS= read -r line; do
if [[ "$line" == "# Claude CodePro alias - $PROJECT_DIR" ]]; then
in_section=1
echo "# Claude CodePro alias - $PROJECT_DIR" >> "$temp_file"
echo "$alias_cmd" >> "$temp_file"
elif [[ $in_section -eq 1 ]] && [[ "$line" =~ ^alias\ ${alias_name}= ]]; then
in_section=0
continue
else
echo "$line" >> "$temp_file"
fi
done < "$shell_file"
mv "$temp_file" "$shell_file"
print_success "Updated alias '$alias_name' in $shell_name"
elif grep -q "^alias ${alias_name}=" "$shell_file"; then
print_warning "Alias '$alias_name' already exists in $shell_name (skipped)"
Expand Down