-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·420 lines (366 loc) · 16.2 KB
/
dev.sh
File metadata and controls
executable file
·420 lines (366 loc) · 16.2 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
#!/bin/bash
# =============================================================================
# NEURO-OS Development Script with Hot Reload
# =============================================================================
# Starts all services with automatic reload on code changes.
#
# Requirements:
# - cargo-watch: cargo install cargo-watch
# - Docker services running: ./start.sh --docker
#
# Usage:
# ./dev.sh - Start all dev services with hot reload
# ./dev.sh backend - Start only backend with hot reload
# ./dev.sh ui - Start only user UI
# ./dev.sh admin - Start only admin UI
# ./dev.sh voice - Rebuild and restart voice service (release)
#
# FAST DEV MODE (Docker, 3-5x faster builds):
# ./dev.sh docker-dev - Start Docker services with dev optimizations
# ./dev.sh rebuild-voice - Rebuild voice service (debug + mold)
# ./dev.sh rebuild-music - Rebuild music service (debug + mold)
# ./dev.sh rebuild-checklists - Rebuild checklists service (debug + mold)
# ./dev.sh clean-cache - Clear persistent cargo cache
#
# Fast Dev Mode uses:
# - Debug builds (no --release) - ~30% faster compilation
# - mold linker - 2-3x faster linking
# - Persistent cargo cache - dependencies compile ONCE
# =============================================================================
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
NC='\033[0m'
PROJECT_ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_ROOT"
print_header() {
echo -e "\n${CYAN}╔════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║${NC} ${BLUE}$1${NC}"
echo -e "${CYAN}╚════════════════════════════════════════════════════════════════╝${NC}\n"
}
print_step() {
echo -e "${GREEN}▶${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
# Check prerequisites
check_prerequisites() {
if ! command -v cargo-watch &> /dev/null; then
print_warning "cargo-watch not found. Installing..."
cargo install cargo-watch
fi
if [ ! -f .env ]; then
echo -e "${RED}Error: .env file not found. Run ./setup.sh first.${NC}"
exit 1
fi
}
# Check if Docker services are running
check_docker_services() {
if ! docker ps 2>/dev/null | grep -q "surrealdb"; then
print_warning "Docker services not running. Starting them first..."
./start.sh --docker
sleep 3
fi
}
# Export common environment variables
export_env() {
export DATABASE_URL="ws://127.0.0.1:8000"
export DATABASE_USER="root"
export DATABASE_PASS="neuroos_secret_2024"
export OLLAMA_URL="http://127.0.0.1:11434"
export SEARXNG_URL="http://127.0.0.1:8080"
export VOICE_SERVICE_URL="http://127.0.0.1:8100"
export RUST_LOG=debug
}
# Start backend with hot reload
start_backend() {
print_step "Starting backend with hot reload..."
echo -e " ${CYAN}Watching: neuro-backend/src/**/*.rs${NC}"
echo -e " ${YELLOW}Press Ctrl+C to stop${NC}\n"
cd neuro-backend
export_env
cargo watch -x run -w src
}
# Start user UI (Vite already has HMR)
start_ui() {
print_step "Starting User UI with HMR..."
echo -e " ${CYAN}URL: http://localhost:5173${NC}"
echo -e " ${YELLOW}Press Ctrl+C to stop${NC}\n"
cd neuro-ui
npm run dev
}
# Start admin UI (Vite already has HMR)
start_admin() {
print_step "Starting Admin UI with HMR..."
echo -e " ${CYAN}URL: http://localhost:5174${NC}"
echo -e " ${YELLOW}Press Ctrl+C to stop${NC}\n"
cd neuro-admin
npm run dev
}
# Rebuild and restart voice service
restart_voice() {
print_step "Rebuilding and restarting Voice Service..."
# Stop existing container
docker stop neuro-voice 2>/dev/null || true
docker rm neuro-voice 2>/dev/null || true
# Rebuild image
echo -e " ${YELLOW}Building image...${NC}"
docker build -t neuro-voice ./neuro-voice
# Get network name
NETWORK_NAME=$(docker network ls --filter name=kibo --format '{{.Name}}' | grep neuro-network | head -1)
if [ -z "$NETWORK_NAME" ]; then
NETWORK_NAME="kibo_neuro-network"
fi
# Start container
docker run -d --gpus all \
--name neuro-voice \
--network $NETWORK_NAME \
-p 8100:8100 \
-e RUST_LOG=info,voice_service=debug \
-e HOST=0.0.0.0 \
-e PORT=8100 \
-e PIPER_BIN=/app/piper/piper \
-e MODELS_DIR=/app/models \
-e DEFAULT_VOICE=es_MX-claude-high \
neuro-voice
echo -e " ${GREEN}Voice Service restarted!${NC}"
}
# =============================================================================
# FAST DEV MODE - Uses debug builds + persistent cache
# =============================================================================
# Builds are ~3-5x faster because:
# 1. Uses debug mode (no optimizations)
# 2. Uses mold linker (2-3x faster linking)
# 3. Persistent cargo cache (dependencies compile once)
# =============================================================================
# Start Docker services in fast dev mode
start_docker_dev() {
print_header "Starting Docker services in FAST DEV mode"
echo -e "${CYAN}Using development optimizations:${NC}"
echo -e " • ${GREEN}Debug builds${NC} (no --release, ~30% faster)"
echo -e " • ${GREEN}mold linker${NC} (2-3x faster linking)"
echo -e " • ${GREEN}Persistent cache${NC} (dependencies compile once)"
echo -e ""
# Always rebuild to catch source changes
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build
echo -e "\n${GREEN}✓ Dev services started!${NC}"
echo -e " Voice: ${YELLOW}http://localhost:8100${NC}"
echo -e " Music: ${YELLOW}http://localhost:3002${NC}"
echo -e " Checklists: ${YELLOW}http://localhost:3001${NC}"
echo -e " Chat: ${YELLOW}http://localhost:3003${NC}"
echo -e " Memory: ${YELLOW}http://localhost:3004${NC}"
echo -e " Agent: ${YELLOW}http://localhost:3005${NC}"
echo -e " Kanban: ${YELLOW}http://localhost:3006${NC}"
echo -e " Note: ${YELLOW}http://localhost:3007${NC}"
echo -e " Docs: ${YELLOW}http://localhost:3008${NC}"
echo -e " Calendar: ${YELLOW}http://localhost:3009${NC}"
echo -e " Pomodoro: ${YELLOW}http://localhost:3010${NC}"
echo -e " Image: ${YELLOW}http://localhost:3011${NC}"
echo -e ""
echo -e "${CYAN}Tip:${NC} Use ${YELLOW}./dev.sh watch${NC} for auto-rebuild on changes"
}
# Start Docker services in watch mode (auto-rebuild on changes)
start_docker_watch() {
print_header "Starting Docker services in WATCH mode (auto-rebuild)"
echo -e "${CYAN}Watch mode features:${NC}"
echo -e " • ${GREEN}Auto-rebuild${NC} when source files change"
echo -e " • ${GREEN}Solo reconstruye el servicio modificado${NC} (los demás siguen corriendo)"
echo -e " • ${GREEN}Debug builds${NC} (no --release, ~30% faster)"
echo -e " • ${GREEN}mold linker${NC} (2-3x faster linking)"
echo -e " • ${GREEN}Persistent cache${NC} (dependencies compile once)"
echo -e " • ${GREEN}Rebuild típico: ~30s${NC} (vs 3-5min en release)"
echo -e ""
echo -e "${YELLOW}Watching for changes in:${NC}"
echo -e " • neuro-voice/src/**/*.rs → Reconstruye solo neuro-voice"
echo -e " • neuro-music/src/**/*.rs → Reconstruye solo neuro-music"
echo -e " • neuro-checklists/src/**/*.rs → Reconstruye solo neuro-checklists"
echo -e " • neuro-chat/src/**/*.rs → Reconstruye solo neuro-chat"
echo -e " • neuro-memory/src/**/*.rs → Reconstruye solo neuro-memory"
echo -e " • neuro-agent/src/**/*.rs → Reconstruye solo neuro-agent"
echo -e " • neuro-*/Cargo.toml"
echo -e ""
echo -e "${CYAN}Press Ctrl+C to stop${NC}"
echo -e ""
# Use docker compose watch for auto-rebuild
docker compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.watch.yml watch
}
# Rebuild a specific service in dev mode (fast)
rebuild_service_dev() {
local service=$1
print_step "Rebuilding $service in FAST DEV mode..."
echo -e " ${CYAN}Using debug build + mold linker${NC}"
docker compose -f docker-compose.yml -f docker-compose.dev.yml build --no-cache $service
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d $service
echo -e " ${GREEN}$service rebuilt and restarted!${NC}"
}
# Clean cargo cache (if needed)
clean_cargo_cache() {
print_step "Cleaning persistent cargo cache..."
docker volume rm neuro-cargo-cache-voice neuro-cargo-git-voice neuro-voice-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-music neuro-cargo-git-music neuro-music-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-checklists neuro-cargo-git-checklists neuro-checklists-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-chat neuro-cargo-git-chat neuro-chat-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-memory neuro-cargo-git-memory neuro-memory-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-agent neuro-cargo-git-agent neuro-agent-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-pomodoro neuro-cargo-git-pomodoro neuro-pomodoro-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-kanban neuro-cargo-git-kanban neuro-kanban-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-note neuro-cargo-git-note neuro-note-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-docs neuro-cargo-git-docs neuro-docs-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-calendar neuro-cargo-git-calendar neuro-calendar-target 2>/dev/null || true
docker volume rm neuro-cargo-cache-image neuro-cargo-git-image neuro-image-target 2>/dev/null || true
echo -e " ${GREEN}Cache cleaned! Next build will be slower but fresh.${NC}"
}
# Start all services in tmux (if available) or parallel
start_all() {
print_header "NEURO-OS Development Mode"
check_docker_services
# Check if tmux is available
if command -v tmux &> /dev/null; then
echo -e "${CYAN}Using tmux for multiple terminals${NC}\n"
# Kill existing session if any
tmux kill-session -t neuro-dev 2>/dev/null || true
# Create new session with backend
tmux new-session -d -s neuro-dev -n backend
tmux send-keys -t neuro-dev:backend "cd $PROJECT_ROOT && ./dev.sh backend" Enter
# Create window for UI
tmux new-window -t neuro-dev -n ui
tmux send-keys -t neuro-dev:ui "cd $PROJECT_ROOT && ./dev.sh ui" Enter
# Create window for admin
tmux new-window -t neuro-dev -n admin
tmux send-keys -t neuro-dev:admin "cd $PROJECT_ROOT && ./dev.sh admin" Enter
echo -e "
${GREEN}╔════════════════════════════════════════════════════════════════╗${NC}
${GREEN}║${NC} ${CYAN}NEURO-OS Dev Mode (tmux session)${NC} ${GREEN}║${NC}
${GREEN}╚════════════════════════════════════════════════════════════════╝${NC}
${CYAN}Services with Hot Reload:${NC}
• ${MAGENTA}backend${NC} - Rust backend (cargo watch)
• ${MAGENTA}ui${NC} - User interface (Vite HMR)
• ${MAGENTA}admin${NC} - Admin interface (Vite HMR)
${CYAN}URLs:${NC}
• User UI: ${YELLOW}http://localhost:5173${NC}
• Admin UI: ${YELLOW}http://localhost:5174${NC}
• Backend: ${YELLOW}http://localhost:3000${NC}
• Voice API: ${YELLOW}http://localhost:8100${NC}
${CYAN}tmux Commands:${NC}
• Attach: ${YELLOW}tmux attach -t neuro-dev${NC}
• Switch: ${YELLOW}Ctrl+B then 0/1/2${NC} (backend/ui/admin)
• Detach: ${YELLOW}Ctrl+B then D${NC}
• Kill: ${YELLOW}tmux kill-session -t neuro-dev${NC}
${CYAN}To stop:${NC} ${YELLOW}./stop.sh${NC} or ${YELLOW}tmux kill-session -t neuro-dev${NC}
"
# Attach to session
tmux attach -t neuro-dev
else
# No tmux - run in foreground with instructions
echo -e "
${YELLOW}tmux not found. Run these in separate terminals:${NC}
${CYAN}Terminal 1 (Backend):${NC}
./dev.sh backend
${CYAN}Terminal 2 (User UI):${NC}
./dev.sh ui
${CYAN}Terminal 3 (Admin UI):${NC}
./dev.sh admin
"
fi
}
# Main
check_prerequisites
case "${1:-all}" in
backend|be|b)
check_docker_services
start_backend
;;
ui|user|u)
start_ui
;;
admin|a)
start_admin
;;
voice|v)
restart_voice
;;
docker-dev|dd)
start_docker_dev
;;
watch|w)
start_docker_watch
;;
rebuild-voice|rv)
rebuild_service_dev neuro-voice
;;
rebuild-music|rm)
rebuild_service_dev neuro-music
;;
rebuild-checklists|rc)
rebuild_service_dev neuro-checklists
;;
rebuild-chat|rch)
rebuild_service_dev neuro-chat
;;
rebuild-memory|rmem)
rebuild_service_dev neuro-memory
;;
rebuild-agent|ra)
rebuild_service_dev neuro-agent
;;
rebuild-pomodoro|rp)
rebuild_service_dev neuro-pomodoro
;;
rebuild-kanban|rk)
rebuild_service_dev neuro-kanban
;;
rebuild-note|rn)
rebuild_service_dev neuro-note
;;
rebuild-docs|rd)
rebuild_service_dev neuro-docs
;;
rebuild-calendar|rcal)
rebuild_service_dev neuro-calendar
;;
rebuild-image|ri)
rebuild_service_dev neuro-image
;;
clean-cache|cc)
clean_cargo_cache
;;
all|"")
start_all
;;
*)
echo -e "${CYAN}Usage:${NC} ./dev.sh [command]"
echo -e ""
echo -e "${CYAN}Local Development:${NC}"
echo -e " ${YELLOW}(none)${NC} Start all services with hot reload (uses tmux)"
echo -e " ${YELLOW}backend${NC} Start backend with cargo watch"
echo -e " ${YELLOW}ui${NC} Start user UI with Vite HMR"
echo -e " ${YELLOW}admin${NC} Start admin UI with Vite HMR"
echo -e ""
echo -e "${CYAN}Docker Fast Dev Mode (3-5x faster builds):${NC}"
echo -e " ${YELLOW}docker-dev${NC} Start Docker services with dev optimizations"
echo -e " ${YELLOW}watch${NC} ${GREEN}Auto-rebuild on changes${NC} (solo reconstruye servicio modificado)"
echo -e " ${YELLOW}rebuild-voice${NC} Rebuild voice service (fast dev mode)"
echo -e " ${YELLOW}rebuild-music${NC} Rebuild music service (fast dev mode)"
echo -e " ${YELLOW}rebuild-checklists${NC} Rebuild checklists service (fast dev mode)"
echo -e " ${YELLOW}rebuild-chat${NC} Rebuild chat service (fast dev mode)"
echo -e " ${YELLOW}rebuild-memory${NC} Rebuild memory service (fast dev mode)"
echo -e " ${YELLOW}rebuild-agent${NC} Rebuild agent service (fast dev mode)"
echo -e " ${YELLOW}rebuild-pomodoro${NC} Rebuild pomodoro service (fast dev mode)"
echo -e " ${YELLOW}rebuild-kanban${NC} Rebuild kanban service (fast dev mode)"
echo -e " ${YELLOW}rebuild-note${NC} Rebuild note service (fast dev mode)"
echo -e " ${YELLOW}rebuild-docs${NC} Rebuild docs service (fast dev mode)"
echo -e " ${YELLOW}rebuild-calendar${NC} Rebuild calendar service (fast dev mode)"
echo -e " ${YELLOW}rebuild-image${NC} Rebuild image service (fast dev mode)"
echo -e " ${YELLOW}clean-cache${NC} Clean persistent cargo cache"
echo -e ""
echo -e "${CYAN}Legacy (slower):${NC}"
echo -e " ${YELLOW}voice${NC} Rebuild voice service (release mode)"
exit 1
;;
esac