-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·117 lines (100 loc) · 3.66 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·117 lines (100 loc) · 3.66 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
#!/usr/bin/env bash
# install.sh — install the Claude Code Toolkit into ~/.claude/.
# Idempotent: re-running upgrades in place. Backs up anything it overwrites.
# Usage: bash install.sh # install / upgrade
# bash install.sh --uninstall
set -euo pipefail
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
CLAUDE_DIR="${CLAUDE_DIR:-$HOME/.claude}"
SETTINGS="$CLAUDE_DIR/settings.json"
CLAUDEMD="$CLAUDE_DIR/CLAUDE.md"
TS="$(date +%Y%m%d-%H%M%S)"
BACKUP="$CLAUDE_DIR/.toolkit-backup-$TS"
command -v jq >/dev/null 2>&1 || { echo "Error: jq is required. Install with: brew install jq"; exit 1; }
mkdir -p "$CLAUDE_DIR/skills" "$CLAUDE_DIR/agents" "$CLAUDE_DIR/hooks"
backup() {
local src="$1"
[ -e "$src" ] || return 0
mkdir -p "$BACKUP"
cp -R "$src" "$BACKUP/"
}
uninstall() {
echo "Uninstalling Claude Code Toolkit..."
for s in my-ship-it my-tidy my-council; do
rm -rf "$CLAUDE_DIR/skills/$s"
done
for a in my-code-reviewer my-refactor-surgeon my-test-writer; do
rm -f "$CLAUDE_DIR/agents/$a.md"
done
for h in pre-edit-guard.sh post-edit-format.sh pre-bash-safety.sh stop-summary.sh; do
rm -f "$CLAUDE_DIR/hooks/$h"
done
if [ -f "$SETTINGS" ]; then
backup "$SETTINGS"
tmp="$(mktemp)"
jq 'del(.hooks)' "$SETTINGS" > "$tmp" && mv "$tmp" "$SETTINGS"
echo " removed hooks block from $SETTINGS"
fi
echo "Done. CLAUDE.md ruleset left intact — delete by hand if desired."
exit 0
}
[ "${1:-}" = "--uninstall" ] && uninstall
echo "Installing Claude Code Toolkit into $CLAUDE_DIR ..."
# 1. Skills
for s in my-ship-it my-tidy my-council; do
dst="$CLAUDE_DIR/skills/$s"
[ -e "$dst" ] && backup "$dst" && rm -rf "$dst"
cp -R "$REPO_DIR/skills/$s" "$dst"
echo " installed skill: $s"
done
# 2. Agents
for a in my-code-reviewer my-refactor-surgeon my-test-writer; do
dst="$CLAUDE_DIR/agents/$a.md"
[ -e "$dst" ] && backup "$dst"
cp "$REPO_DIR/agents/$a.md" "$dst"
echo " installed agent: $a"
done
# 3. Hooks
for h in pre-edit-guard.sh post-edit-format.sh pre-bash-safety.sh stop-summary.sh; do
dst="$CLAUDE_DIR/hooks/$h"
[ -e "$dst" ] && backup "$dst"
cp "$REPO_DIR/hooks/$h" "$dst"
chmod +x "$dst"
echo " installed hook: $h"
done
# 4. Append CLAUDE.md ruleset (if not already present)
SNIPPET="$REPO_DIR/docs/CLAUDE-snippet.md"
if [ ! -f "$CLAUDEMD" ] || ! grep -q "^# Code quality defaults" "$CLAUDEMD" 2>/dev/null; then
[ -f "$CLAUDEMD" ] && backup "$CLAUDEMD"
printf '\n' >> "$CLAUDEMD"
cat "$SNIPPET" >> "$CLAUDEMD"
echo " appended Code-Quality-Defaults to $CLAUDEMD"
else
echo " CLAUDE.md already has the ruleset — skipped"
fi
# 5. Register hooks in settings.json
[ -f "$SETTINGS" ] || echo '{}' > "$SETTINGS"
backup "$SETTINGS"
HOOKS_JSON=$(cat <<'JSON'
{
"PreToolUse": [
{ "matcher": "Edit|Write|MultiEdit", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/pre-edit-guard.sh" }] },
{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/pre-bash-safety.sh" }] }
],
"PostToolUse": [
{ "matcher": "Edit|Write|MultiEdit", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/post-edit-format.sh" }] }
],
"Stop": [
{ "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/stop-summary.sh" }] }
]
}
JSON
)
# Resolve ~ in commands to the user's home so the harness can exec them.
HOOKS_JSON="$(printf '%s' "$HOOKS_JSON" | sed "s|~/.claude|$CLAUDE_DIR|g")"
tmp="$(mktemp)"
jq --argjson new "$HOOKS_JSON" '.hooks = $new' "$SETTINGS" > "$tmp" && mv "$tmp" "$SETTINGS"
echo " registered hooks in $SETTINGS"
echo ""
echo "Done. Backups (if any) at: $BACKUP"
echo "Restart Claude Code, then try: /my-ship-it, /my-tidy, /my-council"