|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# Auggie Wrapper Setup Script |
4 | | -# This script installs dependencies and configures OpenCode to use the Augment provider |
| 3 | +# Augment Code for OpenCode — Setup Script |
| 4 | +# Installs the OpenCode plugin and configures authentication. |
| 5 | +# No separate server process needed — the plugin embeds everything. |
5 | 6 |
|
6 | 7 | set -e |
7 | 8 |
|
8 | 9 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 10 | +PLUGIN_DIR="$SCRIPT_DIR/plugin" |
9 | 11 | OPENCODE_CONFIG_DIR="$HOME/.config/opencode" |
10 | 12 | OPENCODE_CONFIG_FILE="$OPENCODE_CONFIG_DIR/opencode.json" |
11 | 13 |
|
12 | | -# Colors for output |
| 14 | +# Colors |
13 | 15 | RED='\033[0;31m' |
14 | 16 | GREEN='\033[0;32m' |
15 | 17 | YELLOW='\033[1;33m' |
16 | 18 | BLUE='\033[0;34m' |
17 | | -NC='\033[0m' # No Color |
| 19 | +NC='\033[0m' |
18 | 20 |
|
19 | 21 | echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" |
20 | | -echo -e "${BLUE}║ Auggie Wrapper Setup Script ║${NC}" |
| 22 | +echo -e "${BLUE}║ Augment Code for OpenCode — Setup ║${NC}" |
21 | 23 | echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}" |
22 | 24 | echo "" |
23 | 25 |
|
24 | | -# Check Node.js version |
25 | | -echo -e "${YELLOW}Checking Node.js version...${NC}" |
| 26 | +# ─── Prerequisites ─────────────────────────────────────────────────────────── |
| 27 | + |
| 28 | +echo -e "${YELLOW}Checking prerequisites...${NC}" |
| 29 | + |
| 30 | +# Node.js |
26 | 31 | if ! command -v node &> /dev/null; then |
27 | | - echo -e "${RED}Error: Node.js is not installed. Please install Node.js 22 or later.${NC}" |
| 32 | + echo -e "${RED}✗ Node.js is not installed. Please install Node.js 20 or later.${NC}" |
28 | 33 | exit 1 |
29 | 34 | fi |
30 | | - |
31 | 35 | NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) |
32 | | -if [ "$NODE_VERSION" -lt 22 ]; then |
33 | | - echo -e "${RED}Error: Node.js 22 or later is required. Current version: $(node -v)${NC}" |
| 36 | +if [ "$NODE_VERSION" -lt 20 ]; then |
| 37 | + echo -e "${RED}✗ Node.js 20+ required. Current: $(node -v)${NC}" |
34 | 38 | exit 1 |
35 | 39 | fi |
36 | | -echo -e "${GREEN}✓ Node.js $(node -v) detected${NC}" |
| 40 | +echo -e "${GREEN}✓ Node.js $(node -v)${NC}" |
37 | 41 |
|
38 | | -# Check if auggie is installed and authenticated |
39 | | -echo -e "${YELLOW}Checking Auggie CLI...${NC}" |
| 42 | +# OpenCode |
| 43 | +if ! command -v opencode &> /dev/null; then |
| 44 | + echo -e "${YELLOW}⚠ OpenCode not found in PATH. Install from https://opencode.ai${NC}" |
| 45 | +fi |
| 46 | + |
| 47 | +# Auggie CLI |
40 | 48 | if ! command -v auggie &> /dev/null; then |
41 | 49 | echo -e "${YELLOW}Auggie CLI not found. Installing...${NC}" |
42 | 50 | npm install -g @augmentcode/auggie |
43 | 51 | fi |
44 | 52 | echo -e "${GREEN}✓ Auggie CLI installed${NC}" |
45 | 53 |
|
46 | | -# Check for authentication |
| 54 | +# Authentication |
47 | 55 | if [ ! -f "$HOME/.augment/session.json" ]; then |
48 | | - echo -e "${YELLOW}Auggie not authenticated. Please run 'auggie login' first.${NC}" |
49 | | - echo -e "${YELLOW}Running auggie login...${NC}" |
| 56 | + echo -e "${YELLOW}Not authenticated. Running 'auggie login'...${NC}" |
50 | 57 | auggie login |
51 | 58 | fi |
52 | 59 | echo -e "${GREEN}✓ Auggie authenticated${NC}" |
53 | 60 |
|
54 | | -# Install npm dependencies |
55 | | -echo -e "${YELLOW}Installing npm dependencies...${NC}" |
56 | | -cd "$SCRIPT_DIR" |
| 61 | +# ─── Build Plugin ──────────────────────────────────────────────────────────── |
| 62 | + |
| 63 | +echo "" |
| 64 | +echo -e "${YELLOW}Building plugin...${NC}" |
| 65 | +cd "$PLUGIN_DIR" |
57 | 66 | npm install |
58 | | -echo -e "${GREEN}✓ Dependencies installed${NC}" |
| 67 | +npm run build |
| 68 | +echo -e "${GREEN}✓ Plugin built${NC}" |
59 | 69 |
|
60 | | -# Configure OpenCode |
61 | | -echo -e "${YELLOW}Configuring OpenCode...${NC}" |
| 70 | +# ─── Configure OpenCode ───────────────────────────────────────────────────── |
62 | 71 |
|
63 | | -# Create config directory if it doesn't exist |
| 72 | +echo "" |
| 73 | +echo -e "${YELLOW}Configuring OpenCode...${NC}" |
64 | 74 | mkdir -p "$OPENCODE_CONFIG_DIR" |
65 | 75 |
|
66 | | -# Augment Code provider configuration - All models |
67 | 76 | if [ -f "$OPENCODE_CONFIG_FILE" ]; then |
68 | | - # Check if augment-code provider already exists |
69 | | - if grep -q '"augment-code"' "$OPENCODE_CONFIG_FILE" 2>/dev/null; then |
70 | | - echo -e "${GREEN}✓ Augment Code provider already configured in OpenCode${NC}" |
| 77 | + # Check if plugin is already configured |
| 78 | + if grep -q "opencode-augment-auth\|$PLUGIN_DIR" "$OPENCODE_CONFIG_FILE" 2>/dev/null; then |
| 79 | + echo -e "${GREEN}✓ Plugin already configured in OpenCode${NC}" |
71 | 80 | else |
72 | | - # Backup existing config |
| 81 | + # Backup and merge |
73 | 82 | cp "$OPENCODE_CONFIG_FILE" "$OPENCODE_CONFIG_FILE.backup.$(date +%Y%m%d%H%M%S)" |
74 | 83 | echo -e "${YELLOW}Backed up existing config${NC}" |
75 | 84 |
|
76 | | - # Use node to merge the configuration |
77 | 85 | node -e " |
78 | 86 | const fs = require('fs'); |
79 | | -const configPath = '$OPENCODE_CONFIG_FILE'; |
80 | | -const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')); |
81 | | -
|
82 | | -if (!config.provider) { |
83 | | - config.provider = {}; |
| 87 | +const config = JSON.parse(fs.readFileSync('$OPENCODE_CONFIG_FILE', 'utf-8')); |
| 88 | +if (!config.plugin) config.plugin = []; |
| 89 | +if (!config.plugin.includes('$PLUGIN_DIR')) { |
| 90 | + config.plugin.push('$PLUGIN_DIR'); |
84 | 91 | } |
85 | | -
|
86 | | - config.provider["augment-code"] = { |
87 | | - npm: '@ai-sdk/openai-compatible', |
88 | | - name: 'Augment Code', |
89 | | - options: { |
90 | | - baseURL: 'http://localhost:8765/v1' |
91 | | - }, |
92 | | - models: { |
93 | | - 'claude-opus-4-6': { |
94 | | - name: 'Claude Opus 4.6 (Augment)', |
95 | | - limit: { context: 200000, output: 32000 } |
96 | | - }, |
97 | | - 'claude-opus-4-5': { |
98 | | - name: 'Claude Opus 4.5 (Augment)', |
99 | | - limit: { context: 200000, output: 32000 } |
100 | | - }, |
101 | | - 'claude-sonnet-4-5': { |
102 | | - name: 'Claude Sonnet 4.5 (Augment)', |
103 | | - limit: { context: 200000, output: 16000 } |
104 | | - }, |
105 | | - 'claude-sonnet-4': { |
106 | | - name: 'Claude Sonnet 4 (Augment)', |
107 | | - limit: { context: 200000, output: 16000 } |
108 | | - }, |
109 | | - 'claude-haiku-4-5': { |
110 | | - name: 'Claude Haiku 4.5 (Augment)', |
111 | | - limit: { context: 200000, output: 8000 } |
112 | | - }, |
113 | | - 'gpt-5': { |
114 | | - name: 'GPT-5 (Augment)', |
115 | | - limit: { context: 128000, output: 16000 } |
116 | | - }, |
117 | | - 'gpt-5-1': { |
118 | | - name: 'GPT-5.1 (Augment)', |
119 | | - limit: { context: 128000, output: 16000 } |
120 | | - }, |
121 | | - 'gpt-5-2': { |
122 | | - name: 'GPT-5.2 (Augment)', |
123 | | - limit: { context: 128000, output: 16000 } |
124 | | - } |
125 | | - } |
126 | | - }; |
127 | | -
|
128 | | - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); |
129 | | - console.log('Configuration merged successfully'); |
130 | | - " |
131 | | - echo -e "${GREEN}✓ Augment Code provider added to existing OpenCode config${NC}" |
| 92 | +fs.writeFileSync('$OPENCODE_CONFIG_FILE', JSON.stringify(config, null, 2)); |
| 93 | +console.log('Plugin added to OpenCode config'); |
| 94 | +" |
| 95 | + echo -e "${GREEN}✓ Plugin added to OpenCode config${NC}" |
132 | 96 | fi |
133 | 97 | else |
134 | | - # Create new config file |
135 | | - cat > "$OPENCODE_CONFIG_FILE" << 'EOF' |
| 98 | + cat > "$OPENCODE_CONFIG_FILE" << EOF |
136 | 99 | { |
137 | | - "$schema": "https://opencode.ai/config.json", |
138 | | - "provider": { |
139 | | - "augment-code": { |
140 | | - "npm": "@ai-sdk/openai-compatible", |
141 | | - "name": "Augment Code", |
142 | | - "options": { |
143 | | - "baseURL": "http://localhost:8765/v1" |
144 | | - }, |
145 | | - "models": { |
146 | | - "claude-opus-4-6": { |
147 | | - "name": "Claude Opus 4.6 (Augment)", |
148 | | - "limit": { "context": 200000, "output": 32000 } |
149 | | - }, |
150 | | - "claude-opus-4-5": { |
151 | | - "name": "Claude Opus 4.5 (Augment)", |
152 | | - "limit": { "context": 200000, "output": 32000 } |
153 | | - }, |
154 | | - "claude-sonnet-4-5": { |
155 | | - "name": "Claude Sonnet 4.5 (Augment)", |
156 | | - "limit": { "context": 200000, "output": 16000 } |
157 | | - }, |
158 | | - "claude-sonnet-4": { |
159 | | - "name": "Claude Sonnet 4 (Augment)", |
160 | | - "limit": { "context": 200000, "output": 16000 } |
161 | | - }, |
162 | | - "claude-haiku-4-5": { |
163 | | - "name": "Claude Haiku 4.5 (Augment)", |
164 | | - "limit": { "context": 200000, "output": 8000 } |
165 | | - }, |
166 | | - "gpt-5": { |
167 | | - "name": "GPT-5 (Augment)", |
168 | | - "limit": { "context": 128000, "output": 16000 } |
169 | | - }, |
170 | | - "gpt-5-1": { |
171 | | - "name": "GPT-5.1 (Augment)", |
172 | | - "limit": { "context": 128000, "output": 16000 } |
173 | | - }, |
174 | | - "gpt-5-2": { |
175 | | - "name": "GPT-5.2 (Augment)", |
176 | | - "limit": { "context": 128000, "output": 16000 } |
177 | | - } |
178 | | - } |
179 | | - } |
180 | | - } |
| 100 | + "\$schema": "https://opencode.ai/config.json", |
| 101 | + "plugin": ["$PLUGIN_DIR"], |
| 102 | + "model": "augment/claude-opus-4-6" |
181 | 103 | } |
182 | 104 | EOF |
183 | | - echo -e "${GREEN}✓ Created new OpenCode config with Augment Code provider${NC}" |
| 105 | + echo -e "${GREEN}✓ Created OpenCode config${NC}" |
184 | 106 | fi |
185 | 107 |
|
| 108 | +# ─── Auth Setup ────────────────────────────────────────────────────────────── |
| 109 | + |
| 110 | +echo "" |
| 111 | +echo -e "${YELLOW}Setting up authentication...${NC}" |
| 112 | + |
| 113 | +AUTH_FILE="$HOME/.local/share/opencode/auth.json" |
| 114 | +if [ -f "$AUTH_FILE" ] && grep -q '"augment"' "$AUTH_FILE" 2>/dev/null; then |
| 115 | + echo -e "${GREEN}✓ Auth already configured${NC}" |
| 116 | +else |
| 117 | + mkdir -p "$(dirname "$AUTH_FILE")" |
| 118 | + if [ -f "$AUTH_FILE" ]; then |
| 119 | + node -e " |
| 120 | +const fs = require('fs'); |
| 121 | +const auth = JSON.parse(fs.readFileSync('$AUTH_FILE', 'utf-8')); |
| 122 | +auth.augment = { type: 'api', key: 'session' }; |
| 123 | +fs.writeFileSync('$AUTH_FILE', JSON.stringify(auth, null, 2)); |
| 124 | +console.log('Auth entry added'); |
| 125 | +" |
| 126 | + else |
| 127 | + echo '{"augment":{"type":"api","key":"session"}}' > "$AUTH_FILE" |
| 128 | + fi |
| 129 | + echo -e "${GREEN}✓ Auth configured${NC}" |
| 130 | +fi |
| 131 | + |
| 132 | +# ─── Done ──────────────────────────────────────────────────────────────────── |
| 133 | + |
186 | 134 | echo "" |
187 | 135 | echo -e "${GREEN}╔════════════════════════════════════════════════════════════╗${NC}" |
188 | 136 | echo -e "${GREEN}║ Setup Complete! ║${NC}" |
189 | 137 | echo -e "${GREEN}╚════════════════════════════════════════════════════════════╝${NC}" |
190 | 138 | echo "" |
191 | | -echo -e "${BLUE}To start the server:${NC}" |
192 | | -echo -e " cd $SCRIPT_DIR" |
193 | | -echo -e " npm start" |
| 139 | +echo -e "${BLUE}Just run OpenCode — no server to start:${NC}" |
| 140 | +echo -e " opencode" |
194 | 141 | echo "" |
195 | | -echo -e "${BLUE}Available models in OpenCode:${NC}" |
196 | | -echo -e " Claude models:" |
197 | | -echo -e " - augment-code/claude-opus-4-6 (default, recommended)" |
198 | | -echo -e " - augment-code/claude-opus-4-5" |
199 | | -echo -e " - augment-code/claude-sonnet-4-5" |
200 | | -echo -e " - augment-code/claude-sonnet-4" |
201 | | -echo -e " - augment-code/claude-haiku-4-5" |
202 | | -echo -e " GPT models:" |
203 | | -echo -e " - augment-code/gpt-5" |
204 | | -echo -e " - augment-code/gpt-5-1" |
205 | | -echo -e " - augment-code/gpt-5-2" |
| 142 | +echo -e "${BLUE}Available models (use augment/<model-id>):${NC}" |
| 143 | +echo -e " Claude: claude-opus-4-6 (default), claude-opus-4-5, claude-sonnet-4-5," |
| 144 | +echo -e " claude-sonnet-4, claude-haiku-4-5" |
| 145 | +echo -e " GPT: gpt-5, gpt-5-1, gpt-5-2" |
206 | 146 | echo "" |
207 | | -echo -e "${BLUE}To use with OpenCode:${NC}" |
208 | | -echo -e " 1. Start the server (npm start)" |
209 | | -echo -e " 2. Run OpenCode" |
210 | | -echo -e " 3. Type /models and select an augment-code/* model" |
| 147 | +echo -e "${BLUE}The plugin auto-configures everything:${NC}" |
| 148 | +echo -e " • Provider and models are registered automatically" |
| 149 | +echo -e " • An embedded server starts inside OpenCode (no separate process)" |
| 150 | +echo -e " • Authentication uses your existing auggie session" |
211 | 151 | echo "" |
0 commit comments