-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalkyl.sh
More file actions
executable file
·300 lines (272 loc) · 11.5 KB
/
alkyl.sh
File metadata and controls
executable file
·300 lines (272 loc) · 11.5 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
#!/usr/bin/env bash
# ALKYL — Unified management script
# Usage:
# bash alkyl.sh install
# bash alkyl.sh repair
# bash alkyl.sh uninstall
# bash alkyl.sh setup-key perplexity <API_KEY>
# bash alkyl.sh status
set -e
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLAUDE_MD="$HOME/.claude/CLAUDE.md"
SETTINGS="$HOME/.claude/settings.json"
MARKER_START="<!-- ALKYL-START -->"
MARKER_END="<!-- ALKYL-END -->"
# ── Colors ─────────────────────────────────────────────────────────────────
BLUE='\033[38;2;31;81;255m'
BOLD='\033[1m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
DIM='\033[2m'
RESET='\033[0m'
# ── Logo ───────────────────────────────────────────────────────────────────
print_logo() {
printf "\n${BLUE}${BOLD}"
cat << 'LOGO'
░▒▓██████▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
░▒▓████████▓▒░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓████████▓▒░
LOGO
printf "${RESET}"
printf " ${DIM}Computational Chemistry · Claude Code Plugin${RESET}\n\n"
}
# ── Helpers ────────────────────────────────────────────────────────────────
is_installed() {
grep -q "$MARKER_START" "$CLAUDE_MD" 2>/dev/null
}
remove_block() {
if is_installed; then
sed -i "/$MARKER_START/,/$MARKER_END/d" "$CLAUDE_MD"
fi
}
inject_block() {
mkdir -p "$(dirname "$CLAUDE_MD")"
touch "$CLAUDE_MD"
remove_block
{
echo ""
echo "$MARKER_START"
cat "$REPO_DIR/config/CLAUDE.md"
echo "$MARKER_END"
} >> "$CLAUDE_MD"
# Resolve scripts path placeholder
SCRIPTS_ABS="$REPO_DIR/scripts"
sed -i "s|ALKYL_SCRIPTS_PATH|${SCRIPTS_ABS}|g" "$CLAUDE_MD"
}
# ── Commands ───────────────────────────────────────────────────────────────
register_plugin() {
mkdir -p "$(dirname "$SETTINGS")"
[ -f "$SETTINGS" ] || echo '{"plugins":{}}' > "$SETTINGS"
python3 - "$SETTINGS" "$REPO_DIR" "$HOME/.claude/plugins/installed_plugins.json" <<'PY'
import json, sys, datetime
path, repo, plugins_path = sys.argv[1], sys.argv[2], sys.argv[3]
with open(path) as f:
d = json.load(f)
now = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.000Z")
installed = json.load(open(plugins_path))
installed["plugins"]["alkyl@local"] = [{
"scope": "user",
"installPath": repo,
"version": "1.0.0",
"installedAt": now,
"lastUpdated": now,
"gitCommitSha": "local"
}]
with open(plugins_path, "w") as f:
json.dump(installed, f, indent=2)
# Enable the plugin in settings.json (required for skill discovery)
d.setdefault("enabledPlugins", {})["alkyl@local"] = True
with open(path, "w") as f:
json.dump(d, f, indent=2, ensure_ascii=False)
PY
}
deregister_plugin() {
python3 - "$HOME/.claude/plugins/installed_plugins.json" "$SETTINGS" <<'PY'
import json, os, sys
plugins_path, settings_path = sys.argv[1], sys.argv[2]
with open(plugins_path) as f:
d = json.load(f)
d["plugins"].pop("alkyl@local", None)
with open(plugins_path, "w") as f:
json.dump(d, f, indent=2)
if os.path.exists(settings_path):
with open(settings_path) as f:
s = json.load(f)
s.get("enabledPlugins", {}).pop("alkyl@local", None)
with open(settings_path, "w") as f:
json.dump(s, f, indent=2, ensure_ascii=False)
PY
}
cmd_install() {
print_logo
if is_installed; then
printf " ${YELLOW}⚠ ALKYL already installed. Re-injecting (idempotent)...${RESET}\n"
fi
inject_block
register_plugin
printf " ${GREEN}✓ Chemistry context injected into $CLAUDE_MD${RESET}\n"
printf " ${GREEN}✓ ALKYL registered as plugin (visible in /plugins)${RESET}\n"
printf " ${GREEN}✓ 23 skills discoverable via /skills${RESET}\n\n"
printf " ${DIM}Repair: bash alkyl.sh repair${RESET}\n"
printf " ${DIM}Uninstall: bash alkyl.sh uninstall${RESET}\n"
printf " ${DIM}API keys: bash alkyl.sh setup-key perplexity <KEY>${RESET}\n\n"
}
cmd_repair() {
print_logo
printf " ${YELLOW}⟳ Repairing ALKYL — re-injecting config...${RESET}\n"
inject_block
printf " ${GREEN}✓ Config repaired and re-injected${RESET}\n"
printf " ${GREEN}✓ Scripts path: $REPO_DIR/scripts${RESET}\n\n"
}
cmd_uninstall() {
printf "\n ${RED}Uninstalling ALKYL...${RESET}\n"
if is_installed; then
remove_block
printf " ${GREEN}✓ ALKYL block removed from $CLAUDE_MD${RESET}\n"
else
printf " ${DIM}ALKYL was not installed in $CLAUDE_MD${RESET}\n"
fi
deregister_plugin
printf " ${GREEN}✓ ALKYL deregistered from plugin system${RESET}\n"
# Optional: remove MCP keys from settings.json
if [ -f "$SETTINGS" ] && grep -q '"perplexity"' "$SETTINGS" 2>/dev/null; then
printf " ${YELLOW}Remove Perplexity MCP key from settings.json? (y/N):${RESET} "
read -r ans
if [[ "$ans" =~ ^[Yy]$ ]]; then
python3 - "$SETTINGS" <<'PY'
import json, sys
path = sys.argv[1]
with open(path) as f:
d = json.load(f)
d.get('mcpServers', {}).pop('perplexity', None)
with open(path, 'w') as f:
json.dump(d, f, indent=2, ensure_ascii=False)
print(" ✓ Perplexity MCP key removed")
PY
fi
fi
printf "\n"
}
cmd_status() {
printf "\n ${BOLD}ALKYL Status${RESET}\n"
printf " ─────────────────────────────\n"
if is_installed; then
printf " ${GREEN}✓ Installed${RESET} — $CLAUDE_MD\n"
# Show block line count
LINES=$(sed -n "/$MARKER_START/,/$MARKER_END/p" "$CLAUDE_MD" | wc -l)
printf " ${DIM} Block size: $LINES lines${RESET}\n"
else
printf " ${RED}✗ Not installed${RESET}\n"
fi
printf " ${DIM}Repo: $REPO_DIR${RESET}\n"
printf " ${DIM}Scripts: $REPO_DIR/scripts${RESET}\n"
# Count skills
N_SKILLS=$(find "$REPO_DIR/skills" -name "SKILL.md" 2>/dev/null | wc -l)
printf " ${DIM}Skills: $N_SKILLS loaded${RESET}\n"
# MCP keys
if [ -f "$SETTINGS" ]; then
printf "\n ${BOLD}MCP keys in settings.json:${RESET}\n"
python3 - "$SETTINGS" <<'PY'
import json, sys
with open(sys.argv[1]) as f:
d = json.load(f)
servers = d.get('mcpServers', {})
if not servers:
print(" (none configured)")
else:
for name, cfg in servers.items():
env = cfg.get('env', {})
keys = [k for k in env if 'KEY' in k or 'TOKEN' in k or 'SECRET' in k]
masked = {k: env[k][:8] + '...' for k in keys}
print(f" • {name}: {masked if masked else '(no key)'}")
PY
else
printf " ${DIM}(settings.json not found)${RESET}\n"
fi
printf "\n"
}
cmd_venv() {
VENV_DIR="$REPO_DIR/.venv"
printf "\n ${BOLD}Setting up ALKYL virtual environment${RESET}\n"
printf " ${DIM}Location: $VENV_DIR${RESET}\n\n"
if [ -d "$VENV_DIR" ]; then
printf " ${YELLOW}⚠ .venv already exists. Reinstalling dependencies...${RESET}\n"
else
python3 -m venv "$VENV_DIR"
printf " ${GREEN}✓ Virtual environment created${RESET}\n"
fi
"$VENV_DIR/bin/pip" install --quiet --upgrade pip
"$VENV_DIR/bin/pip" install --quiet "rdkit>=2023.9.1" pytest
printf " ${GREEN}✓ Dependencies installed (rdkit, pytest)${RESET}\n\n"
printf " ${BOLD}Run scripts:${RESET}\n"
printf " ${DIM} $VENV_DIR/bin/python scripts/chem_props.py --smiles 'CCO'${RESET}\n\n"
printf " ${BOLD}Run tests:${RESET}\n"
printf " ${DIM} $VENV_DIR/bin/python -m pytest tests/ -m 'not network' -v${RESET}\n\n"
}
cmd_setup_key() {
local SERVICE="${1:-}"
local API_KEY="${2:-}"
if [ -z "$SERVICE" ] || [ -z "$API_KEY" ]; then
printf "\n ${RED}Usage: bash alkyl.sh setup-key <service> <API_KEY>${RESET}\n"
printf " Supported services: perplexity\n\n"
exit 1
fi
mkdir -p "$(dirname "$SETTINGS")"
[ -f "$SETTINGS" ] || echo "{}" > "$SETTINGS"
case "$SERVICE" in
perplexity)
if [[ "$API_KEY" != pplx-* ]]; then
printf " ${YELLOW}Warning: key doesn't start with 'pplx-'. Continue? (y/N):${RESET} "
read -r ans
[[ "$ans" =~ ^[Yy]$ ]] || exit 1
fi
python3 - "$SETTINGS" "$API_KEY" <<'PY'
import json, sys
path, api_key = sys.argv[1], sys.argv[2]
with open(path) as f:
d = json.load(f)
d.setdefault('mcpServers', {})['perplexity'] = {
'command': 'npx',
'args': ['-y', '@perplexity-ai/mcp-server'],
'env': {'PERPLEXITY_API_KEY': api_key}
}
with open(path, 'w') as f:
json.dump(d, f, indent=2, ensure_ascii=False)
PY
printf " ${GREEN}✓ Perplexity MCP configured in $SETTINGS${RESET}\n"
printf " ${DIM}Restart Claude Code for changes to take effect.${RESET}\n\n"
;;
*)
printf " ${RED}Unknown service: $SERVICE${RESET}\n"
printf " Supported: perplexity\n\n"
exit 1
;;
esac
}
# ── Dispatch ───────────────────────────────────────────────────────────────
CMD="${1:-}"
case "$CMD" in
install) cmd_install ;;
repair) cmd_repair ;;
uninstall) cmd_uninstall ;;
status) cmd_status ;;
venv) cmd_venv ;;
setup-key) cmd_setup_key "${2:-}" "${3:-}" ;;
*)
printf "\n ${BOLD}ALKYL — Computational Chemistry Plugin${RESET}\n\n"
printf " Usage: bash alkyl.sh <command>\n\n"
printf " Commands:\n"
printf " ${GREEN}install${RESET} Install ALKYL into ~/.claude/CLAUDE.md\n"
printf " ${GREEN}venv${RESET} Create .venv with RDKit (for scripts & tests)\n"
printf " ${GREEN}repair${RESET} Force re-inject config (fixes corruption)\n"
printf " ${GREEN}uninstall${RESET} Remove ALKYL from ~/.claude/CLAUDE.md\n"
printf " ${GREEN}status${RESET} Show installation status and MCP keys\n"
printf " ${GREEN}setup-key perplexity <KEY>${RESET} Configure Perplexity MCP API key\n\n"
exit 1
;;
esac