Skip to content

Commit ac0fbef

Browse files
committed
♻️ refactor: rewrite setup script for plugin-based architecture
- Build plugin instead of configuring standalone server - Add plugin path to opencode.json plugin array - Set up auth.json with auggie session entry - Remove manual provider/model configuration (plugin handles it) - Fix JS syntax bug with unquoted bracket notation
1 parent 4fbf833 commit ac0fbef

File tree

1 file changed

+87
-147
lines changed

1 file changed

+87
-147
lines changed

setup.sh

Lines changed: 87 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,211 +1,151 @@
11
#!/bin/bash
22

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.
56

67
set -e
78

89
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
PLUGIN_DIR="$SCRIPT_DIR/plugin"
911
OPENCODE_CONFIG_DIR="$HOME/.config/opencode"
1012
OPENCODE_CONFIG_FILE="$OPENCODE_CONFIG_DIR/opencode.json"
1113

12-
# Colors for output
14+
# Colors
1315
RED='\033[0;31m'
1416
GREEN='\033[0;32m'
1517
YELLOW='\033[1;33m'
1618
BLUE='\033[0;34m'
17-
NC='\033[0m' # No Color
19+
NC='\033[0m'
1820

1921
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
20-
echo -e "${BLUE} Auggie Wrapper Setup Script ${NC}"
22+
echo -e "${BLUE}Augment Code for OpenCode — Setup ║${NC}"
2123
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
2224
echo ""
2325

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
2631
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}"
2833
exit 1
2934
fi
30-
3135
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}"
3438
exit 1
3539
fi
36-
echo -e "${GREEN}✓ Node.js $(node -v) detected${NC}"
40+
echo -e "${GREEN}✓ Node.js $(node -v)${NC}"
3741

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
4048
if ! command -v auggie &> /dev/null; then
4149
echo -e "${YELLOW}Auggie CLI not found. Installing...${NC}"
4250
npm install -g @augmentcode/auggie
4351
fi
4452
echo -e "${GREEN}✓ Auggie CLI installed${NC}"
4553

46-
# Check for authentication
54+
# Authentication
4755
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}"
5057
auggie login
5158
fi
5259
echo -e "${GREEN}✓ Auggie authenticated${NC}"
5360

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"
5766
npm install
58-
echo -e "${GREEN}✓ Dependencies installed${NC}"
67+
npm run build
68+
echo -e "${GREEN}✓ Plugin built${NC}"
5969

60-
# Configure OpenCode
61-
echo -e "${YELLOW}Configuring OpenCode...${NC}"
70+
# ─── Configure OpenCode ─────────────────────────────────────────────────────
6271

63-
# Create config directory if it doesn't exist
72+
echo ""
73+
echo -e "${YELLOW}Configuring OpenCode...${NC}"
6474
mkdir -p "$OPENCODE_CONFIG_DIR"
6575

66-
# Augment Code provider configuration - All models
6776
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}"
7180
else
72-
# Backup existing config
81+
# Backup and merge
7382
cp "$OPENCODE_CONFIG_FILE" "$OPENCODE_CONFIG_FILE.backup.$(date +%Y%m%d%H%M%S)"
7483
echo -e "${YELLOW}Backed up existing config${NC}"
7584

76-
# Use node to merge the configuration
7785
node -e "
7886
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');
8491
}
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}"
13296
fi
13397
else
134-
# Create new config file
135-
cat > "$OPENCODE_CONFIG_FILE" << 'EOF'
98+
cat > "$OPENCODE_CONFIG_FILE" << EOF
13699
{
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"
181103
}
182104
EOF
183-
echo -e "${GREEN}✓ Created new OpenCode config with Augment Code provider${NC}"
105+
echo -e "${GREEN}✓ Created OpenCode config${NC}"
184106
fi
185107

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+
186134
echo ""
187135
echo -e "${GREEN}╔════════════════════════════════════════════════════════════╗${NC}"
188136
echo -e "${GREEN}║ Setup Complete! ║${NC}"
189137
echo -e "${GREEN}╚════════════════════════════════════════════════════════════╝${NC}"
190138
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"
194141
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"
206146
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"
211151
echo ""

0 commit comments

Comments
 (0)