-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
150 lines (126 loc) · 6.12 KB
/
Copy pathsetup.sh
File metadata and controls
150 lines (126 loc) · 6.12 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
#!/usr/bin/env bash
set -euo pipefail
# ─────────────────────────────────────────────────────────
# context-forge setup wizard
# ─────────────────────────────────────────────────────────
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
header() { echo -e "\n${BLUE}▶ $1${NC}"; }
ok() { echo -e " ${GREEN}✓${NC} $1"; }
warn() { echo -e " ${YELLOW}!${NC} $1"; }
err() { echo -e " ${RED}✗${NC} $1"; }
echo ""
echo "╔══════════════════════════════════════╗"
echo "║ context-forge setup ║"
echo "╚══════════════════════════════════════╝"
# ─── Prerequisites ────────────────────────────────────────
header "Checking prerequisites"
if ! command -v docker &>/dev/null; then
err "Docker not found. Install Docker: https://docs.docker.com/get-docker/"
exit 1
fi
ok "Docker $(docker --version | awk '{print $3}' | tr -d ',')"
if ! docker compose version &>/dev/null; then
err "Docker Compose v2 not found. Update Docker or install the plugin."
exit 1
fi
ok "Docker Compose $(docker compose version --short)"
# ─── .env ─────────────────────────────────────────────────
header "Environment configuration"
if [ -f .env ]; then
warn ".env already exists, skipping creation"
else
cp .env.example .env
ok "Created .env from .env.example"
# Generate a random Postgres password
if command -v openssl &>/dev/null; then
PG_PASS=$(openssl rand -base64 24 | tr -d '/+=')
sed -i.bak "s/changeme_strong_password/$PG_PASS/" .env && rm -f .env.bak
ok "Generated random Postgres password"
# Generate the first-run bootstrap token (the web onboarding wizard asks for it once)
BOOTSTRAP_TOKEN=$(openssl rand -base64 32 | tr -d '/+=')
sed -i.bak "s/change_this_bootstrap_token/$BOOTSTRAP_TOKEN/" .env && rm -f .env.bak
ok "Generated SETUP_BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN"
warn "The web UI setup wizard will ask for this token (it stays in .env)"
# Guard GET /metrics by default; empty METRICS_TOKEN in .env to open it up
METRICS_TOKEN=$(openssl rand -base64 32 | tr -d '/+=')
sed -i.bak "s/^METRICS_TOKEN=/METRICS_TOKEN=$METRICS_TOKEN/" .env && rm -f .env.bak
ok "Generated METRICS_TOKEN: $METRICS_TOKEN"
fi
echo ""
echo " Please edit .env and set your API keys:"
echo -e " ${YELLOW}OPENAI_API_KEY${NC} (required for OpenAI embeddings)"
echo -e " ${YELLOW}GITHUB_TOKEN${NC} (optional, for private GitHub repos)"
echo -e " ${YELLOW}GITLAB_TOKEN${NC} (optional, for GitLab repos)"
echo ""
read -p " Press Enter to open .env in your editor (or Ctrl+C to skip)..."
${EDITOR:-nano} .env
fi
# ─── context-forge.yml ────────────────────────────────────
header "Repository configuration"
if [ -f context-forge.yml ]; then
warn "context-forge.yml already exists, skipping creation"
else
cp context-forge.yml.example context-forge.yml
ok "Created context-forge.yml from example"
echo ""
warn "Edit context-forge.yml to add your repositories"
echo " See context-forge.yml.example for examples"
fi
# ─── docker-compose.override.yml ──────────────────────────
header "Volume mounts for local repos"
if [ -f docker-compose.override.yml ]; then
warn "docker-compose.override.yml already exists"
else
cp docker-compose.override.yml.example docker-compose.override.yml
ok "Created docker-compose.override.yml"
warn "Edit docker-compose.override.yml to mount your local repo paths"
fi
# ─── Start services ───────────────────────────────────────
header "Starting context-forge"
echo ""
read -p " Start services now? [Y/n] " START_NOW
START_NOW=${START_NOW:-Y}
if [[ "$START_NOW" =~ ^[Yy]$ ]]; then
docker compose build --quiet
docker compose up -d
echo ""
ok "Services started!"
echo ""
echo " Waiting for services to be ready..."
sleep 5
if curl -sf http://localhost:8000/api/health >/dev/null 2>&1; then
ok "API is healthy"
else
warn "API not yet ready — may still be initializing"
fi
echo ""
echo -e " ${GREEN}context-forge is running!${NC}"
echo ""
echo " ┌─ Endpoints ──────────────────────────────────┐"
echo " │ MCP server: http://localhost:4000/mcp │"
echo " │ REST API: http://localhost:8000/api │"
echo " │ Web UI: http://localhost:3000 │"
echo " └──────────────────────────────────────────────┘"
else
echo ""
echo " Run manually with: docker compose up -d"
fi
# ─── Agent connection ─────────────────────────────────────
echo ""
header "Connect your AI agent"
echo ""
echo " Claude Code:"
echo -e " ${YELLOW}claude mcp add --transport http context-forge http://localhost:4000/mcp${NC}"
echo ""
echo " Cursor — add to .cursor/mcp.json:"
echo -e ' ${YELLOW}{"mcpServers": {"context-forge": {"url": "http://localhost:4000/mcp"}}}${NC}'
echo ""
echo " Copy system prompt to your project:"
echo -e " ${YELLOW}cp templates/CLAUDE.md /path/to/your/project/CLAUDE.md${NC}"
echo ""
echo " Full docs: docs/claude-code.md | docs/cursor.md | docs/codex.md"
echo ""