-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·293 lines (251 loc) · 9.48 KB
/
install.sh
File metadata and controls
executable file
·293 lines (251 loc) · 9.48 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
#!/usr/bin/env bash
#
# Snowflake AI Kit — Installer
#
# Installs Snowflake CLI (snow), Cortex Code CLI (cortex), and optionally
# Claude Code CLI (claude) with the Cortex Code router skill,
# if not already present, then verifies your Snowflake connection.
#
# Usage:
# bash <(curl -sSL https://raw.githubusercontent.com/Snowflake-Labs/snowflake-ai-kit/main/install.sh)
#
# # Check what's installed
# bash <(curl -sSL .../install.sh) --check
#
set -e
# Colors
G='\033[0;32m' Y='\033[1;33m' R='\033[0;31m' B='\033[1m' N='\033[0m'
REPO_URL="https://github.com/Snowflake-Labs/snowflake-ai-kit.git"
SKILL_DIR="${HOME}/.claude/skills/cortex-code"
TROUBLESHOOT="https://github.com/Snowflake-Labs/snowflake-ai-kit#troubleshooting"
msg() { echo -e " $*"; }
ok() { echo -e " ${G}✓${N} $*"; }
warn() { echo -e " ${Y}!${N} $*"; }
die() { echo -e " ${R}✗${N} $*" >&2; exit 1; }
step() { echo -e "\n${B}$*${N}"; }
# ─── Prereq checks ─────────────────────────────────────────
check_cmd() {
command -v "$1" &>/dev/null
}
check_snowflake_auth() {
if [[ -f "$HOME/.snowflake/connections.toml" ]]; then
ok "Snowflake config found (~/.snowflake/connections.toml)"
return 0
elif [[ -f "$HOME/.snowflake/config.toml" ]]; then
ok "Snowflake config found (~/.snowflake/config.toml)"
return 0
elif [[ -n "$SNOWFLAKE_HOST" ]] || [[ -n "$SNOWFLAKE_ACCOUNT" ]]; then
ok "Snowflake config found (environment variables)"
return 0
else
warn "No Snowflake connection configured."
msg " Set one up (shared by both snow and cortex CLIs):"
msg " snow connection add"
msg " This creates ~/.snowflake/connections.toml, used by both tools."
msg " Docs: https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/specify-credentials"
msg " More help: $TROUBLESHOOT"
return 1
fi
}
install_snowflake_cli() {
if check_cmd snow; then
ok "Snowflake CLI (snow) already installed"
return 0
fi
msg "Installing Snowflake CLI..."
if check_cmd pipx; then
pipx install snowflake-cli && ok "Snowflake CLI installed via pipx" && return 0
elif check_cmd pip3; then
pip3 install snowflake-cli && ok "Snowflake CLI installed via pip3" && return 0
elif check_cmd pip; then
pip install snowflake-cli && ok "Snowflake CLI installed via pip" && return 0
elif check_cmd brew; then
brew tap snowflakedb/snowflake-cli && brew install snowflake-cli && ok "Snowflake CLI installed via brew" && return 0
fi
die "Could not install Snowflake CLI. See $TROUBLESHOOT"
}
install_cortex_code_cli() {
if check_cmd cortex; then
ok "Cortex Code CLI (cortex) already installed"
return 0
fi
msg "Installing Cortex Code CLI..."
if curl -LsS https://ai.snowflake.com/static/cc-scripts/install.sh | sh; then
ok "Cortex Code CLI installed"
return 0
fi
die "Could not install Cortex Code CLI. See $TROUBLESHOOT"
}
install_claude_code_cli() {
if check_cmd claude; then
ok "Claude Code CLI (claude) already installed"
return 0
fi
msg "Installing Claude Code CLI..."
# If npm not found, try to install Node.js first
if ! check_cmd npm; then
msg " Node.js not found -- attempting to install..."
if check_cmd brew; then
brew install node 2>/dev/null && msg " Node.js installed via brew"
elif check_cmd apt-get; then
curl -fsSL https://deb.nodesource.com/setup_lts.x 2>/dev/null | sudo -E bash - 2>/dev/null && sudo apt-get install -y nodejs 2>/dev/null && msg " Node.js installed via apt"
elif check_cmd yum; then
curl -fsSL https://rpm.nodesource.com/setup_lts.x 2>/dev/null | sudo bash - 2>/dev/null && sudo yum install -y nodejs 2>/dev/null && msg " Node.js installed via yum"
fi
fi
if check_cmd npm; then
npm install -g @anthropic-ai/claude-code 2>/dev/null && ok "Claude Code CLI installed via npm" && return 0
fi
warn "Could not install Claude Code CLI (requires Node.js + npm)."
msg " Install Node.js from https://nodejs.org then re-run."
msg " Or install manually: npm install -g @anthropic-ai/claude-code"
return 1
}
# ─── Skill installation ──────────────────────────────────────
install_skills() {
if [ -f "${SKILL_DIR}/SKILL.md" ] && ! $UPDATE; then
ok "Claude-to-Cortex Code Router skill already installed"
msg " Re-run with --update to overwrite"
return 0
fi
msg "Installing Claude-to-Cortex Code Router skill..."
tmp_dir=$(mktemp -d)
trap "rm -rf '$tmp_dir'" EXIT
src=""
# Try cloning the repo
if git clone --depth 1 "$REPO_URL" "$tmp_dir/repo" 2>/dev/null; then
if [ -d "$tmp_dir/repo/agent-to-agent-skills/claude-cortex-code-router" ]; then
src="$tmp_dir/repo/agent-to-agent-skills/claude-cortex-code-router"
fi
fi
# Fallback: check if script is running from within the repo
if [ -z "$src" ] || [ ! -f "$src/SKILL.md" ]; then
script_dir="$(cd "$(dirname "$0")" && pwd)"
local_src="$script_dir/agent-to-agent-skills/claude-cortex-code-router"
if [ -f "$local_src/SKILL.md" ]; then
msg " Using local repo as source..."
src="$local_src"
fi
fi
if [ -z "$src" ] || [ ! -f "$src/SKILL.md" ]; then
warn "Could not find skill source (clone failed and not running from repo)."
msg " Manual install: git clone $REPO_URL && copy agent-to-agent-skills/claude-cortex-code-router/ to $SKILL_DIR/"
return 1
fi
mkdir -p "$SKILL_DIR/scripts" "$SKILL_DIR/security/policies" "$SKILL_DIR/references"
# Core skill definition
cp "$src/SKILL.md" "$SKILL_DIR/"
cp "$src/README.md" "$SKILL_DIR/"
cp "$src/config.yaml.example" "$SKILL_DIR/"
# Scripts
for f in discover_cortex.py execute_cortex.py predict_tools.py \
read_cortex_sessions.py route_request.py security_wrapper.py; do
cp "$src/scripts/$f" "$SKILL_DIR/scripts/"
done
# Security module
for f in __init__.py approval_handler.py audit_logger.py \
cache_manager.py config_manager.py prompt_sanitizer.py; do
cp "$src/security/$f" "$SKILL_DIR/security/"
done
cp "$src/security/policies/default_policy.yaml" "$SKILL_DIR/security/policies/"
# References
for f in cortex-cli-reference.md routing-examples.md; do
cp "$src/references/$f" "$SKILL_DIR/references/"
done
# Optional docs
for f in SECURITY.md; do
[ -f "$src/$f" ] && cp "$src/$f" "$SKILL_DIR/"
done
ok "Claude-to-Cortex Code Router skill installed to ${SKILL_DIR}/"
return 0
}
# ─── Parse arguments ────────────────────────────────────────
CHECK_ONLY=false
UPDATE=false
WITH_CLAUDE=false
while [ $# -gt 0 ]; do
case $1 in
--check|-c)
CHECK_ONLY=true
shift
;;
--update|-u)
UPDATE=true
shift
;;
--with-claude)
WITH_CLAUDE=true
shift
;;
--help|-h)
echo "Snowflake AI Kit — Installer"
echo ""
echo "Installs Snowflake CLI (snow), Cortex Code CLI (cortex), and optionally Claude Code CLI (claude) + router skill."
echo ""
echo "Usage: install.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --check, -c Check installation status without installing"
echo " --update, -u Re-install skills (overwrite existing)"
echo " --with-claude Also install Claude Code CLI and Claude-to-Cortex router skill"
echo " --help, -h Show this help"
exit 0
;;
*)
die "Unknown option: $1 (use --help)"
;;
esac
done
# ─── Execute ────────────────────────────────────────────────
echo ""
echo -e "${B}Snowflake AI Kit — Installer${N}"
echo "──────────────────────────────"
echo ""
if $CHECK_ONLY; then
step "Checking installation status..."
check_cmd snow && ok "Snowflake CLI (snow) installed" || warn "Snowflake CLI (snow) not found"
check_cmd cortex && ok "Cortex Code CLI (cortex) installed" || warn "Cortex Code CLI (cortex) not found"
check_cmd claude && ok "Claude Code CLI (claude) installed" || warn "Claude Code CLI (claude) not found"
[ -f "${SKILL_DIR}/SKILL.md" ] && ok "Claude-to-Cortex Code Router skill installed" || warn "Claude-to-Cortex Code Router skill not found"
check_snowflake_auth || true
echo ""
exit 0
fi
step "Installing CLIs..."
install_snowflake_cli
install_cortex_code_cli
# Claude Code CLI is opt-in (but if already installed, just ensure skill is there)
install_claude=false
if $WITH_CLAUDE; then
install_claude=true
elif check_cmd claude; then
install_claude=true
elif [ -t 0 ]; then
echo ""
msg "Claude Code CLI is optional (requires Node.js + Anthropic API key)."
printf " Install Claude Code CLI and router skill? (y/N) "
read -r answer
case "$answer" in
[Yy]*) install_claude=true ;;
esac
fi
if $install_claude; then
install_claude_code_cli || true
step "Installing skills..."
install_skills || true
else
msg "Skipping Claude Code CLI (use --with-claude to include)"
fi
step "Checking Snowflake connection..."
check_snowflake_auth || true
echo ""
echo -e "${G}All done!${N}"
echo ""
echo "Next steps:"
echo " snow --version # Verify Snowflake CLI"
echo " cortex --version # Verify Cortex Code CLI"
if $install_claude; then
echo " claude --version # Verify Claude Code CLI"
fi
echo " cortex # Start Cortex Code"
echo ""