-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·500 lines (455 loc) · 19.4 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·500 lines (455 loc) · 19.4 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#!/bin/bash
#
# Claude Code Scientist - Installation Script
#
# Installs research capabilities into your Claude Code environment:
# - Skills (literature-search, peer-review, etc.)
# - Agent definitions (lit-scout, synthesizer, reviewers, etc.)
# - MCP server for literature search
# - Validation hooks
#
# Usage:
# ./install.sh --global # Install globally (one-time setup)
# ./install.sh --init [DIR] # Initialize DIR (or current dir) for research
# ./install.sh # Full install to current project (standalone)
# ./install.sh --uninstall # Uninstall from current project
# ./install.sh --uninstall --global # Uninstall globally
#
# Recommended workflow:
# 1. git clone https://github.com/rhowardstone/Claude-Code-Scientist.git
# 2. ./Claude-Code-Scientist/install.sh --global
# 3. ./Claude-Code-Scientist/install.sh --init ~/my-research-project
# 4. cd ~/my-research-project && claude
#
# After global install, you can init any directory:
# ~/Claude-Code-Scientist/install.sh --init /path/to/project
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GLOBAL_CLAUDE_DIR="$HOME/.claude"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Parse arguments
UNINSTALL=false
GLOBAL=false
INIT=false
INIT_DIR=""
while [[ $# -gt 0 ]]; do
case $1 in
--uninstall|--remove)
UNINSTALL=true
shift
;;
--global)
GLOBAL=true
shift
;;
--init)
INIT=true
shift
# Check if next arg is a directory (not another flag)
if [[ $# -gt 0 && ! "$1" =~ ^-- ]]; then
INIT_DIR="$1"
shift
fi
;;
*)
shift
;;
esac
done
# Determine target directory
if [[ "$GLOBAL" == true ]]; then
TARGET_DIR="$GLOBAL_CLAUDE_DIR"
PROJECT_ROOT="$HOME"
else
# Find project root (look for .git or .claude)
PROJECT_ROOT="$(pwd)"
while [[ "$PROJECT_ROOT" != "/" ]]; do
if [[ -d "$PROJECT_ROOT/.git" ]] || [[ -d "$PROJECT_ROOT/.claude" ]]; then
break
fi
PROJECT_ROOT="$(dirname "$PROJECT_ROOT")"
done
if [[ "$PROJECT_ROOT" == "/" ]]; then
PROJECT_ROOT="$(pwd)"
fi
TARGET_DIR="$PROJECT_ROOT/.claude"
fi
# Handle --init (quick project setup pointing to global install)
if [[ "$INIT" == true ]]; then
# Determine target directory
if [[ -n "$INIT_DIR" ]]; then
INIT_TARGET="$INIT_DIR"
# Create directory if it doesn't exist
mkdir -p "$INIT_TARGET"
else
INIT_TARGET="$(pwd)"
fi
# Convert to absolute path
INIT_TARGET="$(cd "$INIT_TARGET" && pwd)"
echo -e "${BLUE}╔════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Claude Code Scientist - Project Init ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════╝${NC}"
echo
echo -e "${YELLOW}Initializing: $INIT_TARGET${NC}"
echo
# Copy MCP server into project (self-contained, works for any user)
echo -e "${GREEN}Setting up MCP server...${NC}"
mkdir -p "$INIT_TARGET/.claude/mcp-servers/literature"
if [[ -f "$SCRIPT_DIR/mcp-servers/literature/server.py" ]]; then
cp "$SCRIPT_DIR/mcp-servers/literature/server.py" "$INIT_TARGET/.claude/mcp-servers/literature/"
chmod +x "$INIT_TARGET/.claude/mcp-servers/literature/server.py"
echo " ✓ Copied MCP server to project"
elif [[ -f "$HOME/.claude/mcp-servers/literature/server.py" ]]; then
cp "$HOME/.claude/mcp-servers/literature/server.py" "$INIT_TARGET/.claude/mcp-servers/literature/"
chmod +x "$INIT_TARGET/.claude/mcp-servers/literature/server.py"
echo " ✓ Copied MCP server from global install"
else
echo -e "${RED}Error: Cannot find MCP server. Run './install.sh --global' first.${NC}"
exit 1
fi
# Create .mcp.json pointing to project-local server
echo -e "${GREEN}Creating .mcp.json...${NC}"
cat > "$INIT_TARGET/.mcp.json" << EOF
{
"mcpServers": {
"literature": {
"type": "stdio",
"command": "python3",
"args": ["$INIT_TARGET/.claude/mcp-servers/literature/server.py"]
}
}
}
EOF
echo " ✓ .mcp.json (project-local MCP server)"
# Create workspace directory structure for session management
echo -e "${GREEN}Creating workspace structure...${NC}"
mkdir -p "$INIT_TARGET/workspace/sessions"
echo " ✓ workspace/sessions/ directory"
# Copy session.sh if we have it
if [ -f "session.sh" ]; then
cp session.sh "$INIT_TARGET/session.sh"
chmod +x "$INIT_TARGET/session.sh"
echo " ✓ session.sh (session management)"
fi
echo
echo -e "${GREEN}Project initialized!${NC}"
echo
echo "This project is self-contained with its own MCP server."
echo "Skills, agents, rules, and hooks are loaded from ~/.claude/ (global install)"
echo
echo -e "${YELLOW}To start:${NC}"
echo " cd $INIT_TARGET"
echo " ./session.sh new \"Your research goal\""
echo " claude"
exit 0
fi
# Handle uninstall
if [[ "$UNINSTALL" == true ]]; then
echo -e "${BLUE}╔════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Claude Code Scientist - Uninstaller ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════╝${NC}"
echo
echo -e "${YELLOW}Uninstalling from: $TARGET_DIR${NC}"
echo
# Remove installed components
echo -e "${RED}Removing skills...${NC}"
for skill in goal-decomposition literature-search peer-review synthesis experiment brainstorming \
claim-extraction hypothesis-generator lit-scout narrative-framing prisma-tracking \
research-coordinator research-director results-analyst reviewer-impact \
reviewer-methodology reviewer-statistics scientific-figures synthesizer \
tool-acquirer verification-before-completion writing-plans; do
rm -rf "$TARGET_DIR/skills/$skill" 2>/dev/null && echo " ✓ Removed skill: $skill" || true
done
echo -e "${RED}Removing agents...${NC}"
rm -f "$TARGET_DIR/agents/lit-scout.md" 2>/dev/null && echo " ✓ Removed lit-scout" || true
rm -f "$TARGET_DIR/agents/synthesizer.md" 2>/dev/null && echo " ✓ Removed synthesizer" || true
rm -f "$TARGET_DIR/agents/reviewer-methodology.md" 2>/dev/null && echo " ✓ Removed reviewer-methodology" || true
rm -f "$TARGET_DIR/agents/reviewer-statistics.md" 2>/dev/null && echo " ✓ Removed reviewer-statistics" || true
rm -f "$TARGET_DIR/agents/reviewer-impact.md" 2>/dev/null && echo " ✓ Removed reviewer-impact" || true
rm -f "$TARGET_DIR/agents/experimentalist.md" 2>/dev/null && echo " ✓ Removed experimentalist" || true
rm -f "$TARGET_DIR/agents/tool-acquirer.md" 2>/dev/null && echo " ✓ Removed tool-acquirer" || true
echo -e "${RED}Removing rules...${NC}"
rm -f "$TARGET_DIR/rules/provenance-tracking.md" 2>/dev/null && echo " ✓ Removed provenance-tracking" || true
rm -f "$TARGET_DIR/rules/world-model.md" 2>/dev/null && echo " ✓ Removed world-model" || true
rm -f "$TARGET_DIR/rules/workflow.md" 2>/dev/null && echo " ✓ Removed workflow" || true
rm -f "$TARGET_DIR/rules/literature-acquisition.md" 2>/dev/null && echo " ✓ Removed literature-acquisition" || true
echo -e "${RED}Removing hooks...${NC}"
rm -rf "$TARGET_DIR/hooks" 2>/dev/null && echo " ✓ Removed hooks directory" || true
echo -e "${RED}Removing MCP server...${NC}"
rm -rf "$TARGET_DIR/mcp-servers/literature" 2>/dev/null && echo " ✓ Removed literature MCP server" || true
echo -e "${RED}Removing Craig package...${NC}"
pip uninstall -y craig 2>/dev/null && echo " ✓ Removed craig package" || true
# Also clean up old-style install if present
rm -rf "$HOME/.craig" 2>/dev/null || true
echo -e "${RED}Removing CLAUDE.md...${NC}"
if [[ "$GLOBAL" == true ]]; then
rm -f "$TARGET_DIR/CLAUDE.md" 2>/dev/null && echo " ✓ Removed ~/.claude/CLAUDE.md" || true
else
rm -f "$PROJECT_ROOT/.claude/CLAUDE.md" 2>/dev/null && echo " ✓ Removed .claude/CLAUDE.md" || true
fi
# Clean up MCP config
if [[ "$GLOBAL" == true ]]; then
if [[ -f "$HOME/.mcp.json" ]]; then
echo -e "${YELLOW}Note: ~/.mcp.json left intact (may contain other servers)${NC}"
echo " To remove literature server, edit ~/.mcp.json manually"
fi
fi
echo
echo -e "${GREEN}Uninstall complete!${NC}"
echo -e "${YELLOW}Restart Claude Code to apply changes.${NC}"
exit 0
fi
# Regular install continues below
echo -e "${BLUE}╔════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Claude Code Scientist - Installer ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════╝${NC}"
echo
if [[ "$GLOBAL" == true ]]; then
echo -e "${YELLOW}Installing globally to: $TARGET_DIR${NC}"
else
echo -e "${YELLOW}Installing to project: $TARGET_DIR${NC}"
fi
echo
# Detect if running from source repo (SCRIPT_DIR == PROJECT_ROOT)
# In this case, files are already in place - no copy needed
RUNNING_FROM_SOURCE=false
if [[ "$(realpath "$SCRIPT_DIR")" == "$(realpath "$PROJECT_ROOT")" ]] && [[ "$GLOBAL" != true ]]; then
RUNNING_FROM_SOURCE=true
echo -e "${GREEN}Running from source repository - files already in place.${NC}"
echo -e "${YELLOW}Skipping file copies, will configure MCP and dependencies only.${NC}"
echo
fi
# Create target directories
mkdir -p "$TARGET_DIR/skills"
mkdir -p "$TARGET_DIR/agents"
mkdir -p "$TARGET_DIR/rules"
mkdir -p "$TARGET_DIR/hooks"
mkdir -p "$TARGET_DIR/mcp-servers"
# Install CLAUDE.md (the Research Director brain)
echo -e "${GREEN}[1/7] Installing CLAUDE.md...${NC}"
if [[ "$RUNNING_FROM_SOURCE" == true ]]; then
echo " ✓ CLAUDE.md (already in place)"
elif [[ "$GLOBAL" == true ]]; then
cp "$SCRIPT_DIR/.claude/CLAUDE.md" "$TARGET_DIR/CLAUDE.md"
echo " ✓ CLAUDE.md (Research Director prompt)"
else
# For project install, create .claude/CLAUDE.md (standard Claude Code location)
mkdir -p "$PROJECT_ROOT/.claude"
cp "$SCRIPT_DIR/.claude/CLAUDE.md" "$PROJECT_ROOT/.claude/CLAUDE.md"
echo " ✓ CLAUDE.md (Research Director prompt)"
fi
# Install skills
echo -e "${GREEN}[2/7] Installing skills...${NC}"
if [[ "$RUNNING_FROM_SOURCE" == true ]]; then
skill_count=$(find "$TARGET_DIR/skills" -name "SKILL.md" | wc -l)
echo " ✓ $skill_count skills (already in place)"
else
for skill_dir in "$SCRIPT_DIR/.claude/skills"/*/; do
skill_name=$(basename "$skill_dir")
if [[ -f "$skill_dir/SKILL.md" ]]; then
mkdir -p "$TARGET_DIR/skills/$skill_name"
cp "$skill_dir/SKILL.md" "$TARGET_DIR/skills/$skill_name/"
echo " ✓ $skill_name"
fi
done
fi
# Install agents
echo -e "${GREEN}[3/7] Installing agent definitions...${NC}"
if [[ "$RUNNING_FROM_SOURCE" == true ]]; then
agent_count=$(find "$TARGET_DIR/agents" -name "*.md" 2>/dev/null | wc -l)
echo " ✓ $agent_count agents (already in place)"
else
for agent_file in "$SCRIPT_DIR/.claude/agents"/*.md; do
if [[ -f "$agent_file" ]]; then
agent_name=$(basename "$agent_file")
cp "$agent_file" "$TARGET_DIR/agents/"
echo " ✓ ${agent_name%.md}"
fi
done
fi
# Install rules
echo -e "${GREEN}[4/7] Installing rules...${NC}"
if [[ "$RUNNING_FROM_SOURCE" == true ]]; then
rule_count=$(find "$TARGET_DIR/rules" -name "*.md" 2>/dev/null | wc -l)
echo " ✓ $rule_count rules (already in place)"
else
for rule_file in "$SCRIPT_DIR/.claude/rules"/*.md; do
if [[ -f "$rule_file" ]]; then
rule_name=$(basename "$rule_file")
cp "$rule_file" "$TARGET_DIR/rules/"
echo " ✓ ${rule_name%.md}"
fi
done
fi
# Install hooks (recursively, including subdirectories like post-tool-use/)
echo -e "${GREEN}[5/7] Installing validation hooks...${NC}"
if [[ "$RUNNING_FROM_SOURCE" == true ]]; then
hook_count=$(find "$TARGET_DIR/hooks" -name "*.py" 2>/dev/null | wc -l)
echo " ✓ $hook_count hooks (already in place)"
else
# Copy entire hooks directory structure
cp -r "$SCRIPT_DIR/.claude/hooks/"* "$TARGET_DIR/hooks/" 2>/dev/null || true
# Make all Python scripts executable
find "$TARGET_DIR/hooks" -name "*.py" -exec chmod +x {} \;
find "$TARGET_DIR/hooks" -name "*.sh" -exec chmod +x {} \;
# Count and report
hook_count=$(find "$TARGET_DIR/hooks" -name "*.py" | wc -l)
echo " ✓ $hook_count hooks installed (including post-tool-use/)"
fi
# Install MCP server
echo -e "${GREEN}[6/7] Installing MCP server...${NC}"
if [[ "$RUNNING_FROM_SOURCE" == true ]]; then
echo " ✓ literature server (already in place)"
else
cp -r "$SCRIPT_DIR/mcp-servers/literature" "$TARGET_DIR/mcp-servers/"
chmod +x "$TARGET_DIR/mcp-servers/literature/server.py"
echo " ✓ literature server"
fi
# Install Craig Python module as proper package
echo -e "${GREEN}[7/7] Installing Craig Python package...${NC}"
pip install -e "$SCRIPT_DIR" --quiet 2>/dev/null || \
pip install --user -e "$SCRIPT_DIR" --quiet 2>/dev/null || {
echo -e "${YELLOW} Warning: Could not install craig package via pip${NC}"
echo " Please run: pip install -e $SCRIPT_DIR"
}
# Verify installation
if python3 -c "import craig" 2>/dev/null; then
echo " ✓ Craig package installed (import craig works)"
else
echo -e "${YELLOW} Warning: craig package not importable - may need to restart shell${NC}"
fi
# Create/update .mcp.json
if [[ "$GLOBAL" == true ]]; then
# For global install, create both template AND global ~/.mcp.json
MCP_TEMPLATE="$HOME/.claude/mcp-template.json"
cat > "$MCP_TEMPLATE" << EOF
{
"mcpServers": {
"literature": {
"type": "stdio",
"command": "python3",
"args": ["$HOME/.claude/mcp-servers/literature/server.py"]
}
}
}
EOF
# Also create global ~/.mcp.json
cp "$MCP_TEMPLATE" "$HOME/.mcp.json"
echo " ✓ MCP config created at ~/.mcp.json (global)"
echo " ✓ MCP template also at ~/.claude/mcp-template.json (for project copies)"
else
MCP_CONFIG="$PROJECT_ROOT/.mcp.json"
# Check if .mcp.json exists and merge, or create new
if [[ -f "$MCP_CONFIG" ]]; then
echo
echo -e "${YELLOW}Found existing .mcp.json - merging...${NC}"
# Use Python to merge JSON
python3 << EOF
import json
with open("$MCP_CONFIG", "r") as f:
config = json.load(f)
config.setdefault("mcpServers", {})
config["mcpServers"]["literature"] = {
"type": "stdio",
"command": "python3",
"args": ["$TARGET_DIR/mcp-servers/literature/server.py"]
}
with open("$MCP_CONFIG", "w") as f:
json.dump(config, f, indent=2)
EOF
else
cat > "$MCP_CONFIG" << EOF
{
"mcpServers": {
"literature": {
"type": "stdio",
"command": "python3",
"args": ["$TARGET_DIR/mcp-servers/literature/server.py"]
}
}
}
EOF
fi
echo " ✓ .mcp.json configured"
fi
# Create/update settings.json for hooks
SETTINGS_FILE="$TARGET_DIR/settings.json"
if [[ "$RUNNING_FROM_SOURCE" != true ]]; then
cp "$SCRIPT_DIR/.claude/settings.json" "$SETTINGS_FILE"
fi
# Update hook paths - replace placeholder with actual path (even for source installs)
sed -i "s|__HOOKS_DIR__|$TARGET_DIR/hooks|g" "$SETTINGS_FILE" 2>/dev/null || true
echo " ✓ settings.json configured with hooks at $TARGET_DIR/hooks"
# Set up .env file for API keys
echo
echo -e "${GREEN}Setting up environment file...${NC}"
if [[ -f "$SCRIPT_DIR/.env.example" ]]; then
if [[ "$GLOBAL" == true ]]; then
ENV_TARGET="$HOME/.claude/.env"
else
ENV_TARGET="$PROJECT_ROOT/.env"
fi
# Skip if running from source and .env already exists (don't overwrite)
if [[ ! -f "$ENV_TARGET" ]] && [[ "$RUNNING_FROM_SOURCE" != true || ! -f "$PROJECT_ROOT/.env" ]]; then
cp "$SCRIPT_DIR/.env.example" "$ENV_TARGET" 2>/dev/null || true
echo " ✓ Created $ENV_TARGET from template"
echo -e "${YELLOW} → Edit $ENV_TARGET to add your API keys${NC}"
else
echo " ✓ $ENV_TARGET already exists (not overwritten)"
fi
fi
# Install Python dependencies
echo
echo -e "${GREEN}Installing Python dependencies...${NC}"
if [[ -f "$SCRIPT_DIR/requirements.txt" ]]; then
pip install -q -r "$SCRIPT_DIR/requirements.txt" 2>/dev/null || \
pip install --user -q -r "$SCRIPT_DIR/requirements.txt" 2>/dev/null || {
echo -e "${YELLOW} Warning: Could not install all dependencies automatically${NC}"
echo " Please run: pip install -r $SCRIPT_DIR/requirements.txt"
}
echo " ✓ Python dependencies (aiohttp, pymupdf, pymupdf4llm, pdfplumber, mcp)"
else
# Fallback to minimal deps if requirements.txt missing
pip install -q aiohttp mcp pymupdf pymupdf4llm pdfplumber 2>/dev/null || \
pip install --user -q aiohttp mcp pymupdf pymupdf4llm pdfplumber 2>/dev/null || {
echo -e "${YELLOW} Warning: Could not install dependencies automatically${NC}"
echo " Please run: pip install aiohttp mcp pymupdf pymupdf4llm pdfplumber"
}
fi
echo
echo -e "${BLUE}════════════════════════════════════════════${NC}"
echo -e "${GREEN}Installation complete!${NC}"
echo
echo "Installed components:"
echo " • CLAUDE.md: Research Director prompt (the brain)"
echo " • Skills: 24 research workflows (literature-search, peer-review, synthesis, experiments...)"
echo " • Agents: 7 specialized subagents (lit-scout, synthesizer, 3 reviewers, experimentalist, tool-acquirer)"
echo " • Hooks: 8 validation hooks (claims, DOI, provenance, sources...)"
echo " • Rules: 3 convention files (provenance-tracking, world-model, workflow)"
echo " • MCP: literature server (OpenAlex, PubMed, Semantic Scholar) + ~/.mcp.json"
echo " • Craig: Python utilities including:"
echo " - Bulk literature pipeline (python -m craig.cli.literature_pipeline)"
echo " - PDF extraction (PyMuPDF4LLM, Marker AI, pdfplumber)"
echo " - World model, DOI fetcher, LaTeX compiler, experiment harness"
echo
echo -e "${YELLOW}Next steps:${NC}"
echo " 1. Restart Claude Code in your project directory"
echo " 2. Try: 'Search for papers on <your topic>'"
echo
echo -e "${BLUE}Optional API keys (add to ~/.bashrc or ~/.zshrc for higher rate limits):${NC}"
echo " export NCBI_API_KEY='...' # PubMed: 10 req/sec (vs 3 without)"
echo " export OPENALEX_API_KEY='...' # OpenAlex: polite pool access"
echo " export SEMANTIC_SCHOLAR_API_KEY='...' # Semantic Scholar: higher limits"
echo " export USER_EMAIL='you@example.com' # Polite pool identification"
echo
echo -e "${BLUE}Get keys at:${NC}"
echo " • NCBI: https://www.ncbi.nlm.nih.gov/account/settings/"
echo " • Semantic Scholar: https://www.semanticscholar.org/product/api"
echo " • OpenAlex: https://openalex.org/users/me (optional, email is usually enough)"
echo