Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·328 lines (300 loc) · 12.8 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·328 lines (300 loc) · 12.8 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
#!/bin/sh
# Kiro Crew first-time setup script (public build, contributor / from-source layout)
# Usage: source setup.sh (bash or zsh), or: bash setup.sh
#
# Builds the clone it sits in, so the install follows the clone's branch (`main`
# is the Nightly lane). For Stable on a laptop or server, use the signed wheel:
# curl -fsSL https://download.crew.kiro.dev/cli.sh | sh
#
# Sets up KiroCrew using only public tooling:
# 1. Node.js (via ensure-node.sh)
# 2. Optional tools (git-lfs, ffmpeg for voice)
# 3. Optional ACP adapter + Kiro CLI prerequisite disclosure
# 4. Build frontend (npm/vite) + backend (pip)
# 5. PATH config
# 6. Agent config (kirocrew setup --agent-only)
# Resolve script directory (works in bash and zsh, sourced or executed)
if [ -n "$BASH_SOURCE" ]; then
_kirocrew_dir="$(cd "$(dirname "$BASH_SOURCE")" && pwd)"
elif [ -n "$ZSH_VERSION" ]; then
_kirocrew_dir="$(cd "$(dirname "${(%):-%x}")" && pwd)"
else
_kirocrew_dir="$(pwd)"
fi
cd "$_kirocrew_dir" || return 1
# ACP_NPM_PKG and acp_adapter_spec (the exact pinned version).
# shellcheck source=scripts/lib/acp-adapter-pin.sh
. "$_kirocrew_dir/scripts/lib/acp-adapter-pin.sh"
echo "👻 KiroCrew Setup"
echo ""
# ── Ensure PATH includes common install locations ──
[ -d "$HOME/.local/bin" ] && export PATH="$HOME/.local/bin:$PATH"
if [ -s "$HOME/.nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
# shellcheck disable=SC1091
. "$NVM_DIR/nvm.sh"
fi
# ── Helper ──
_check() {
command -v "$1" >/dev/null 2>&1
}
# ── 1. Python ──
echo "── Step 1: Python ──"
_py=""
for _candidate in python3.12 python3.13 python3; do
if _check "$_candidate" && "$_candidate" -c "import sys; assert sys.version_info >= (3,12)" 2>/dev/null; then
_py="$_candidate"
break
fi
done
# See cloud-install.sh's _has_provisioner: the automatic fallback may use a
# version manager that is already installed, and may never install one, because
# ensure-python.sh would do that by piping a remote script into sh.
_has_provisioner() {
command -v mise >/dev/null 2>&1 || [ -x "$HOME/.local/bin/mise" ]
}
if [ -z "$_py" ] && [ -f "$_kirocrew_dir/ensure-python.sh" ] && _has_provisioner; then
# Runs from a clone, so the repo's own bootstrap is available: provision
# 3.12 rather than stopping on a distro whose archive cannot supply it.
echo " → No system Python 3.12+; provisioning one via ensure-python.sh…"
bash "$_kirocrew_dir/ensure-python.sh" >/dev/null 2>&1 || true
_recorded="$(cat "${KIROCREW_HOME:-$HOME/.kiro/crew}/python-bin" 2>/dev/null || true)"
if [ -n "$_recorded" ] && [ -x "$_recorded" ] \
&& "$_recorded" -c "import sys; assert sys.version_info >= (3,12)" 2>/dev/null; then
_py="$_recorded"
fi
fi
if [ -z "$_py" ]; then
echo " ❌ Python 3.12+ required and could not be provisioned."
echo " Install Python 3.12+ (https://www.python.org/downloads/), or install mise"
echo " (https://mise.jdx.dev/installing-mise.html) and re-run — this script will"
echo " then provision Python 3.12 through it."
cd - > /dev/null 2>&1
return 1 2>/dev/null || exit 1
fi
echo " ✅ $($_py --version 2>&1) ($(which "$_py"))"
echo ""
# ── 2. Node.js + optional tools ──
echo "── Step 2: Dependencies ──"
# Node.js (>= 22.12 required for the website build; 24 LTS recommended)
if [ -x "$_kirocrew_dir/ensure-node.sh" ]; then
bash "$_kirocrew_dir/ensure-node.sh"
# Re-source managers so newly-installed node lands on PATH
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
if [ -f "$HOME/.local/bin/mise" ]; then
eval "$("$HOME/.local/bin/mise" activate bash 2>/dev/null)" 2>/dev/null || true
elif command -v mise >/dev/null 2>&1; then
eval "$(mise activate bash 2>/dev/null)" 2>/dev/null || true
fi
# On a host where no version manager can serve a supported Node -- Amazon
# Linux 2, whose glibc 2.26 cannot load the official builds -- ensure-node.sh
# installs a private toolchain that neither nvm nor mise owns, so the
# re-sourcing above cannot surface it. It records the directory it settled on;
# consume that marker the way the Makefile and kiro_crew.env.node_bin_dirs()
# already do. Without this the checks below miss the node just installed and
# the frontend build plus the agent-backend install are skipped.
_nbd="$(cat "${KIROCREW_HOME:-$HOME/.kiro/crew}/node-bin-dir" 2>/dev/null || true)"
if [ -n "$_nbd" ] && [ -x "$_nbd/node" ]; then
export PATH="$_nbd:$PATH"
fi
unset _nbd
if _check node; then
echo " ✅ node ($(which node))"
else
echo " ⚠️ node not found after ensure-node.sh — run: bash ensure-node.sh"
fi
elif _check node; then
echo " ✅ node ($(which node))"
else
echo " ⚠️ node not found — run: bash ensure-node.sh"
fi
# Git LFS: optional, used if any LFS-tracked assets are added
if ! git lfs version >/dev/null 2>&1; then
if [ "$(uname)" = "Darwin" ] && _check brew; then
echo " → Installing git-lfs..."
brew install git-lfs >/dev/null 2>&1 || true
if git lfs version >/dev/null 2>&1; then
git lfs install >/dev/null 2>&1
echo " ✅ git-lfs installed and initialized"
else
echo " ⚠️ git-lfs install failed — run manually: brew install git-lfs && git lfs install"
fi
else
echo " ⚠️ git-lfs not found (optional) — install via your package manager if needed"
fi
else
if ! git config --global filter.lfs.smudge >/dev/null 2>&1; then
git lfs install >/dev/null 2>&1 && echo " ✅ git-lfs ($(git lfs version 2>/dev/null | head -1))" \
|| echo " ⚠️ git-lfs filter init failed — run: git lfs install"
else
echo " ✅ git-lfs ($(git lfs version 2>/dev/null | head -1))"
fi
fi
# ffmpeg: needed for voice input (whisper) and MP3 stitching
if ! _check ffmpeg; then
if [ "$(uname)" = "Darwin" ] && _check brew; then
echo " → Installing ffmpeg..."
brew install ffmpeg >/dev/null 2>&1 || true
_check ffmpeg && echo " ✅ ffmpeg installed" \
|| echo " ⚠️ ffmpeg install failed — run manually: brew install ffmpeg"
else
echo " ⚠️ ffmpeg not found (optional, for voice) — install via your package manager"
fi
fi
echo ""
# ── 3. Optional ACP adapter and Kiro CLI prerequisite ──
echo "── Step 3: Agent Backends ──"
if _check claude-agent-acp; then
echo " ✅ claude-agent-acp ($(which claude-agent-acp))"
elif _check npm; then
if ! ACP_NPM_SPEC="$(acp_adapter_spec "$_kirocrew_dir")"; then
echo " ⚠️ Could not read the pinned $ACP_NPM_PKG version (packaging/acp-adapters/package.json) — skipping"
else
echo " → Installing $ACP_NPM_SPEC via npm..."
if npm install -g "$ACP_NPM_SPEC" >/dev/null 2>&1; then
echo " ✅ claude-agent-acp installed"
else
echo " ⚠️ npm i -g $ACP_NPM_SPEC failed — install it manually before selecting this backend"
fi
fi
else
echo " ⚠️ npm not found — install the optional agent backend later:"
echo " npm i -g $ACP_NPM_PKG"
fi
if _check kiro-cli; then
echo " ✅ kiro-cli ($(which kiro-cli))"
else
echo " ⚠️ Kiro CLI is required for the default agent."
echo " Install it separately from https://kiro.dev/cli/"
fi
echo " Sign in separately with: kiro-cli login"
echo " This script does not install Kiro CLI or handle sign-in."
echo ""
# ── 4. Build (npm/vite frontend + pip backend) ──
echo "── Step 4: Build ──"
# Frontend: vite emits to website/dist; stage into src/kiro_crew/static/dist
if _check node && [ -d "$_kirocrew_dir/website" ]; then
echo "→ Building frontend (website/)..."
if (cd "$_kirocrew_dir/website" \
&& { [ -f package-lock.json ] && npm ci --no-audit --no-fund --loglevel=error \
|| npm install --no-audit --no-fund --loglevel=error; } \
&& npm run build); then
_dist_src="$_kirocrew_dir/website/dist"
_dist_dst="$_kirocrew_dir/src/kiro_crew/static/dist"
if [ -d "$_dist_src" ]; then
rm -rf "$_dist_dst"
mkdir -p "$(dirname "$_dist_dst")"
cp -R "$_dist_src" "$_dist_dst"
echo " ✅ Frontend built and staged → src/kiro_crew/static/dist"
else
echo " ⚠️ website/dist not found after build — dashboard will use legacy fallback"
fi
else
echo " ⚠️ Frontend build failed — dashboard will use legacy fallback"
fi
else
echo " ⚠️ Skipping frontend build (node or website/ not available)"
fi
# Backend: venv + pip install -e .
_venv="$_kirocrew_dir/.venv"
# Build the venv under a umask that masks group/other WRITE so bin/kirocrew
# and its dirs are born non-group-writable -- `kirocrew service install`
# refuses to attach its AppArmor profile to a group/world-writable launcher
# (see the matching block in cli.sh for the full rationale). OR-ing with 022
# only ADDS write-mask bits, so a stricter caller umask is preserved.
_KC_PREV_UMASK="$(umask)"
umask "$(printf '%03o' "$(( $(umask) | 022 ))")"
# A reused venv keeps the perms it was born with: one built by an older installer
# under a permissive umask still has a group/world-writable root or bin/, so the
# AppArmor profile would keep refusing. Rebuild it under the tightened umask.
if [ -d "$_venv" ] && [ -n "$(find "$_venv" "$_venv/bin" -prune \( -perm -g+w -o -perm -o+w \) -print 2>/dev/null)" ]; then
echo "→ Recreating virtual environment (existing one is group/world-writable)..."
rm -rf "$_venv"
fi
# Same requires-python reuse rule as install.sh: a pre-3.12 venv cannot host the
# package, so rebuild rather than pip-install into it and hit a hard refusal.
if [ ! -d "$_venv" ] || [ ! -x "$_venv/bin/python" ] \
|| ! "$_venv/bin/python" -c "import sys; sys.exit(0 if sys.version_info >= (3, 12) else 1)" 2>/dev/null; then
if [ -d "$_venv" ]; then
echo "→ Recreating virtual environment (existing interpreter < 3.12)..."
rm -rf "$_venv"
else
echo "→ Creating virtual environment..."
fi
"$_py" -m venv "$_venv" || {
echo " ❌ Failed to create venv"
umask "$_KC_PREV_UMASK"
cd - > /dev/null 2>&1
return 1 2>/dev/null || exit 1
}
fi
echo "→ Installing kirocrew (pip)..."
"$_venv/bin/pip" install --upgrade pip setuptools wheel -q 2>/dev/null || true
if KIROCREW_SKIP_FRONTEND=1 "$_venv/bin/pip" install -e "$_kirocrew_dir" -q; then
echo " ✅ Build succeeded"
# Record install method for tooling that branches on it
echo "pip" > "$_kirocrew_dir/.install-method"
umask "$_KC_PREV_UMASK"
else
echo " ❌ pip install failed"
umask "$_KC_PREV_UMASK"
cd - > /dev/null 2>&1
return 1 2>/dev/null || exit 1
fi
# Symlink CLI so `kirocrew` works on PATH
mkdir -p "$HOME/.local/bin"
ln -sf "$_venv/bin/kirocrew" "$HOME/.local/bin/kirocrew"
if _check kirocrew; then
echo " ✅ kirocrew command available ($(which kirocrew))"
else
echo " ✅ kirocrew symlinked → ~/.local/bin/kirocrew (restart shell or fix PATH in Step 5)"
fi
echo ""
# ── 5. PATH ──
echo "── Step 5: PATH ──"
export PATH="$HOME/.local/bin:$PATH"
echo "→ ~/.local/bin added to PATH"
_path_line="export PATH=\"\$HOME/.local/bin:\$PATH\""
_add_to_rc() {
_rc="$1"
if [ ! -f "$_rc" ]; then return; fi
if grep -qF "$_path_line" "$_rc" 2>/dev/null; then
echo " ✅ Already in $_rc"
return
fi
# Remove any old KiroCrew PATH entry and replace with current
if grep -qF "KiroCrew" "$_rc" 2>/dev/null; then
sed -i.bak '/# KiroCrew/d;/KiroCrew.*bin/d;/\.local\/bin/d' "$_rc"
rm -f "${_rc}.bak"
fi
printf "→ Add ~/.local/bin to PATH permanently in %s? [Y/n] " "$_rc"
read _answer
case "${_answer:-Y}" in
[Yy]*)
echo "" >> "$_rc"
echo "# KiroCrew" >> "$_rc"
echo "$_path_line" >> "$_rc"
echo " ✅ Added to $_rc"
;;
esac
}
_add_to_rc "$HOME/.bashrc"
_add_to_rc "$HOME/.zshrc"
echo ""
# ── 6. Install agent config ──
echo "── Step 6: Agent Config ──"
echo "→ Installing agent config..."
KIROCREW_PROJECT_DIR="$_kirocrew_dir" kirocrew setup --agent-only \
|| echo " ⚠️ kirocrew setup --agent-only failed (run manually later)"
echo ""
echo "👻 Setup complete!"
echo ""
echo " kirocrew doctor # verify everything"
echo " kirocrew gateway # start dashboard + gateway"
echo " kirocrew chat # interactive chat"
echo ""
echo " Optional — local vector memory (embeddings):"
echo " Install ollama (https://ollama.com), then: ollama pull qwen3-embedding:0.6b"
# Cleanup
cd - > /dev/null 2>&1