forked from masoncl/review-prompts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·151 lines (127 loc) · 4.97 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·151 lines (127 loc) · 4.97 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
#!/bin/bash
#
# Setup script for AI-assisted code review prompts
#
# Installs skills and slash commands for the specified agent on their respective
# locations.
#
# Usage: ./setup.sh [OPTIONS] <agent> <project>
#
# Each project directory must contain a skill file at:
# <project>/skills/<project>.md
#
# The skill filename is derived from the directory name (e.g. the "iproute"
# project uses iproute/skills/iproute.md). Inside that file, use the
# placeholder {{<PROJECT>_REVIEW_PROMPTS_DIR}} (uppercased project name)
# for paths that should resolve to the project directory at install time.
#
# Slash commands live in <project>/slash-commands/*.md and may use
# {{REVIEW_DIR}} as a placeholder for the project directory path.
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
usage() {
echo "Usage: $0 [OPTIONS] <agent> <project>"
echo "Setup script for AI-assisted code review prompts."
echo "Installs skills and slash commands for the specified agent."
echo ""
echo "Arguments:"
echo " <agent> Install skill and commands for this code agent"
echo " Available agents: claude, codex, opencode, gemini,"
echo " goose, kiro-cli"
echo " <project> Install skills and commands for this project"
echo " Available projects: iproute, kernel, nfs-utils,"
echo " systemd"
echo ""
echo "Options:"
echo " -h, --help Show this help message and exit"
}
# Skill and slash commands installation process.
# Args: $1 = project
install_project() {
local project="$1"
local src_skill_fn="${project}.md"
local project_dir="$SCRIPT_DIR/$project"
local prompts_dir_var="${project^^}_REVIEW_PROMPTS_DIR"
echo "--- Installing $project prompts ---"
# Install skills from the source to the agent specific path
local agent_skills_dir="$SKILL_BASE_DIR/$project"
local agent_skill_path="$agent_skills_dir/$SKILL_FILE_NAME"
local src_skill_path="$project_dir/skills/$src_skill_fn"
if [ ! -f "$src_skill_path" ]; then
echo "Error: Source skill file not found: $src_skill_path"
exit 1
fi
mkdir -p "$agent_skills_dir"
sed "s|{{${prompts_dir_var}}}|$project_dir|g" "$src_skill_path" > "$agent_skill_path"
echo "Installed skill:"
echo " $agent_skill_path"
# Install slash commands to agent specific path
local src_commands="$project_dir/slash-commands"
if [ ! -d "$src_commands" ]; then
echo "Warning: commands directory not found for $project, skipping"
else
mkdir -p "$COMMANDS_DIR"
echo ""
echo "Installed slash commands:"
for cmd_file in "$src_commands"/*.md; do
if [ -f "$cmd_file" ]; then
local cmd_name=$(basename "$cmd_file")
if [ "${COMMANDS_AS_SKILLS:-0}" = "1" ]; then
# The agent has no standalone slash-command files; install
# each command as a skill (<name>/SKILL.md) so the agent
# exposes it as /<name>. Skills require frontmatter with
# a name, so generate it when the source file has none.
local cmd_skill_dir="$COMMANDS_DIR/${cmd_name%.md}"
mkdir -p "$cmd_skill_dir"
{
if ! head -n 1 "$cmd_file" | grep -q '^---$'; then
printf -- '---\n'
printf 'name: %s\n' "${cmd_name%.md}"
printf 'description: "/%s slash command from the %s review prompts; load only when invoked explicitly"\n' \
"${cmd_name%.md}" "$project"
printf -- '---\n\n'
fi
sed "s|{{REVIEW_DIR}}|$project_dir|g" "$cmd_file"
} > "$cmd_skill_dir/$SKILL_FILE_NAME"
else
sed "s|{{REVIEW_DIR}}|$project_dir|g" "$cmd_file" > "$COMMANDS_DIR/$cmd_name"
fi
echo " ${COMMAND_PREFIX:-/}${cmd_name%.md}"
fi
done
fi
echo ""
}
# Handle args and flags
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
usage
exit 0
fi
if [ "$#" -ne 2 ]; then
echo "Error: expected 2 arguments (<agent> <project>), got $#"
echo ""
usage
exit 1
fi
AGENT="$1"
PROJECT="$2"
AGENT_SCRIPT="$SCRIPT_DIR/agents/${AGENT}.sh"
if [ ! -f "$AGENT_SCRIPT" ]; then
echo "Error: Setup script for agent '$AGENT' not found at $AGENT_SCRIPT"
exit 1
fi
PROJECT_DIR="$SCRIPT_DIR/$PROJECT"
if [ ! -d "$PROJECT_DIR" ]; then
echo "Error: Project '$PROJECT' not found at $PROJECT_DIR"
exit 1
fi
# Load agent configuration
source "$AGENT_SCRIPT"
echo "Review prompts directory: $SCRIPT_DIR/$PROJECT"
echo "Setting up for agent: $AGENT"
echo "Setting up for project: $PROJECT"
echo ""
install_project "$PROJECT"
echo "Setup complete!"
echo ""
echo "The skills load automatically in their respective project trees."