-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·311 lines (276 loc) · 9.23 KB
/
install.sh
File metadata and controls
executable file
·311 lines (276 loc) · 9.23 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
#!/usr/bin/env bash
#
# Better-Work Series Installer
#
# Non-interactive, parameter-driven installer for the Better-Work skill series.
# Works on macOS and Linux. For Windows users, see the Manual Install section
# of README.md.
#
# Usage:
# install.sh [OPTIONS]
#
# Examples:
# ./install.sh # Install better-work only
# ./install.sh --with code --with test # Install full series
# ./install.sh --update # Pull latest for all installed
# ./install.sh --uninstall # Remove ~/.claude/skills/ symlinks
#
set -euo pipefail
INSTALL_DIR="${HOME}/.better-work-series"
SKILLS_DIR="${HOME}/.claude/skills"
CLAUDE_MD_GLOBAL="${HOME}/.claude/CLAUDE.md"
VERSION=""
MODE="install"
WITH_SUBSKILLS=()
SKIP_PROTOCOL=0
PROTOCOL_SCOPE="global"
# Each entry: name|repo-url
SKILL_REPOS=(
"better-work|https://github.com/d-wwei/better-work.git"
"better-code|https://github.com/d-wwei/better-code.git"
"better-test|https://github.com/d-wwei/better-test.git"
)
# Companion skill: reflect-and-refine provides a Stop-hook adversarial
# reviewer. Opt-in via --with reflect-and-refine. When present, installed
# series skills are auto-registered so their invocation opens the gate.
RAR_REPO_URL="https://github.com/d-wwei/reflect-and-refine.git"
usage() {
cat <<EOF
Usage: install.sh [OPTIONS]
Install, update, or uninstall the Better-Work skill series.
OPTIONS:
--with <subskill> Install subskill (valid: code, test, reflect-and-refine).
Repeat for multiple. Default: better-work only.
reflect-and-refine is an adversarial completion-review
Stop-hook companion; opt-in only because it edits your
~/.claude/ft-settings.json (or settings.json).
--install-dir <path> Install location. Default: ${HOME}/.better-work-series/
--version <tag> Check out specific tag (e.g. v1.3.0). Default: main.
--skip-protocol Do NOT inject protocol.md reference into CLAUDE.md.
--protocol-scope=project Inject into \$PWD/CLAUDE.md instead of global.
--protocol-scope=global (default) Inject into ~/.claude/CLAUDE.md.
--update git pull the main branch for all installed skills.
--uninstall Remove symlinks from ~/.claude/skills/. Source repos
are preserved in --install-dir.
--help, -h Show this help.
EXAMPLES:
./install.sh
./install.sh --with code --with test
./install.sh --with code --version v1.3.0
./install.sh --update
./install.sh --uninstall
REPORT ISSUES:
https://github.com/d-wwei/better-work/issues
EOF
}
log() { echo "[install.sh] $*"; }
die() { echo "[install.sh] ERROR: $*" >&2; exit 1; }
while [[ $# -gt 0 ]]; do
case "$1" in
--with)
[[ $# -ge 2 ]] || die "--with requires an argument (code|test)"
WITH_SUBSKILLS+=("$2")
shift 2
;;
--install-dir)
[[ $# -ge 2 ]] || die "--install-dir requires a path"
INSTALL_DIR="$2"
shift 2
;;
--version)
[[ $# -ge 2 ]] || die "--version requires a tag"
VERSION="$2"
shift 2
;;
--skip-protocol)
SKIP_PROTOCOL=1
shift
;;
--protocol-scope=project)
PROTOCOL_SCOPE="project"
shift
;;
--protocol-scope=global)
PROTOCOL_SCOPE="global"
shift
;;
--update)
MODE="update"
shift
;;
--uninstall)
MODE="uninstall"
shift
;;
--help|-h)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage
exit 1
;;
esac
done
# Require git
command -v git >/dev/null 2>&1 || die "git is required but not found"
# Validate --with is only meaningful in install mode (S2: fail-fast to catch
# user intent mismatch rather than silently drop the intent)
if [[ "$MODE" != "install" && ${#WITH_SUBSKILLS[@]} -gt 0 ]]; then
die "--with is not allowed in ${MODE} mode (applies only to install). Remove --with and re-run."
fi
mkdir -p "$INSTALL_DIR" "$SKILLS_DIR"
install_one() {
local name="$1" url="$2"
local target="${INSTALL_DIR}/${name}"
local link symlink_src
case "$name" in
better-work)
link="${SKILLS_DIR}/better-work"
symlink_src="${target}/skills/better-work"
;;
*)
link="${SKILLS_DIR}/${name}"
symlink_src="${target}"
;;
esac
if [[ ! -d "${target}/.git" ]]; then
log "Cloning ${name} into ${target}"
git clone "$url" "$target"
else
log "${name} already cloned at ${target}; skipping clone"
fi
if [[ -n "$VERSION" ]]; then
log "Checking out ${VERSION} in ${target}"
(cd "$target" && git fetch --tags --quiet && git checkout "$VERSION")
fi
log "Linking ${link} -> ${symlink_src}"
ln -sfn "$symlink_src" "$link"
}
update_one() {
local name="$1"
local target="${INSTALL_DIR}/${name}"
if [[ -d "${target}/.git" ]]; then
log "Updating ${name}"
(cd "$target" && git pull --ff-only)
else
log "${name} not installed at ${target}; skip"
fi
}
uninstall_one() {
local name="$1"
local link="${SKILLS_DIR}/${name}"
if [[ -L "$link" ]]; then
log "Removing symlink ${link}"
rm "$link"
elif [[ -e "$link" ]]; then
log "WARN: ${link} exists but is not a symlink (likely a manual install)."
log " NOT removing. Inspect and remove manually if needed."
else
log "${link} does not exist; skip"
fi
}
install_reflect_and_refine() {
# Clone reflect-and-refine alongside better-work, then run its installer
# with the installed series skills as registered parents. Idempotent —
# rerunning is safe (installer does its own dedup + backup).
local target="${INSTALL_DIR}/reflect-and-refine"
if [[ ! -d "${target}/.git" ]]; then
log "Cloning reflect-and-refine into ${target}"
git clone "$RAR_REPO_URL" "$target"
else
log "reflect-and-refine already cloned at ${target}; skipping clone"
fi
if [[ -n "$VERSION" ]]; then
log "Checking out ${VERSION} in ${target}"
(cd "$target" && git fetch --tags --quiet && git checkout "$VERSION")
fi
if [[ ! -x "${target}/install.sh" ]]; then
log "WARN: ${target}/install.sh not executable or missing; skipping RAR configure"
return
fi
# Registered parents = the series skills we've actually installed this run.
local -a registered=("better-work")
for sub in "${WITH_SUBSKILLS[@]:-}"; do
case "$sub" in
code) registered+=("better-code") ;;
test) registered+=("better-test") ;;
esac
done
log "Configuring reflect-and-refine (register: ${registered[*]})"
"${target}/install.sh" --register "${registered[@]}"
}
inject_protocol() {
# Inject in tilde-form for portability (different users have different $HOME).
# On grep, check both tilde-form and expanded-form to be idempotent against
# historical installs that used the expanded-path form (N1 fix).
local ref_inject="@~/.claude/skills/better-work/protocol.md"
local ref_expanded="@${HOME}/.claude/skills/better-work/protocol.md"
local target_file
if [[ "$PROTOCOL_SCOPE" == "project" ]]; then
target_file="$(pwd)/CLAUDE.md"
else
target_file="$CLAUDE_MD_GLOBAL"
fi
mkdir -p "$(dirname "$target_file")"
[[ -f "$target_file" ]] || touch "$target_file"
if grep -qF "$ref_inject" "$target_file" 2>/dev/null \
|| grep -qF "$ref_expanded" "$target_file" 2>/dev/null; then
log "Protocol ref already present in ${target_file} (tilde or expanded form); skip inject"
else
log "Injecting protocol ref into ${target_file}"
{
echo ""
echo "$ref_inject"
} >> "$target_file"
fi
}
case "$MODE" in
install)
install_one "better-work" "https://github.com/d-wwei/better-work.git"
WITH_RAR=0
for sub in "${WITH_SUBSKILLS[@]:-}"; do
[[ -z "$sub" ]] && continue
case "$sub" in
code) install_one "better-code" "https://github.com/d-wwei/better-code.git" ;;
test) install_one "better-test" "https://github.com/d-wwei/better-test.git" ;;
reflect-and-refine|rar) WITH_RAR=1 ;; # defer: need to know which subskills got installed
*) die "Unknown subskill: ${sub} (valid: code, test, reflect-and-refine)" ;;
esac
done
if [[ $WITH_RAR -eq 1 ]]; then
install_reflect_and_refine
fi
if [[ $SKIP_PROTOCOL -eq 0 ]]; then
inject_protocol
else
log "Skipping protocol injection (--skip-protocol)"
fi
log "Install complete."
log "Verify: ls -la ${SKILLS_DIR}"
log "Next: open a new Claude Code session and use /better-work"
;;
update)
for entry in "${SKILL_REPOS[@]}"; do
update_one "${entry%%|*}"
done
if [[ -d "${INSTALL_DIR}/reflect-and-refine/.git" ]]; then
update_one "reflect-and-refine"
fi
log "Update complete."
;;
uninstall)
for entry in "${SKILL_REPOS[@]}"; do
uninstall_one "${entry%%|*}"
done
log "Uninstall complete. Source repos preserved at ${INSTALL_DIR}."
log "To fully remove sources: rm -rf ${INSTALL_DIR}"
if [[ -d "${INSTALL_DIR}/reflect-and-refine/.git" ]]; then
log ""
log "Note: reflect-and-refine is still installed (hook still active)."
log "To remove it too: ${INSTALL_DIR}/reflect-and-refine/uninstall.sh"
log "Then restart Claude Code for the hook removal to take effect."
fi
;;
esac