Skip to content

Commit fb032ac

Browse files
committed
chore: add install-flex automated setup script and update docs
- add install-flex: single curl | bash installer that clones the flex branch, builds the binary, writes the AWS SSO profile, writes ~/.config/opencode/opencode.json, and appends opencode-work() to the user's shell rc file; all steps are idempotent - hardcode SSO start URL and us-east-2 SSO region; prompt only for account ID and preferred AWS region - correct sso_role_name from AdministratorAccess to ClaudeCodeAccess - fix opencode-work(): replace undeclared \${opencode_args[@]} with "\$@", replace hardcoded path and arch with runtime uname detection - add Quick Install section to LOCAL_AWS_SETUP.md
1 parent 2e92b8f commit fb032ac

2 files changed

Lines changed: 292 additions & 8 deletions

File tree

LOCAL_AWS_SETUP.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
Instructions for cloning, building, and running the Flexion fork of opencode with AWS Bedrock.
44

5+
## Quick Install
6+
7+
The installer handles all steps below automatically:
8+
9+
```bash
10+
curl -fsSL https://raw.githubusercontent.com/flexion/opencode/flex/install-flex | bash
11+
```
12+
13+
You will be prompted for:
14+
- **Clone directory** (default: `~/opencode`)
15+
- **AWS account ID** (your personal Flexion account)
16+
- **Preferred AWS region** (default: `us-east-1`)
17+
18+
Everything else — AWS SSO profile, opencode config, and the `opencode-work` shell function — is written automatically. Skip to [Usage](#4-usage) once the installer finishes.
19+
20+
---
21+
22+
## Manual Setup
23+
24+
Follow these steps if you prefer to configure things yourself.
25+
526
## Prerequisites
627

728
- [Bun](https://bun.sh) v1.3+
@@ -46,11 +67,11 @@ Add to `~/.aws/config`:
4667

4768
```ini
4869
[profile ClaudeCodeAccess]
49-
sso_start_url = <your-sso-start-url>
50-
sso_region = <your-sso-region>
70+
sso_start_url = https://identitycenter.amazonaws.com/ssoins-6684680a9b285ea2
71+
sso_region = us-east-2
5172
sso_account_id = <your-account-id>
52-
sso_role_name = AdministratorAccess
53-
region = <your-preferred-region>
73+
sso_role_name = ClaudeCodeAccess
74+
region = <your-preferred-region>
5475
```
5576

5677
### 2. Configure opencode for Bedrock
@@ -118,20 +139,24 @@ Create `~/.config/opencode/opencode.json`:
118139
119140
### 3. Shell alias
120141

121-
Add to `~/.zshrc` or `~/.bashrc`:
142+
Add to `~/.zshrc` or `~/.bashrc` (replace `~/opencode` with your actual clone path if different):
122143

123144
```bash
145+
# ── Flexion opencode launcher ─────────────────────────────────────────────────
124146
opencode-work() {
125147
local profile="ClaudeCodeAccess"
148+
local arch os
149+
case "$(uname -m)" in arm64|aarch64) arch="arm64" ;; *) arch="x64" ;; esac
150+
case "$(uname -s)" in Darwin) os="darwin" ;; Linux) os="linux" ;; *)
151+
echo "Unsupported OS: $(uname -s)" && return 1 ;; esac
126152
echo "Logging in to AWS SSO ($profile)..."
127153
aws sso login --profile "$profile" || return 1
128154
eval "$(aws configure export-credentials --profile "$profile" --format env)"
129-
/path/to/opencode/packages/opencode/dist/opencode-darwin-arm64/bin/opencode "${opencode_args[@]}"
155+
"$HOME/opencode/packages/opencode/dist/opencode-${os}-${arch}/bin/opencode" "$@"
130156
}
157+
# ─────────────────────────────────────────────────────────────────────────────
131158
```
132159

133-
Replace `/path/to/opencode` with where you cloned the repo (e.g. `~/Code/personal/flexion-work-items/flexchat-stack/opencode`).
134-
135160
### 4. Usage
136161

137162
```bash
@@ -174,6 +199,7 @@ See [flexion/opencode#2](https://github.com/flexion/opencode/pull/2) for the ful
174199
| Strip reasoning from history for non-reasoning models | `packages/opencode/src/provider/transform.ts` | Removes reasoning content parts from assistant message history before sending to models with `reasoning: false` — fixes Bedrock rejections when switching from a reasoning model |
175200
| Exclude palmyra from reasoning variant generation | `packages/opencode/src/provider/transform.ts` | Prevents unsupported `reasoningConfig` parameters from being sent to Writer Palmyra models |
176201
| Local build & AWS Bedrock setup docs | `LOCAL_AWS_SETUP.md` | This file |
202+
| Automated installer | `install-flex` | Single-command installer for the entire setup |
177203

178204
Full details and upstream tracking: [flexion/opencode#2](https://github.com/flexion/opencode/pull/2)
179205

install-flex

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
#!/usr/bin/env bash
2+
# install-flex — Flexion fork of opencode, automated installer
3+
#
4+
# Usage:
5+
# curl -fsSL https://raw.githubusercontent.com/flexion/opencode/flex/install-flex | bash
6+
#
7+
# What this does:
8+
# 1. Checks prerequisites (git, bun, aws-cli v2)
9+
# 2. Prompts: clone directory, AWS account ID, preferred AWS region
10+
# 3. Clones git@github.com:flexion/opencode.git (flex branch) — skipped if already present
11+
# 4. Installs dependencies and builds the native binary
12+
# 5. Writes [profile ClaudeCodeAccess] to ~/.aws/config
13+
# 6. Writes ~/.config/opencode/opencode.json (Bedrock + model config)
14+
# 7. Appends opencode-work() launcher function to ~/.zshrc or ~/.bashrc
15+
#
16+
# Existing files are never overwritten; each step is skipped with a warning
17+
# if the output already exists.
18+
19+
set -euo pipefail
20+
21+
# ── colors ────────────────────────────────────────────────────────────────────
22+
if [ -t 1 ]; then
23+
BOLD=$'\033[1m'; GREEN=$'\033[0;32m'; YELLOW=$'\033[1;33m'
24+
BLUE=$'\033[0;34m'; RED=$'\033[0;31m'; NC=$'\033[0m'
25+
else
26+
BOLD=''; GREEN=''; YELLOW=''; BLUE=''; RED=''; NC=''
27+
fi
28+
29+
# ── constants ─────────────────────────────────────────────────────────────────
30+
SSO_START_URL="https://identitycenter.amazonaws.com/ssoins-6684680a9b285ea2"
31+
SSO_REGION="us-east-2"
32+
SSO_ROLE_NAME="ClaudeCodeAccess"
33+
AWS_PROFILE="ClaudeCodeAccess"
34+
REPO_URL="git@github.com:flexion/opencode.git"
35+
BRANCH="flex"
36+
37+
# ── helpers ───────────────────────────────────────────────────────────────────
38+
info() { printf '%s▶%s %s\n' "$BLUE" "$NC" "$*"; }
39+
success() { printf '%s✔%s %s\n' "$GREEN" "$NC" "$*"; }
40+
warn() { printf '%s⚠%s %s\n' "$YELLOW" "$NC" "$*"; }
41+
die() { printf '%s✖%s %s\n' "$RED" "$NC" "$*" >&2; exit 1; }
42+
43+
# ── step 1: prerequisites ─────────────────────────────────────────────────────
44+
check_prereqs() {
45+
info "Checking prerequisites..."
46+
local missing=()
47+
command -v git >/dev/null 2>&1 || missing+=("git")
48+
command -v bun >/dev/null 2>&1 || missing+=("bun (https://bun.sh)")
49+
command -v aws >/dev/null 2>&1 || missing+=("aws-cli v2 (https://aws.amazon.com/cli/)")
50+
if [ ${#missing[@]} -gt 0 ]; then
51+
die "Missing prerequisites:$(printf '\n • %s' "${missing[@]}")"
52+
fi
53+
success "Prerequisites OK"
54+
}
55+
56+
# ── step 2: gather inputs ─────────────────────────────────────────────────────
57+
# All reads use /dev/tty so prompts work when stdin is the script (curl | bash).
58+
gather_inputs() {
59+
printf '\n%sFlexion opencode installer%s\n' "$BOLD" "$NC"
60+
printf '────────────────────────────────────────────\n'
61+
62+
printf 'Clone directory [%s]: ' "$HOME/opencode" >/dev/tty
63+
IFS= read -r CLONE_DIR </dev/tty
64+
CLONE_DIR="${CLONE_DIR:-$HOME/opencode}"
65+
66+
while true; do
67+
printf 'AWS account ID: ' >/dev/tty
68+
IFS= read -r ACCOUNT_ID </dev/tty
69+
[ -n "${ACCOUNT_ID:-}" ] && break
70+
warn "AWS account ID is required."
71+
done
72+
73+
printf 'Preferred AWS region [us-east-1]: ' >/dev/tty
74+
IFS= read -r AWS_REGION </dev/tty
75+
AWS_REGION="${AWS_REGION:-us-east-1}"
76+
echo
77+
}
78+
79+
# ── step 3: clone & build ─────────────────────────────────────────────────────
80+
clone_and_build() {
81+
if [ -d "$CLONE_DIR/.git" ]; then
82+
warn "Directory $CLONE_DIR already exists — skipping clone"
83+
info "Fetching and checking out $BRANCH branch..."
84+
git -C "$CLONE_DIR" fetch origin
85+
git -C "$CLONE_DIR" checkout "$BRANCH"
86+
else
87+
info "Cloning $REPO_URL$CLONE_DIR ..."
88+
git clone --branch "$BRANCH" "$REPO_URL" "$CLONE_DIR"
89+
fi
90+
91+
info "Installing dependencies..."
92+
# BUN_CONFIG_REGISTRY override prevents private registry redirects (e.g. CMS Artifactory)
93+
# from breaking public package resolution.
94+
(cd "$CLONE_DIR" && BUN_CONFIG_REGISTRY=https://registry.npmjs.org bun install)
95+
96+
info "Building opencode binary (this takes about a minute)..."
97+
BUN_CONFIG_REGISTRY=https://registry.npmjs.org \
98+
bun run --cwd "$CLONE_DIR/packages/opencode" build --single --skip-embed-web-ui
99+
100+
success "Binary built"
101+
}
102+
103+
# ── step 4: AWS SSO config ────────────────────────────────────────────────────
104+
write_aws_config() {
105+
mkdir -p "$HOME/.aws"
106+
local config="$HOME/.aws/config"
107+
108+
if grep -q "\[profile $AWS_PROFILE\]" "$config" 2>/dev/null; then
109+
warn "AWS profile [$AWS_PROFILE] already in $config — skipping"
110+
return
111+
fi
112+
113+
info "Writing AWS SSO profile to $config..."
114+
cat >>"$config" <<EOF
115+
116+
[profile $AWS_PROFILE]
117+
sso_start_url = $SSO_START_URL
118+
sso_region = $SSO_REGION
119+
sso_account_id = $ACCOUNT_ID
120+
sso_role_name = $SSO_ROLE_NAME
121+
region = $AWS_REGION
122+
EOF
123+
success "AWS profile [$AWS_PROFILE] written"
124+
}
125+
126+
# ── step 5: opencode provider config ─────────────────────────────────────────
127+
write_opencode_config() {
128+
local config_dir="$HOME/.config/opencode"
129+
local config_file="$config_dir/opencode.json"
130+
mkdir -p "$config_dir"
131+
132+
if [ -f "$config_file" ]; then
133+
warn "opencode config already exists at $config_file — skipping"
134+
return
135+
fi
136+
137+
info "Writing opencode config to $config_file..."
138+
cat >"$config_file" <<EOF
139+
{
140+
"\$schema": "https://opencode.ai/config.json",
141+
"model": "amazon-bedrock/us.anthropic.claude-sonnet-4-6",
142+
"enabled_providers": ["amazon-bedrock"],
143+
"plugin": [],
144+
"provider": {
145+
"amazon-bedrock": {
146+
"options": {
147+
"region": "$AWS_REGION"
148+
},
149+
"models": {
150+
"writer.palmyra-x4-v1:0": {
151+
"name": "Writer Palmyra X4",
152+
"tool_call": false,
153+
"limit": { "context": 128000, "output": 8192 }
154+
},
155+
"writer.palmyra-x5-v1:0": {
156+
"name": "Writer Palmyra X5",
157+
"tool_call": false,
158+
"limit": { "context": 1000000, "output": 8192 }
159+
},
160+
"deepseek.r1-v1:0": {
161+
"name": "DeepSeek R1 (A)",
162+
"tool_call": false,
163+
"reasoning": false,
164+
"limit": { "context": 64000, "output": 32768 }
165+
},
166+
"mistral.pixtral-large-2502-v1:0": {
167+
"name": "Mistral Pixtral Large",
168+
"tool_call": false,
169+
"limit": { "context": 128000, "output": 8192 }
170+
},
171+
"meta.llama4-maverick-17b-instruct-v1:0": {
172+
"name": "Meta Llama 4 Maverick 17B",
173+
"tool_call": false,
174+
"limit": { "context": 1000000, "output": 8192 }
175+
},
176+
"meta.llama4-scout-17b-instruct-v1:0": {
177+
"name": "Meta Llama 4 Scout 17B",
178+
"tool_call": false,
179+
"limit": { "context": 10000000, "output": 8192 }
180+
},
181+
"amazon.nova-2-lite-v1:0": {
182+
"name": "Amazon Nova 2 Lite",
183+
"limit": { "context": 300000, "output": 5120 }
184+
}
185+
}
186+
}
187+
}
188+
}
189+
EOF
190+
success "opencode config written"
191+
}
192+
193+
# ── step 6: shell launcher function ──────────────────────────────────────────
194+
write_shell_alias() {
195+
local rc_file
196+
case "$(basename "${SHELL:-bash}")" in
197+
zsh) rc_file="$HOME/.zshrc" ;;
198+
*) rc_file="$HOME/.bashrc" ;;
199+
esac
200+
201+
if grep -q "opencode-work()" "$rc_file" 2>/dev/null; then
202+
warn "opencode-work() already defined in $rc_file — skipping"
203+
return
204+
fi
205+
206+
info "Appending opencode-work() to $rc_file..."
207+
208+
# Single-quoted heredoc prevents variable expansion inside the function body.
209+
# CLONE_DIR_PLACEHOLDER is substituted after writing via perl.
210+
cat >>"$rc_file" <<'SHELL_EOF'
211+
212+
# ── Flexion opencode launcher ─────────────────────────────────────────────────
213+
opencode-work() {
214+
local profile="ClaudeCodeAccess"
215+
local arch os
216+
case "$(uname -m)" in arm64|aarch64) arch="arm64" ;; *) arch="x64" ;; esac
217+
case "$(uname -s)" in Darwin) os="darwin" ;; Linux) os="linux" ;; *)
218+
echo "Unsupported OS: $(uname -s)" && return 1 ;; esac
219+
echo "Logging in to AWS SSO ($profile)..."
220+
aws sso login --profile "$profile" || return 1
221+
eval "$(aws configure export-credentials --profile "$profile" --format env)"
222+
"CLONE_DIR_PLACEHOLDER/packages/opencode/dist/opencode-${os}-${arch}/bin/opencode" "$@"
223+
}
224+
# ─────────────────────────────────────────────────────────────────────────────
225+
SHELL_EOF
226+
227+
# Substitute actual clone path. Uses | as delimiter to safely handle / in paths.
228+
perl -i -pe "s|CLONE_DIR_PLACEHOLDER|${CLONE_DIR}|g" "$rc_file"
229+
230+
success "opencode-work() added to $rc_file"
231+
}
232+
233+
# ── main ──────────────────────────────────────────────────────────────────────
234+
main() {
235+
check_prereqs
236+
gather_inputs
237+
clone_and_build
238+
write_aws_config
239+
write_opencode_config
240+
write_shell_alias
241+
242+
local rc_file
243+
case "$(basename "${SHELL:-bash}")" in
244+
zsh) rc_file="~/.zshrc" ;;
245+
*) rc_file="~/.bashrc" ;;
246+
esac
247+
248+
printf '\n%s%sInstallation complete!%s\n' "$GREEN" "$BOLD" "$NC"
249+
printf '────────────────────────────────────────────\n'
250+
printf ' Binary: %s/packages/opencode/dist/opencode-*/bin/opencode\n' "$CLONE_DIR"
251+
printf ' AWS: profile=%s account=%s region=%s\n' "$AWS_PROFILE" "$ACCOUNT_ID" "$AWS_REGION"
252+
printf ' Config: %s/.config/opencode/opencode.json\n' "$HOME"
253+
printf '\n Next steps:\n'
254+
printf ' 1. source %s\n' "$rc_file"
255+
printf ' 2. opencode-work\n\n'
256+
}
257+
258+
main

0 commit comments

Comments
 (0)