-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·328 lines (288 loc) · 10.3 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·328 lines (288 loc) · 10.3 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
#!/usr/bin/env bash
# Install ai-workflows via symlinks.
# Automatically discovers all workflow directories (any dir with a SKILL.md).
#
# Scope:
# User-level (default) — available in all your projects
# Project-level — committed / shared with a specific repo
#
# Usage:
# ./install.sh cursor # user-level, all workflows
# ./install.sh cursor --workflows bugfix # user-level, specific workflow
# ./install.sh cursor --workflows bugfix,docs-writer # user-level, multiple workflows
# ./install.sh cursor --project [path] # project-level, all workflows
# ./install.sh claude # user-level Claude Code reference
# ./install.sh claude --project [path] # project-level Claude Code reference
# ./install.sh gemini # user-level Gemini CLI skill symlinks
# ./install.sh gemini --project [path] # project-level Gemini CLI skill symlinks
# ./install.sh all # user-level Cursor + Claude + Gemini
# ./install.sh all --project [path] # project-level Cursor + Claude + Gemini
# ./install.sh --list # list available workflows
set -e
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_DIR="${HOME}/.ai-workflows"
# --- discover all available workflows ---
ALL_WORKFLOWS=()
for skill in "$REPO_DIR"/*/SKILL.md; do
[[ -f "$skill" ]] || continue
ALL_WORKFLOWS+=("$(basename "$(dirname "$skill")")")
done
# --- handle --list early ---
for arg in "$@"; do
if [[ "$arg" == "--list" ]]; then
echo "Available workflows:"
for wf in "${ALL_WORKFLOWS[@]}"; do
echo " $wf"
done
exit 0
fi
done
# --- parse arguments ---
TARGET="${1:-cursor}"
SCOPE="user"
PROJECT_ROOT=""
SELECTED_WORKFLOWS=()
shift 2>/dev/null || true
while [[ $# -gt 0 ]]; do
case "$1" in
--project)
SCOPE="project"
if [[ -n "${2:-}" && "${2:0:1}" != "-" ]]; then
PROJECT_ROOT="$2"
shift
fi
;;
--workflows)
if [[ -n "${2:-}" && "${2:0:1}" != "-" ]]; then
IFS=',' read -ra _wfs <<< "$2"
SELECTED_WORKFLOWS+=("${_wfs[@]}")
shift
else
echo "Error: --workflows requires a comma-separated list of workflow names" >&2
exit 1
fi
;;
esac
shift
done
if [[ "$SCOPE" == "project" && -z "$PROJECT_ROOT" ]]; then
PROJECT_ROOT="$(pwd)"
fi
# --- resolve final workflow list ---
if [[ ${#SELECTED_WORKFLOWS[@]} -gt 0 ]]; then
WORKFLOWS=()
for sel in "${SELECTED_WORKFLOWS[@]}"; do
found=false
for avail in "${ALL_WORKFLOWS[@]}"; do
if [[ "$sel" == "$avail" ]]; then
found=true
break
fi
done
if [[ "$found" == false ]]; then
echo "Error: unknown workflow '$sel'" >&2
echo "Available workflows: ${ALL_WORKFLOWS[*]}" >&2
exit 1
fi
WORKFLOWS+=("$sel")
done
else
WORKFLOWS=("${ALL_WORKFLOWS[@]}")
fi
if [[ ${#WORKFLOWS[@]} -eq 0 ]]; then
echo "Error: no workflows found (directories with SKILL.md)" >&2
exit 1
fi
# --- helpers ---
ensure_repo_linked() {
if [[ "$(readlink -f "$REPO_DIR")" == "$(readlink -f "$INSTALL_DIR" 2>/dev/null)" ]]; then
return
fi
if [[ -e "$INSTALL_DIR" ]]; then
echo "Warning: $INSTALL_DIR already exists and points elsewhere." >&2
echo " Current target: $(readlink -f "$INSTALL_DIR" 2>/dev/null || echo "$INSTALL_DIR")" >&2
echo " This repo: $REPO_DIR" >&2
echo " Remove it first: rm -rf $INSTALL_DIR" >&2
exit 1
fi
ln -sfn "$REPO_DIR" "$INSTALL_DIR"
echo " Linked $INSTALL_DIR -> $REPO_DIR"
}
install_shared() {
local target_dir="$1"
if [[ ! -d "${INSTALL_DIR}/_shared" ]]; then
return
fi
if [[ -e "${target_dir}/_shared" && ! -L "${target_dir}/_shared" ]]; then
echo " Warning: ${target_dir}/_shared exists and is not a symlink; skipping" >&2
return
fi
ln -sfn "${INSTALL_DIR}/_shared" "${target_dir}/_shared"
echo " Linked ${target_dir}/_shared -> ${INSTALL_DIR}/_shared ($SCOPE)"
}
generate_cursor_commands() {
local cmds_dir="$1"
local generated=0
for wf in "${WORKFLOWS[@]}"; do
local wf_dir="${INSTALL_DIR}/${wf}"
[[ -d "${wf_dir}/commands" ]] || continue
for cmd_file in "${wf_dir}"/commands/*.md; do
[[ -f "$cmd_file" ]] || continue
local phase
phase="$(basename "$cmd_file" .md)"
local cmd_name="${wf}-${phase}"
local description=""
if head -1 "$cmd_file" | grep -q "^---"; then
description="$(awk '/^---/{n++; next} n==1 && /^description:/{sub(/^description:[[:space:]]*"?/, ""); sub(/"[[:space:]]*$/, ""); print; exit}' "$cmd_file")"
fi
if [[ -z "$description" ]] && [[ -f "${wf_dir}/skills/${phase}.md" ]]; then
description="$(awk '/^---/{n++; next} n==1 && /^description:/{sub(/^description:[[:space:]]*"?/, ""); sub(/"[[:space:]]*$/, ""); print; exit}' "${wf_dir}/skills/${phase}.md")"
fi
[[ -z "$description" ]] && description="Run the ${phase} phase of the ${wf} workflow."
description="${description//\"/\\\"}"
cat > "${cmds_dir}/${cmd_name}.md" <<CMD_EOF
---
description: "${description}"
---
# /${phase} (${wf})
Read \`${INSTALL_DIR}/${wf}/skills/controller.md\` and follow it.
Dispatch the **${phase}** phase. Context:
\$ARGUMENTS
CMD_EOF
generated=$((generated + 1))
done
done
[[ $generated -gt 0 ]] && echo " Generated ${generated} command(s) in ${cmds_dir} ($SCOPE)"
}
install_cursor() {
if [[ "$SCOPE" == "project" ]]; then
SKILLS_DIR="${PROJECT_ROOT}/.cursor/skills"
CMDS_DIR="${PROJECT_ROOT}/.cursor/commands"
else
SKILLS_DIR="${HOME}/.cursor/skills"
CMDS_DIR="${HOME}/.cursor/commands"
fi
mkdir -p "$SKILLS_DIR" "$CMDS_DIR"
install_shared "$SKILLS_DIR"
for wf in "${WORKFLOWS[@]}"; do
ln -sfn "${INSTALL_DIR}/${wf}" "${SKILLS_DIR}/${wf}"
echo " Linked ${SKILLS_DIR}/${wf} -> ${INSTALL_DIR}/${wf} ($SCOPE)"
done
generate_cursor_commands "$CMDS_DIR"
}
install_claude() {
if [[ "$SCOPE" == "project" ]]; then
CLAUDE_DIR="${PROJECT_ROOT}/.claude"
else
CLAUDE_DIR="${HOME}/.claude"
fi
CLAUDE_MD="${CLAUDE_DIR}/CLAUDE.md"
MARKER="# ai-workflows"
mkdir -p "$CLAUDE_DIR"
if ! [[ -f "$CLAUDE_MD" ]] || ! grep -qF "$MARKER" "$CLAUDE_MD"; then
printf '\n%s\n' "$MARKER" >> "$CLAUDE_MD"
fi
for wf in "${WORKFLOWS[@]}"; do
if [[ "$SCOPE" == "project" ]]; then
LINE="For ${wf} workflows, read and follow ${INSTALL_DIR}/${wf}/SKILL.md"
else
LINE="For ${wf} workflows, read and follow ~/.ai-workflows/${wf}/SKILL.md"
fi
# Remove stale entries: old controller.md references and the alternate
# path format (~ vs expanded $HOME) to avoid duplicates when both scopes
# target the same CLAUDE.md.
STALE_LINES=(
"For ${wf} workflows, read and follow ${INSTALL_DIR}/${wf}/skills/controller.md"
"For ${wf} workflows, read and follow ~/.ai-workflows/${wf}/skills/controller.md"
"For ${wf} workflows, read and follow ${INSTALL_DIR}/${wf}/SKILL.md"
"For ${wf} workflows, read and follow ~/.ai-workflows/${wf}/SKILL.md"
)
for stale in "${STALE_LINES[@]}"; do
[[ "$stale" == "$LINE" ]] && continue
if grep -qF "$stale" "$CLAUDE_MD"; then
grep -vF "$stale" "$CLAUDE_MD" > "${CLAUDE_MD}.tmp" && mv "${CLAUDE_MD}.tmp" "$CLAUDE_MD"
echo " Replaced outdated $wf reference in $CLAUDE_MD"
fi
done
if grep -qF "$LINE" "$CLAUDE_MD"; then
echo " Reference for $wf already present in $CLAUDE_MD"
else
printf '%s\n' "$LINE" >> "$CLAUDE_MD"
echo " Added $wf reference to $CLAUDE_MD ($SCOPE)"
fi
done
# Symlink workflow directories into Claude Code's skills directory so they
# are discovered as slash commands (Claude Code scans .claude/skills/).
SKILLS_DIR="${CLAUDE_DIR}/skills"
mkdir -p "$SKILLS_DIR"
install_shared "$SKILLS_DIR"
for wf in "${WORKFLOWS[@]}"; do
ln -sfn "${INSTALL_DIR}/${wf}" "${SKILLS_DIR}/${wf}"
echo " Linked ${SKILLS_DIR}/${wf} -> ${INSTALL_DIR}/${wf} ($SCOPE)"
done
# Symlink each workflow's commands/ directory into Claude Code's commands
# directory so individual phases are discoverable as /{workflow}:{command}
# slash commands (e.g. /bugfix:assess, /cve-fix:patch).
CMDS_DIR="${CLAUDE_DIR}/commands"
mkdir -p "$CMDS_DIR"
for wf in "${WORKFLOWS[@]}"; do
if [[ -d "${INSTALL_DIR}/${wf}/commands" ]]; then
ln -sfn "${INSTALL_DIR}/${wf}/commands" "${CMDS_DIR}/${wf}"
echo " Linked ${CMDS_DIR}/${wf} -> ${INSTALL_DIR}/${wf}/commands ($SCOPE)"
elif [[ -L "${CMDS_DIR}/${wf}" ]]; then
rm -f "${CMDS_DIR}/${wf}"
echo " Removed stale commands symlink ${CMDS_DIR}/${wf} ($SCOPE)"
fi
done
}
install_gemini() {
if [[ "$SCOPE" == "project" ]]; then
SKILLS_DIR="${PROJECT_ROOT}/.gemini/skills"
else
SKILLS_DIR="${HOME}/.gemini/skills"
fi
mkdir -p "$SKILLS_DIR"
install_shared "$SKILLS_DIR"
for wf in "${WORKFLOWS[@]}"; do
ln -sfn "${INSTALL_DIR}/${wf}" "${SKILLS_DIR}/${wf}"
echo " Linked ${SKILLS_DIR}/${wf} -> ${INSTALL_DIR}/${wf} ($SCOPE)"
done
}
# --- main ---
echo "Installing ai-workflows ($TARGET, $SCOPE)..."
echo " Workflows: ${WORKFLOWS[*]}"
ensure_repo_linked
case "$TARGET" in
cursor)
install_cursor
;;
claude)
install_claude
;;
gemini)
install_gemini
;;
all)
install_cursor
install_claude
install_gemini
;;
*)
echo "Usage: $0 <cursor|claude|gemini|all> [--workflows wf1,wf2] [--project [path]]" >&2
echo "" >&2
echo "Targets:" >&2
echo " cursor Cursor skill symlinks" >&2
echo " claude Claude Code instruction references" >&2
echo " gemini Gemini CLI skill symlinks" >&2
echo " all Cursor + Claude + Gemini" >&2
echo "" >&2
echo "Options:" >&2
echo " --workflows wf1,wf2 install only the listed workflows (comma-separated)" >&2
echo " defaults to all available workflows" >&2
echo " --project [path] project-level (.cursor/skills/, .claude/, .gemini/skills/)" >&2
echo " path defaults to current directory" >&2
echo " --list list available workflows and exit" >&2
exit 1
;;
esac
echo "Done. Run 'git pull' from $INSTALL_DIR to update."