forked from vellum-ai/vellum-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·270 lines (235 loc) · 9.54 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·270 lines (235 loc) · 9.54 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
#!/usr/bin/env bash
#
# setup.sh — One-time local development setup for vellum-assistant.
#
# Installs dependencies for each package, registers local packages as
# linkable, links them into the meta package, and then links the global
# `vellum` command to the local meta entry point.
#
# Usage:
# ./setup.sh
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
info() { echo "==> $*"; }
error() { echo "error: $*" >&2; exit 1; }
# ---------------------------------------------------------------------------
# Pre-flight: ensure bun is available (install automatically if missing)
# ---------------------------------------------------------------------------
# Keep this version in sync with .tool-versions (bun).
EXPECTED_BUN_VERSION="1.3.11"
if ! command -v bun &>/dev/null; then
info "Bun not found — installing bun-v${EXPECTED_BUN_VERSION} from https://bun.sh"
curl -fsSL https://bun.sh/install | bash -s "bun-v${EXPECTED_BUN_VERSION}"
# Add bun to PATH for the rest of this script
export BUN_INSTALL="${HOME}/.bun"
export PATH="${BUN_INSTALL}/bin:${PATH}"
if ! command -v bun &>/dev/null; then
error "Bun installation failed. Install it manually from https://bun.sh and try again."
fi
installed_bun_version="$(bun --version)"
info "Bun ${installed_bun_version} installed successfully"
if [ "${installed_bun_version}" != "${EXPECTED_BUN_VERSION}" ]; then
echo "warning: installed bun ${installed_bun_version} does not match expected ${EXPECTED_BUN_VERSION} (keep setup.sh and .tool-versions in sync when upgrading)" >&2
fi
fi
# ---------------------------------------------------------------------------
# Configure git to use .githooks/ for pre-commit hooks (works in worktrees)
# ---------------------------------------------------------------------------
info "Configuring git hooks"
git config core.hooksPath .githooks
# ---------------------------------------------------------------------------
# Install dependencies and register local packages as linkable
# ---------------------------------------------------------------------------
for dir in cli gateway assistant credential-executor evals; do
info "Installing dependencies in ${dir}/"
(cd "${REPO_ROOT}/${dir}" && bun install)
info "Registering ${dir}/ as a linkable package"
(cd "${REPO_ROOT}/${dir}" && bun link)
done
# ---------------------------------------------------------------------------
# Install dependencies for scripts/
# ---------------------------------------------------------------------------
info "Installing dependencies in scripts/"
(cd "${REPO_ROOT}/scripts" && bun install)
# ---------------------------------------------------------------------------
# Install dependencies for packages in packages/
# ---------------------------------------------------------------------------
for dir in "${REPO_ROOT}"/packages/*/; do
[ -f "${dir}/package.json" ] || continue
pkg="$(basename "${dir}")"
info "Installing dependencies in packages/${pkg}/"
(cd "${dir}" && bun install)
done
# ---------------------------------------------------------------------------
# Install dependencies for skills that have their own package.json
#
# assistant/src/daemon/external-skills-bootstrap.ts statically imports
# skills/meet-join/register.ts, so `tsc --noEmit` in assistant/ follows the
# import into the skill and needs the skill's own node_modules to resolve
# transitive imports. Missing deps surface as false-positive "Cannot find
# module" errors.
# ---------------------------------------------------------------------------
for dir in "${REPO_ROOT}"/skills/*/; do
[ -f "${dir}/package.json" ] || continue
pkg="$(basename "${dir}")"
info "Installing dependencies in skills/${pkg}/"
(cd "${dir}" && bun install)
done
# ---------------------------------------------------------------------------
# Link local packages into meta so it resolves to local source
# ---------------------------------------------------------------------------
info "Linking local packages into meta/"
(cd "${REPO_ROOT}/meta" && bun link @vellumai/cli @vellumai/assistant @vellumai/vellum-gateway @vellumai/credential-executor)
# ---------------------------------------------------------------------------
# Link the global `vellum` command to this repo's meta package
# ---------------------------------------------------------------------------
info "Linking global 'vellum' command to meta/"
(cd "${REPO_ROOT}/meta" && bun link)
# ---------------------------------------------------------------------------
# Install shell completions for the `vellum` command
# ---------------------------------------------------------------------------
info "Installing shell completions for vellum"
VELLUM_COMP_DIR="${HOME}/.config/vellum/completions"
mkdir -p "${VELLUM_COMP_DIR}"
LOCKFILE_PATH="${HOME}/.vellum.lock.json"
LOCKFILE_GREP="grep -o '\"assistantId\"[[:space:]]*:[[:space:]]*\"[^\"]*\"' ${LOCKFILE_PATH} 2>/dev/null | awk -F'\"' '{print \$(NF-1)}'"
# — Bash completions —
cat > "${VELLUM_COMP_DIR}/completions.bash" << 'BASH_COMP'
_vellum_completions() {
local cur prev commands
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
commands="client hatch ps retire sleep wake"
if [[ ${COMP_CWORD} -eq 1 ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
return 0
fi
case "${COMP_WORDS[1]}" in
hatch)
COMPREPLY=( $(compgen -W "openclaw vellum -d --name --remote" -- "${cur}") )
;;
client|retire)
local instances
BASH_COMP
# Append the dynamic lockfile lookup (needs variable expansion)
cat >> "${VELLUM_COMP_DIR}/completions.bash" << BASH_COMP_DYN
instances="\$(${LOCKFILE_GREP} | tr '\n' ' ')"
BASH_COMP_DYN
cat >> "${VELLUM_COMP_DIR}/completions.bash" << 'BASH_COMP_END'
COMPREPLY=( $(compgen -W "${instances}" -- "${cur}") )
;;
esac
return 0
}
complete -F _vellum_completions vellum
BASH_COMP_END
# — Zsh completions —
cat > "${VELLUM_COMP_DIR}/completions.zsh" << 'ZSH_COMP'
_vellum() {
local -a commands
commands=(
'client'
'hatch'
'ps'
'retire'
'sleep'
'wake'
)
_arguments -C \
'1:command:->command' \
'*::arg:->args'
case $state in
command)
_describe 'command' commands
;;
args)
case $words[1] in
hatch)
_arguments '*:species:(openclaw vellum -d --name --remote)'
;;
client|retire)
local -a instances
ZSH_COMP
# Append the dynamic lockfile lookup (needs variable expansion)
cat >> "${VELLUM_COMP_DIR}/completions.zsh" << ZSH_COMP_DYN
instances=(\${(f)"\$(${LOCKFILE_GREP})"})
ZSH_COMP_DYN
cat >> "${VELLUM_COMP_DIR}/completions.zsh" << 'ZSH_COMP_END'
_describe 'instance' instances
;;
esac
;;
esac
}
compdef _vellum vellum
ZSH_COMP_END
# ---------------------------------------------------------------------------
# Wire up PATH + completions in shell rc files.
#
# nix / home-manager manage ~/.zshrc (and friends) as read-only symlinks into
# the nix store. When the canonical rc isn't writable, fall back to a writable
# "*.local" escape hatch it already sources (e.g. ~/.zshrc sources
# ~/.zshenv.local) so our additions still load. If no hatch is found we use a
# "<rc>.local" sidecar and tell the user to source it from their config.
# ---------------------------------------------------------------------------
BUN_BIN="${HOME}/.bun/bin"
# Echo the writable file to append to for a given canonical rc.
rc_target() {
local rc="$1"
if [ -w "$rc" ]; then
printf '%s' "$rc"
return
fi
# Read-only rc (nix symlink): reuse a "source ~/...local" hatch it already
# sources; otherwise fall back to a "<rc>.local" sidecar.
local hatch
hatch="$(sed -n 's/.*source[[:space:]]*\(~[^ ;&]*\.local\).*/\1/p' "$rc" 2>/dev/null | head -1)"
if [ -n "$hatch" ]; then
printf '%s' "${hatch/#\~/$HOME}"
else
printf '%s' "${rc}.local"
fi
}
# Warn if our chosen target isn't actually sourced by the canonical rc.
warn_unsourced() {
local rc="$1" target="$2"
[ "$rc" = "$target" ] && return
if ! grep -qF "$(basename "$target")" "$rc" 2>/dev/null; then
echo "warning: ${rc} is read-only and does not source ${target}." >&2
echo " Add this to your shell config so completions load:" >&2
echo " [[ -f ${target} ]] && source ${target}" >&2
fi
}
# — Ensure ~/.bun/bin is on PATH in shell rc files —
for rc in "${HOME}/.bashrc" "${HOME}/.zshrc"; do
[ -e "$rc" ] || continue
target="$(rc_target "$rc")"
warn_unsourced "$rc" "$target"
[ -e "$target" ] || touch "$target"
if ! grep -qF "${BUN_BIN}" "$target"; then
printf '\nexport PATH="%s:$PATH"\n' "${BUN_BIN}" >> "$target"
fi
done
# — Source completions from shell rc files —
if [ -e "${HOME}/.bashrc" ]; then
target="$(rc_target "${HOME}/.bashrc")"
[ -e "$target" ] || touch "$target"
if ! grep -qF '.config/vellum/completions/completions.bash' "$target"; then
printf '\n# vellum completions\nsource ~/.config/vellum/completions/completions.bash\n' >> "$target"
fi
fi
if [ -e "${HOME}/.zshrc" ]; then
target="$(rc_target "${HOME}/.zshrc")"
[ -e "$target" ] || touch "$target"
if ! grep -qF '.config/vellum/completions/completions.zsh' "$target"; then
# The escape hatch may be sourced before compinit defines `compdef`, so
# ensure the completion system is initialized before sourcing.
{
printf '\n# vellum completions\n'
printf 'if ! whence compdef >/dev/null 2>&1; then autoload -Uz compinit && compinit; fi\n'
printf 'source ~/.config/vellum/completions/completions.zsh\n'
} >> "$target"
fi
fi
info "Setup complete! Run 'vellum --version' to verify."