Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·277 lines (230 loc) · 9.03 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·277 lines (230 loc) · 9.03 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
#!/bin/sh
# Install biff — UNIX-style team communication for Claude Code.
# Usage:
# curl -fsSL https://raw.githubusercontent.com/punt-labs/biff/<SHA>/install.sh | sh
# curl -fsSL .../install.sh | sh -s -- --no-plugin # CLI only, skip the plugin
set -eu
usage() {
cat <<'EOF'
install.sh — install biff (CLI + Claude Code plugin)
Usage:
curl -fsSL .../install.sh | sh # install CLI and plugin
curl -fsSL .../install.sh | sh -s -- --no-plugin # install CLI only
curl -fsSL .../install.sh | BIFF_NO_PLUGIN=1 sh # install CLI only (env)
Options:
--no-plugin Install the biff CLI but skip the Claude Code plugin.
-h, --help Show this help and exit.
Environment:
BIFF_NO_PLUGIN=1 Same effect as --no-plugin (only the literal 1 is honored).
EOF
}
# --- Argument parsing (before any work) ---
SKIP_PLUGIN_REQUESTED=0
for arg in "$@"; do
case "$arg" in
--no-plugin) SKIP_PLUGIN_REQUESTED=1 ;;
-h|--help) usage; exit 0 ;;
*) printf 'install.sh: unknown option: %s\n' "$arg" >&2; usage >&2; exit 2 ;;
esac
done
if [ "${BIFF_NO_PLUGIN:-}" = "1" ]; then
SKIP_PLUGIN_REQUESTED=1
fi
# --- Colors (disabled when not a terminal) ---
if [ -t 1 ]; then
BOLD='\033[1m' GREEN='\033[32m' YELLOW='\033[33m' NC='\033[0m'
else
BOLD='' GREEN='' YELLOW='' NC=''
fi
info() { printf '%b▶%b %s\n' "$BOLD" "$NC" "$1"; }
ok() { printf ' %b✓%b %s\n' "$GREEN" "$NC" "$1"; }
warn() { printf ' %b!%b %s\n' "$YELLOW" "$NC" "$1"; }
fail() { printf ' %b✗%b %s\n' "$YELLOW" "$NC" "$1"; exit 1; }
VERSION="1.26.0"
MARKETPLACE_REPO="punt-labs/claude-plugins"
MARKETPLACE_NAME="punt-labs"
PLUGIN_NAME="biff"
PACKAGE="punt-biff"
BINARY="biff"
# --- Step 1: Prerequisites ---
#
# claude and git are required only for the Claude Code plugin. Their absence
# does not block the CLI — it auto-skips the plugin (install-cli-only.md).
info "Checking prerequisites..."
HAVE_CLAUDE=0
if command -v claude >/dev/null 2>&1; then
ok "claude CLI found"
HAVE_CLAUDE=1
else
warn "'claude' CLI not found — installing biff CLI only (plugin skipped)"
fi
HAVE_GIT=0
if command -v git >/dev/null 2>&1; then
ok "git found"
HAVE_GIT=1
else
warn "'git' not found — installing biff CLI only (plugin skipped)"
fi
# A single boolean gates the plugin steps: explicit request, env var, or a
# missing capability. There is no counter-flag to force the plugin on.
SKIP_PLUGIN=0
if [ "$SKIP_PLUGIN_REQUESTED" = "1" ] || [ "$HAVE_CLAUDE" = "0" ] || [ "$HAVE_GIT" = "0" ]; then
SKIP_PLUGIN=1
fi
# --- Step 2: uv ---
info "Checking uv..."
if command -v uv >/dev/null 2>&1; then
ok "uv already installed"
else
info "Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
if [ -f "$HOME/.local/bin/env" ]; then
# shellcheck source=/dev/null
. "$HOME/.local/bin/env"
elif [ -f "$HOME/.cargo/env" ]; then
# shellcheck source=/dev/null
. "$HOME/.cargo/env"
fi
export PATH="$HOME/.local/bin:$PATH"
if ! command -v uv >/dev/null 2>&1; then
fail "uv install succeeded but 'uv' not found on PATH. Restart your shell and re-run."
fi
ok "uv installed"
fi
# --- Step 3: Python 3.13+ ---
info "Checking Python..."
PYTHON_FLAG=""
HAVE_PYTHON=0
if command -v python3 >/dev/null 2>&1; then
PY_MAJOR=$(python3 -c 'import sys; print(sys.version_info.major)')
PY_MINOR=$(python3 -c 'import sys; print(sys.version_info.minor)')
if [ "$PY_MAJOR" -gt 3 ] || { [ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -ge 13 ]; }; then
ok "Python ${PY_MAJOR}.${PY_MINOR}"
HAVE_PYTHON=1
fi
fi
if [ "$HAVE_PYTHON" = "0" ]; then
info "Installing Python 3.13 via uv..."
uv python install 3.13 || fail "Failed to install Python 3.13"
ok "Python 3.13 (uv-managed)"
PYTHON_FLAG="--python 3.13"
fi
# --- Step 4: Install biff CLI ---
info "Installing $PACKAGE..."
# shellcheck disable=SC2086
uv tool install --force $PYTHON_FLAG "$PACKAGE==$VERSION" || fail "Failed to install $PACKAGE==$VERSION"
ok "$PACKAGE installed"
if ! command -v "$BINARY" >/dev/null 2>&1; then
export PATH="$HOME/.local/bin:$PATH"
if ! command -v "$BINARY" >/dev/null 2>&1; then
fail "$PACKAGE installed but '$BINARY' not found on PATH"
fi
fi
ok "$BINARY $(command -v "$BINARY")"
# --- Home directories (FS-8; biff install creates the same set) ---
for dir in "" active current logs sessions unread; do
path="$HOME/.punt-labs/biff${dir:+/$dir}"
[ -L "$path" ] && fail "Refusing symlinked biff home entry $path"
mkdir -p "$path"
chmod 700 "$path"
done
# --- biffd service (biff install does the same) ---
# >>> biffd service
# Exit 3 means this host has no usable service manager (a container): a note.
# Exit 4 means the service is installed and biffd is still starting: also a note.
# Any other failure is real, so it fails the script after the plugin step ran.
# A pinned release without the command is skipped, not failed.
SERVICE_STATUS=0
PROBE_STATUS=0
PROBE_ERR=$("$BINARY" daemon install --help < /dev/null 2>&1 > /dev/null) || PROBE_STATUS=$?
if [ "$PROBE_STATUS" = "0" ]; then
info "Installing the biffd service..."
"$BINARY" daemon install < /dev/null || SERVICE_STATUS=$?
case "$SERVICE_STATUS" in
0) ok "biffd service installed" ;;
3) warn "no service manager here; biffd is not supervised (start it: biff daemon serve)" ;;
4) warn "biffd service installed and still starting; see: biff daemon status" ;;
*) warn "biffd service not installed (see: biff daemon status, biff doctor)" ;;
esac
else
case "$PROBE_ERR" in
*"No such command"*)
warn "this biff release has no 'daemon install'; the biffd service is skipped" ;;
*)
# The CLI itself failed to start: that is not an old release.
SERVICE_STATUS=$PROBE_STATUS
warn "biff failed to start, so the biffd service was not installed: $PROBE_ERR" ;;
esac
fi
# <<< biffd service
# --- Steps 4-6: Claude Code plugin (skipped in CLI-only mode) ---
if [ "$SKIP_PLUGIN" = "0" ]; then
# --- Step 4: Register marketplace ---
info "Registering Punt Labs marketplace..."
if claude plugin marketplace list < /dev/null 2>/dev/null | grep -q "$MARKETPLACE_NAME"; then
ok "marketplace already registered"
claude plugin marketplace update "$MARKETPLACE_NAME" < /dev/null 2>/dev/null || true
else
claude plugin marketplace add "$MARKETPLACE_REPO" < /dev/null || fail "Failed to register marketplace"
ok "marketplace registered"
fi
# --- Step 5: SSH fallback for plugin install ---
# claude plugin install clones via SSH (git@github.com:...).
# Users without SSH keys need an HTTPS fallback.
NEED_HTTPS_REWRITE=0
cleanup_https_rewrite() {
if [ "$NEED_HTTPS_REWRITE" = "1" ]; then
git config --global --unset url."https://github.com/".insteadOf 2>/dev/null || true
NEED_HTTPS_REWRITE=0
fi
}
trap cleanup_https_rewrite EXIT INT TERM
if ! ssh -n -o StrictHostKeyChecking=accept-new -o BatchMode=yes -o ConnectTimeout=5 -T git@github.com 2>&1 | grep -q "successfully authenticated"; then
warn "SSH auth to GitHub unavailable, using HTTPS fallback"
git config --global url."https://github.com/".insteadOf "git@github.com:"
NEED_HTTPS_REWRITE=1
fi
# --- Step 6: Install plugin ---
info "Installing $PLUGIN_NAME plugin..."
claude plugin uninstall "${PLUGIN_NAME}@${MARKETPLACE_NAME}" < /dev/null 2>/dev/null || true
if ! claude plugin install "${PLUGIN_NAME}@${MARKETPLACE_NAME}" < /dev/null; then
cleanup_https_rewrite
fail "Failed to install $PLUGIN_NAME"
fi
if ! claude plugin list < /dev/null 2>/dev/null | grep -q "$PLUGIN_NAME@$MARKETPLACE_NAME"; then
cleanup_https_rewrite
fail "$PLUGIN_NAME install reported success but plugin not found"
fi
ok "$PLUGIN_NAME plugin installed"
cleanup_https_rewrite
fi
# --- Step 7: Verify ---
info "Verifying installation..."
printf '\n'
"$BINARY" doctor || true
printf '\n'
# >>> service verdict
# A real service failure fails the script, after the plugin and doctor ran.
case "$SERVICE_STATUS" in
0|3|4) ;;
*) fail "The biffd service was not installed; fix it with: biff daemon install" ;;
esac
# <<< service verdict
# --- Done ---
if [ "$SKIP_PLUGIN" = "1" ]; then
printf '%b%bbiff CLI is ready!%b\n\n' "$GREEN" "$BOLD" "$NC"
printf 'The biff CLI and MCP server are installed. Next steps:\n'
printf ' biff doctor # re-check installation health\n'
printf ' biff install # register the Claude Code plugin (machine scope)\n'
printf ' biff enable # enable biff in this checkout only\n'
printf ' biff enable --scope project # enable biff for the team: shared marker, CI workflow, and this clone'\''s git hooks\n'
printf ' biff mcp # stdio MCP server to register with your harness\n\n'
printf 'To add the Claude Code plugin later:\n'
printf ' claude plugin marketplace add %s\n' "$MARKETPLACE_REPO"
printf ' claude plugin install %s@%s\n\n' "$PLUGIN_NAME" "$MARKETPLACE_NAME"
else
printf '%b%b%s is ready!%b\n\n' "$GREEN" "$BOLD" "$PLUGIN_NAME" "$NC"
printf 'Restart Claude Code twice to activate:\n'
printf ' First restart → SessionStart hook runs setup\n'
printf ' Second restart → slash commands active (/who, /write, etc.)\n\n'
fi