-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·151 lines (137 loc) · 5.84 KB
/
setup.sh
File metadata and controls
executable file
·151 lines (137 loc) · 5.84 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
#!/bin/bash
# =============================================================================
# Librarian - UV Environment Setup
# =============================================================================
# Usage:
# ./setup.sh # Interactive mode
# ./setup.sh -y # Non-interactive (auto-yes)
# ./setup.sh --help # Show help
# =============================================================================
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configuration
PYTHON_VERSION="3.11"
VENV_DIR=".venv"
AUTO_YES=false
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-y|--yes)
AUTO_YES=true
shift
;;
-h|--help)
echo "Usage: $0 [-y|--yes] [-h|--help]"
echo ""
echo "Options:"
echo " -y, --yes Non-interactive mode (auto-confirm all prompts)"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Helper functions
confirm() {
if [ "$AUTO_YES" = true ]; then
return 0
fi
local prompt="$1"
echo -ne "${YELLOW}${prompt} [Y/n]: ${NC}"
read -r response
response=${response:-y}
[[ "$response" =~ ^[Yy] ]]
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
echo -e "${BLUE}╔═══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Librarian - Context Management Service ║${NC}"
echo -e "${BLUE}╚═══════════════════════════════════════════════════════════════╝${NC}"
echo ""
# Step 1: Check/Install uv
echo -e "${YELLOW}[1/5] Checking uv installation...${NC}"
if ! command_exists uv; then
echo -e "${RED}✗ uv is not installed${NC}"
if confirm "Install uv now?"; then
echo -e " Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
echo -e "${GREEN}✓ uv installed${NC}"
else
echo -e "${RED}Cannot proceed without uv. Exiting.${NC}"
exit 1
fi
else
echo -e "${GREEN}✓ uv is installed ($(uv --version 2>/dev/null | head -1))${NC}"
fi
# Step 2: Ensure Python is available
echo -e "\n${YELLOW}[2/5] Checking Python ${PYTHON_VERSION}...${NC}"
if ! uv python find "$PYTHON_VERSION" >/dev/null 2>&1; then
echo -e " Python ${PYTHON_VERSION} not found, installing via uv..."
uv python install "$PYTHON_VERSION"
fi
PYTHON_PATH=$(uv python find "$PYTHON_VERSION")
echo -e "${GREEN}✓ Python ${PYTHON_VERSION} available at: ${PYTHON_PATH}${NC}"
# Step 3: Create virtual environment
echo -e "\n${YELLOW}[3/5] Setting up virtual environment...${NC}"
if [ -d "$VENV_DIR" ]; then
CURRENT_VERSION=$("$VENV_DIR/bin/python" --version 2>&1 | cut -d' ' -f2 | cut -d'.' -f1,2)
if [ "$CURRENT_VERSION" = "$PYTHON_VERSION" ]; then
echo -e "${GREEN}✓ Virtual environment exists with Python ${CURRENT_VERSION}${NC}"
else
echo -e " Recreating venv (current: Python ${CURRENT_VERSION})..."
rm -rf "$VENV_DIR"
uv venv --python "$PYTHON_VERSION" "$VENV_DIR"
echo -e "${GREEN}✓ Virtual environment created with Python ${PYTHON_VERSION}${NC}"
fi
else
uv venv --python "$PYTHON_VERSION" "$VENV_DIR"
echo -e "${GREEN}✓ Virtual environment created${NC}"
fi
# Step 4: Install dependencies from pyproject.toml
echo -e "\n${YELLOW}[4/5] Installing dependencies...${NC}"
if [ -f "pyproject.toml" ]; then
echo -e " Installing package in development mode with dev dependencies..."
uv pip install -e ".[dev]"
echo -e "${GREEN}✓ Dependencies installed${NC}"
else
echo -e "${RED}✗ No pyproject.toml found. Cannot install dependencies.${NC}"
exit 1
fi
# Step 5: Setup directories and environment
echo -e "\n${YELLOW}[5/5] Setting up directories...${NC}"
mkdir -p ~/.librarian
mkdir -p documents
echo -e "${GREEN}✓ Directories created${NC}"
# Done!
echo ""
echo -e "${GREEN}╔═══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Setup Complete! ✓ ║${NC}"
echo -e "${GREEN}╚═══════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${BLUE}Activate the environment:${NC}"
echo -e " ${YELLOW}source ${VENV_DIR}/bin/activate${NC}"
echo ""
echo -e "${BLUE}Run the MCP server:${NC}"
echo -e " ${YELLOW}uv run librarian/server.py stdio${NC} # For Claude Desktop"
echo -e " ${YELLOW}uv run librarian/server.py http${NC} # For Cursor/VS Code"
echo ""
echo -e "${BLUE}Configuration (via environment variables):${NC}"
echo -e " ${YELLOW}DOCUMENTS_PATH${NC} - Path to markdown files (default: ./documents)"
echo -e " ${YELLOW}DATABASE_PATH${NC} - SQLite database path (default: ~/.librarian/index.db)"
echo -e " ${YELLOW}EMBEDDING_MODEL${NC} - Sentence transformer model (default: all-MiniLM-L6-v2)"
echo -e " ${YELLOW}CHUNK_SIZE${NC} - Max chunk size in chars (default: 512)"
echo -e " ${YELLOW}CHUNK_OVERLAP${NC} - Overlap between chunks (default: 50)"
echo ""
echo -e "${BLUE}Environment info:${NC}"
echo -e " Python: ${VENV_DIR}/bin/python ($(${VENV_DIR}/bin/python --version 2>&1))"
echo -e " Packages: $(${VENV_DIR}/bin/pip list 2>/dev/null | wc -l | tr -d ' ') installed"