Files
chaos c39549fbb5 Initial commit: opencode config with 32 skills, 3 agents, 11 MCPs
- Cross-platform install scripts (Windows PowerShell + Unix bash)
- Template-based config generation with env var support
- Skills: coding-standards, frontend-patterns, backend-patterns,
  security-review, tdd-workflow, e2e-testing, deep-research,
  exa-search, content-engine, crosspost, x-api, and 20 more
- Agents: explorer, reviewer, docs-researcher
- MCPs: codegraph, brave-search, playwright, github, context7,
  exa, memory, sequential-thinking, git, filesystem
2026-06-11 21:46:50 +08:00

172 lines
6.6 KiB
PowerShell

#Requires -Version 5.1
<#
.SYNOPSIS
Install opencode config on Windows
.DESCRIPTION
Copies config template, replaces placeholders, sets up ~/.config/opencode/
#>
$ErrorActionPreference = "Stop"
$ConfigDir = "$env:USERPROFILE\.config\opencode"
$RepoDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Opencode Config Installer (Windows)" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Check prerequisites
Write-Host "[*] Checking prerequisites..." -ForegroundColor Yellow
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Error "Git not found. Install from https://git-scm.com/download/win"
}
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
Write-Error "npm not found. Install Node.js from https://nodejs.org/"
}
Write-Host "[OK] Prerequisites met" -ForegroundColor Green
Write-Host ""
# Get or prompt for API keys
function Get-EnvOrPrompt($name, $prompt, $required = $false) {
$val = [Environment]::GetEnvironmentVariable($name, "User")
if (-not $val) { $val = [Environment]::GetEnvironmentVariable($name, "Process") }
if (-not $val) {
if ($required) {
$val = Read-Host -Prompt "$prompt (required)"
if (-not $val) { Write-Error "$name is required" }
} else {
$val = Read-Host -Prompt "$prompt (optional, press Enter to skip)"
}
if ($val) {
[Environment]::SetEnvironmentVariable($name, $val, "User")
Write-Host " Saved $name to User environment variables" -ForegroundColor DarkGray
}
} else {
Write-Host " Found $name in environment" -ForegroundColor DarkGray
}
return $val
}
Write-Host "[*] Configuring secrets..." -ForegroundColor Yellow
$apiKey = Get-EnvOrPrompt -name "OPENCODE_API_KEY" -prompt "Enter your OpenAI-compatible API key" -required $true
$braveKey = Get-EnvOrPrompt -name "BRAVE_API_KEY" -prompt "Enter your Brave Search API key"
# Detect or prompt for projects path
$projectsPath = [Environment]::GetEnvironmentVariable("PROJECTS_PATH", "User")
if (-not $projectsPath) { $projectsPath = [Environment]::GetEnvironmentVariable("PROJECTS_PATH", "Process") }
if (-not $projectsPath) {
$defaultPath = "D:\Projects"
$projectsPath = Read-Host -Prompt "Enter your projects directory path [default: $defaultPath]"
if (-not $projectsPath) { $projectsPath = $defaultPath }
if (-not (Test-Path $projectsPath)) {
Write-Host " Creating projects directory: $projectsPath" -ForegroundColor DarkYellow
New-Item -ItemType Directory -Path $projectsPath -Force | Out-Null
}
[Environment]::SetEnvironmentVariable("PROJECTS_PATH", $projectsPath, "User")
}
Write-Host "[OK] Projects path: $projectsPath" -ForegroundColor Green
Write-Host ""
# Backup existing config
if (Test-Path "$ConfigDir\opencode.json") {
$backup = "$ConfigDir\opencode.json.backup.$(Get-Date -Format 'yyyyMMddHHmmss')"
Copy-Item "$ConfigDir\opencode.json" $backup
Write-Host "[*] Backed up existing config to: $backup" -ForegroundColor Yellow
}
# Create config directory
if (-not (Test-Path $ConfigDir)) {
New-Item -ItemType Directory -Path $ConfigDir -Force | Out-Null
}
# Generate opencode.json from template
Write-Host "[*] Generating opencode.json..." -ForegroundColor Yellow
$template = Get-Content "$RepoDir\opencode.json.template" -Raw
$template = $template -replace '\$\{OPENCODE_API_KEY\}', $apiKey
$template = $template -replace '\$\{BRAVE_API_KEY\}', $braveKey
$template = $template -replace '\$\{PROJECTS_PATH\}', ($projectsPath -replace '\\', '\\')
# Disable brave-search if no key
if (-not $braveKey) {
Write-Host " [!] No Brave API key - disabling brave-search MCP" -ForegroundColor DarkYellow
$template = $template -replace '"enabled": true,\r?\n\s*"env": \{\r?\n\s*"BRAVE_API_KEY": "\$\{BRAVE_API_KEY\}"\r?\n\s*\}', '"enabled": false'
}
$template | Set-Content "$ConfigDir\opencode.json" -Encoding UTF8
Write-Host "[OK] Config written to $ConfigDir\opencode.json" -ForegroundColor Green
Write-Host ""
# Copy agents and skills
Write-Host "[*] Syncing agents and skills..." -ForegroundColor Yellow
# Remove old skills/agents to ensure clean sync
if (Test-Path "$ConfigDir\agents") { Remove-Item "$ConfigDir\agents" -Recurse -Force }
if (Test-Path "$ConfigDir\skills") { Remove-Item "$ConfigDir\skills" -Recurse -Force }
Copy-Item "$RepoDir\agents" $ConfigDir -Recurse
Copy-Item "$RepoDir\skills" $ConfigDir -Recurse
$skillCount = (Get-ChildItem "$ConfigDir\skills" -Directory).Count
Write-Host "[OK] Copied 3 agents and $skillCount skills" -ForegroundColor Green
Write-Host ""
# Install global dependencies
Write-Host "[*] Installing global dependencies..." -ForegroundColor Yellow
$globalPackages = @(
"@colbymchenry/codegraph",
"@brave/brave-search-mcp-server",
"@modelcontextprotocol/server-filesystem",
"@modelcontextprotocol/server-github",
"@modelcontextprotocol/server-memory",
"@modelcontextprotocol/server-sequential-thinking",
"@playwright/mcp",
"@upstash/context7-mcp",
"mcp-remote"
)
foreach ($pkg in $globalPackages) {
Write-Host " Installing $pkg..." -ForegroundColor DarkGray -NoNewline
npm install -g $pkg 2>$null | Out-Null
Write-Host " OK" -ForegroundColor Green
}
# Install Python git MCP
Write-Host " Installing Python git MCP..." -ForegroundColor DarkGray -NoNewline
python -m pip install mcp-server-git 2>$null | Out-Null
Write-Host " OK" -ForegroundColor Green
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Installation Complete!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Next steps:" -ForegroundColor White
Write-Host " 1. Restart opencode to load new config" -ForegroundColor White
Write-Host " 2. Run 'opencode' in your project directory" -ForegroundColor White
Write-Host " 3. Initialize CodeGraph: codegraph init" -ForegroundColor White
Write-Host ""
Write-Host "Config location: $ConfigDir" -ForegroundColor DarkGray
Write-Host ""
# Verify config
Write-Host "[*] Verifying config..." -ForegroundColor Yellow
try {
$config = Get-Content "$ConfigDir\opencode.json" | ConvertFrom-Json
$mcpCount = ($config.mcp | Get-Member -MemberType NoteProperty).Count
Write-Host "[OK] Config valid - $mcpCount MCP servers configured" -ForegroundColor Green
} catch {
Write-Warning "Config may have syntax issues - please check $ConfigDir\opencode.json"
}