forked from spencrmartin/brian
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·370 lines (318 loc) · 9.94 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·370 lines (318 loc) · 9.94 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
#!/bin/bash
# Brian - Complete Setup Script
# This script installs Brian and configures it as a Goose extension
set -e # Exit on error
echo "🧠 Brian - Your Personal Knowledge Base"
echo "========================================"
echo ""
# Color codes for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# Check if Python 3 is installed
echo -e "${BLUE}Checking Python installation...${NC}"
if ! command -v python3 &> /dev/null; then
echo -e "${RED}Error: Python 3 is not installed${NC}"
echo "Please install Python 3.8 or higher from https://www.python.org/"
exit 1
fi
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
echo -e "${GREEN}✓ Found Python $PYTHON_VERSION${NC}"
echo ""
# Check if Node.js is installed
echo -e "${BLUE}Checking Node.js installation...${NC}"
if ! command -v node &> /dev/null; then
echo -e "${RED}Error: Node.js is not installed${NC}"
echo "Please install Node.js from https://nodejs.org/"
exit 1
fi
NODE_VERSION=$(node --version)
echo -e "${GREEN}✓ Found Node.js $NODE_VERSION${NC}"
echo ""
# Check if pnpm is installed
echo -e "${BLUE}Checking pnpm installation...${NC}"
if ! command -v pnpm &> /dev/null; then
echo -e "${RED}Error: pnpm is not installed${NC}"
echo "Please install pnpm: npm install -g pnpm"
echo "Or visit: https://pnpm.io/installation"
exit 1
fi
PNPM_VERSION=$(pnpm --version)
echo -e "${GREEN}✓ Found pnpm $PNPM_VERSION${NC}"
echo ""
# Create virtual environment if it doesn't exist
if [ ! -d "venv" ]; then
echo -e "${BLUE}Creating Python virtual environment...${NC}"
python3 -m venv venv
echo -e "${GREEN}✓ Virtual environment created${NC}"
else
echo -e "${YELLOW}Virtual environment already exists${NC}"
fi
echo ""
# Activate virtual environment
echo -e "${BLUE}Activating virtual environment...${NC}"
source venv/bin/activate
echo -e "${GREEN}✓ Virtual environment activated${NC}"
echo ""
# Clear pip cache and upgrade build tools
echo -e "${BLUE}Preparing Python environment...${NC}"
python -m pip cache purge > /dev/null 2>&1 || true
python -m pip install --no-cache-dir --upgrade pip setuptools wheel --quiet
echo -e "${GREEN}✓ Python environment ready${NC}"
echo ""
# Install Python dependencies
echo -e "${BLUE}Installing Python dependencies...${NC}"
if [ -f "requirements.txt" ]; then
pip install --no-cache-dir -r requirements.txt --quiet
echo -e "${GREEN}✓ Python dependencies installed${NC}"
else
echo -e "${RED}Error: requirements.txt not found${NC}"
exit 1
fi
echo ""
# Install brian package in development mode
echo -e "${BLUE}Installing Brian package...${NC}"
pip install --no-cache-dir -e . --quiet
echo -e "${GREEN}✓ Brian package installed${NC}"
echo ""
# Install frontend dependencies
echo -e "${BLUE}Installing frontend dependencies...${NC}"
echo -e "${YELLOW} (This may take 1-2 minutes - downloading React, Vite, D3.js, etc.)${NC}"
echo ""
cd frontend
if [ -f "package.json" ]; then
# Clean install to avoid corruption issues
rm -rf node_modules yarn.lock package-lock.json 2>/dev/null || true
echo -e "${YELLOW} Installing with pnpm...${NC}"
pnpm install
if [ $? -ne 0 ]; then
echo -e "${RED}Error: Failed to install frontend dependencies${NC}"
exit 1
fi
echo -e "${GREEN}✓ Frontend dependencies installed${NC}"
else
echo -e "${RED}Error: frontend/package.json not found${NC}"
exit 1
fi
cd ..
echo ""
# Create .brian directory if it doesn't exist
BRIAN_DIR="$HOME/.brian"
if [ ! -d "$BRIAN_DIR" ]; then
echo -e "${BLUE}Creating Brian data directory...${NC}"
mkdir -p "$BRIAN_DIR"
echo -e "${GREEN}✓ Created $BRIAN_DIR${NC}"
else
echo -e "${YELLOW}Brian data directory already exists${NC}"
fi
echo ""
# Configure Goose extension
GOOSE_CONFIG="$HOME/.config/goose/config.yaml"
GOOSE_CONFIG_DIR="$HOME/.config/goose"
echo -e "${BLUE}Configuring Goose extension...${NC}"
# Create goose config directory if it doesn't exist
if [ ! -d "$GOOSE_CONFIG_DIR" ]; then
mkdir -p "$GOOSE_CONFIG_DIR"
fi
# Check if brian extension already exists in config
if [ -f "$GOOSE_CONFIG" ] && grep -q "^ brian:" "$GOOSE_CONFIG"; then
echo -e "${YELLOW}Brian extension already exists in Goose config${NC}"
echo -e "${YELLOW}Updating configuration...${NC}"
# Remove existing brian config (from " brian:" to next extension or end of extensions block)
sed -i.tmp '/^ brian:/,/^ [a-z]/{ /^ brian:/d; /^ /d; }' "$GOOSE_CONFIG"
rm -f "$GOOSE_CONFIG.tmp"
fi
# Add brian extension to Goose config
if [ -f "$GOOSE_CONFIG" ] && grep -q "^extensions:" "$GOOSE_CONFIG"; then
# Insert brian after "extensions:" line
sed -i.tmp '/^extensions:/a\
brian:\
enabled: true\
type: stdio\
name: Brian\
description: Personal knowledge base with semantic search\
cmd: '"$SCRIPT_DIR"'/venv/bin/python\
args:\
- -m\
- brian_mcp.server\
envs:\
BRIAN_DB_PATH: '"$BRIAN_DIR"'/brian.db\
env_keys: []\
timeout: 300\
bundled: null\
available_tools: []
' "$GOOSE_CONFIG"
rm -f "$GOOSE_CONFIG.tmp"
echo -e "${GREEN}✓ Brian extension added to Goose config${NC}"
else
# Create new config file with brian extension
cat > "$GOOSE_CONFIG" << EOF
extensions:
brian:
enabled: true
type: stdio
name: Brian
description: Personal knowledge base with semantic search
cmd: $SCRIPT_DIR/venv/bin/python
args:
- -m
- brian_mcp.server
envs:
BRIAN_DB_PATH: $BRIAN_DIR/brian.db
env_keys: []
timeout: 300
bundled: null
available_tools: []
EOF
echo -e "${GREEN}✓ Created Goose config with Brian extension${NC}"
fi
echo ""
# Create a startup script
echo -e "${BLUE}Creating startup script...${NC}"
cat > start.sh << 'EOF'
#!/bin/bash
# Brian - Startup Script
# Starts both backend and frontend servers
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# Color codes
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${BLUE}🧠 Starting Brian...${NC}"
echo ""
# Check if frontend dependencies are installed
if [ ! -d "frontend/node_modules" ] || [ ! -f "frontend/node_modules/.bin/vite" ]; then
echo -e "${YELLOW}Frontend dependencies missing or corrupted. Installing...${NC}"
cd frontend
rm -rf node_modules pnpm-lock.yaml 2>/dev/null
pnpm install
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to install frontend dependencies${NC}"
exit 1
fi
cd ..
echo -e "${GREEN}✓ Frontend dependencies installed${NC}"
echo ""
fi
# Activate virtual environment
source venv/bin/activate
# Start backend in background
echo -e "${BLUE}Starting backend server...${NC}"
python -m brian.main > backend.log 2>&1 &
BACKEND_PID=$!
echo -e "${GREEN}✓ Backend started (PID: $BACKEND_PID)${NC}"
# Wait a moment for backend to start
sleep 2
# Start frontend in background
echo -e "${BLUE}Starting frontend server...${NC}"
cd frontend
pnpm run dev > ../frontend.log 2>&1 &
FRONTEND_PID=$!
cd ..
echo -e "${GREEN}✓ Frontend started (PID: $FRONTEND_PID)${NC}"
echo ""
echo -e "${GREEN}✨ Brian is running!${NC}"
echo ""
echo " Backend: http://localhost:8080"
echo " Frontend: http://localhost:5173"
echo ""
echo " Backend logs: tail -f backend.log"
echo " Frontend logs: tail -f frontend.log"
echo ""
echo "To stop Brian, run: ./stop.sh"
echo ""
# Save PIDs for stop script
echo "$BACKEND_PID" > .backend.pid
echo "$FRONTEND_PID" > .frontend.pid
EOF
chmod +x start.sh
echo -e "${GREEN}✓ Created start.sh${NC}"
echo ""
# Create a stop script
echo -e "${BLUE}Creating stop script...${NC}"
cat > stop.sh << 'EOF'
#!/bin/bash
# Brian - Stop Script
# Stops both backend and frontend servers
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# Color codes
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${BLUE}Stopping Brian...${NC}"
echo ""
# Stop backend
if [ -f .backend.pid ]; then
BACKEND_PID=$(cat .backend.pid)
if ps -p $BACKEND_PID > /dev/null 2>&1; then
echo -e "${BLUE}Stopping backend (PID: $BACKEND_PID)...${NC}"
kill $BACKEND_PID
echo -e "${GREEN}✓ Backend stopped${NC}"
else
echo -e "${RED}Backend process not found${NC}"
fi
rm .backend.pid
else
echo -e "${RED}No backend PID file found${NC}"
fi
# Stop frontend
if [ -f .frontend.pid ]; then
FRONTEND_PID=$(cat .frontend.pid)
if ps -p $FRONTEND_PID > /dev/null 2>&1; then
echo -e "${BLUE}Stopping frontend (PID: $FRONTEND_PID)...${NC}"
kill $FRONTEND_PID
echo -e "${GREEN}✓ Frontend stopped${NC}"
else
echo -e "${RED}Frontend process not found${NC}"
fi
rm .frontend.pid
else
echo -e "${RED}No frontend PID file found${NC}"
fi
echo ""
echo -e "${GREEN}Brian stopped${NC}"
EOF
chmod +x stop.sh
echo -e "${GREEN}✓ Created stop.sh${NC}"
echo ""
# Summary
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}✨ Setup Complete!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "${BLUE}What was installed:${NC}"
echo " ✓ Python dependencies (FastAPI, uvicorn, etc.)"
echo " ✓ Frontend dependencies (React, Vite, etc.)"
echo " ✓ Brian data directory: $BRIAN_DIR"
echo " ✓ Goose extension configured"
echo ""
echo -e "${BLUE}Quick Start:${NC}"
echo ""
echo -e " ${YELLOW}1. Start Brian:${NC}"
echo " ./start.sh"
echo ""
echo -e " ${YELLOW}2. Open in browser:${NC}"
echo " http://localhost:5173"
echo ""
echo -e " ${YELLOW}3. Use with Goose:${NC}"
echo " Restart Goose Desktop to load the Brian extension."
echo ""
echo -e " ${YELLOW}4. Stop Brian:${NC}"
echo " ./stop.sh"
echo ""
echo -e "${BLUE}Data:${NC}"
echo " Database: $BRIAN_DIR/brian.db"
echo ""
echo -e "${GREEN}Happy knowledge mapping! 🧠✨${NC}"
echo ""