Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions .github/actions/setup-bun/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,37 @@ description: "Setup Bun with caching and install dependencies"
runs:
using: "composite"
steps:
- name: Get baseline download URL
- name: Ensure build tools are available
if: runner.os == 'Linux'
shell: bash
# Blacksmith's ARM64 ubuntu-2404 runners ship a minimal image that is missing:
# unzip — needed by oven-sh/setup-bun to extract the downloaded bun zip
# build-essential (make, g++) — needed by node-gyp to compile native addons
# (e.g. tree-sitter-powershell) during `bun install`
run: |
PKGS=()
command -v unzip >/dev/null 2>&1 || PKGS+=(unzip)
command -v make >/dev/null 2>&1 || PKGS+=(build-essential)
[ ${#PKGS[@]} -gt 0 ] && sudo apt-get install -y --no-install-recommends "${PKGS[@]}"
true

- name: Get bun download URL
id: bun-url
shell: bash
run: |
if [ "$RUNNER_ARCH" = "X64" ]; then
V=$(node -p "require('./package.json').packageManager.split('@')[1]")
case "$RUNNER_OS" in
macOS) OS=darwin ;;
Linux) OS=linux ;;
Windows) OS=windows ;;
esac
echo "url=https://github.com/oven-sh/bun/releases/download/bun-v${V}/bun-${OS}-x64-baseline.zip" >> "$GITHUB_OUTPUT"
fi
V=$(node -p "require('./package.json').packageManager.split('@')[1]")
case "$RUNNER_OS" in
macOS) OS=darwin ;;
Linux) OS=linux ;;
Windows) OS=windows ;;
*) exit 0 ;;
esac
case "$RUNNER_ARCH" in
X64) ARCH=x64-baseline ;;
ARM64) ARCH=aarch64 ;;
*) exit 0 ;;
esac
echo "url=https://github.com/oven-sh/bun/releases/download/bun-v${V}/bun-${OS}-${ARCH}.zip" >> "$GITHUB_OUTPUT"

- name: Setup Bun
uses: oven-sh/setup-bun@v2
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ jobs:
turbo-${{ runner.os }}-${{ hashFiles('turbo.json', '**/package.json') }}-
turbo-${{ runner.os }}-

- name: Cache npm registry packages
# Plugin integration tests install @opencode-ai/plugin into fresh temp dirs
# using @npmcli/arborist, which fetches from the npm registry and caches
# tarballs in ~/.npm. Without this cache, each test does a full network
# download, easily hitting the 30 s bun test timeout on Blacksmith ARM64.
uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ runner.os }}-${{ runner.arch }}-opencode-ai-plugin-${{ hashFiles('**/package.json') }}
restore-keys: |
npm-${{ runner.os }}-${{ runner.arch }}-opencode-ai-plugin-

- name: Warm npm cache for @opencode-ai/plugin
# Pre-populate ~/.npm so arborist can satisfy @opencode-ai/plugin from
# cache during plugin integration tests instead of hitting the registry.
if: runner.os == 'Linux'
run: npm install --prefix /tmp/plugin-warmup @opencode-ai/plugin

- name: Run unit tests
run: bun turbo test:ci
env:
Expand Down
80 changes: 80 additions & 0 deletions .opencode/sessions/chore-bolster-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Session: Bolster Install — Blacksmith ARM64 CI Fixes

**Branch**: chore/bolster-install
**Issue**: N/A
**Created**: 2026-04-22
**Status**: complete — PR #11 open, awaiting merge

## Goal
Harden the `install-flex` automated installer and fix all Blacksmith ARM64 CI
failures that were blocking the unit and e2e test jobs on the Flexion fork.

## Approach
Fix issues in layers as they surfaced during CI runs:
1. Add `install-flex` installer script
2. Pin `OPENCODE_CHANNEL=flex` to prevent per-branch SQLite DB fragmentation
3. Fix missing build tools on Blacksmith ARM64 runners
4. Fix unit test timeouts caused by arborist npm installs during tests
5. Bump individual test timeouts that are tight on ARM64

## Session Log
- 2026-04-22: Session created
- 2026-04-22: Added `install-flex` script (already existed on branch), fixed DB fragmentation
- 2026-04-22: CI round 1 — fixed `unzip` missing (setup-bun)
- 2026-04-22: CI round 2 — fixed `make`/`g++` missing (build-essential for node-gyp)
- 2026-04-22: CI round 3 — 7 test timeouts; root-caused to `@npmcli/arborist.reify()` in tests
- 2026-04-22: CI round 4 — 1 remaining timeout; fixed shell-loop test 3s → 15s
- 2026-04-22: All CI jobs passing. PR updated.
- 2026-04-22: CI round 5 — 1 new timeout; "shell rejects with BusyError when loop running" 3s → 15s

## Key Decisions

### `OPENCODE_CHANNEL=flex` in `install-flex`
OpenCode bakes `InstallationChannel` from the git branch at build time and uses it
as the SQLite DB name suffix (`opencode-<channel>.db`). Without pinning, each
rebuild from a different branch creates a fresh empty database, losing all session
history. Pinning to `"flex"` ensures all Flexion builds share `opencode-flex.db`.
See: `packages/opencode/src/storage/db.ts:getChannelPath()`.

### `OPENCODE_DISABLE_PLUGIN_DEPS_INSTALL` flag
`config.ts` fires a background `@npmcli/arborist.reify()` for `@opencode-ai/plugin`
in every `.opencode/` directory it discovers. In tests, 7 tests were timing out
because: plugin/tool tests called `waitForDependencies()` which joined the arborist
fiber (10–30 s per test on ARM64), and the resulting CPU saturation starved
concurrent session/snapshot tests. The flag skips the install in tests; safe because
bun resolves `@opencode-ai/plugin` from the workspace `node_modules` directly.
Set unconditionally in `test/preload.ts`.

### Blacksmith ARM64 runner gaps
`blacksmith-4vcpu-ubuntu-2404` uses ARM64 and ships a minimal Ubuntu image missing:
- `unzip` — needed by `oven-sh/setup-bun@v2` to extract the downloaded bun zip
- `make`/`g++` (build-essential) — needed by `node-gyp` for `tree-sitter-powershell`
Both now installed in a single `Ensure build tools are available` step in
`.github/actions/setup-bun/action.yml` (Linux only, no-op if already present).

### Test timeout bumps
- `snapshot.test.ts` "revert handles large mixed batches": 30 s → 60 s
(280 files + multiple git commits/patches/reverts on ARM64)
- `prompt-effect.test.ts` "loop waits while shell runs": 3 s → 15 s
(spawns a real `sleep 0.2` subprocess; ARM64 fork/exec overhead exceeds 3 s)
- `prompt-effect.test.ts` "shell rejects with BusyError when loop running": 3 s → 15 s
(fiber fork + session init before `llm.wait(1)` exceeds 3 s on ARM64)

## Files Changed
- `install-flex` — `OPENCODE_CHANNEL=flex` added to build command
- `.github/actions/setup-bun/action.yml` — build tools prereq + ARM64/X64 URL construction
- `.github/workflows/test.yml` — npm cache + pre-warm step (unit job)
- `packages/opencode/src/flag/flag.ts` — `OPENCODE_DISABLE_PLUGIN_DEPS_INSTALL` flag
- `packages/opencode/src/config/config.ts` — guard arborist install with new flag
- `packages/opencode/test/preload.ts` — set `OPENCODE_DISABLE_PLUGIN_DEPS_INSTALL=true`
- `packages/opencode/test/snapshot/snapshot.test.ts` — 60 s timeout on 280-file test
- `packages/opencode/test/session/prompt-effect.test.ts` — 15 s timeout on shell-loop test

## Side Effects Applied Outside the Repo
- `~/.opencode/bin/opencode` — rebuilt from this branch with `OPENCODE_CHANNEL=flex`;
now reports `0.0.0-flex-<timestamp>` and uses `~/.local/share/opencode/opencode-flex.db`

## Next Steps
- [ ] Merge PR #11 into flex: https://github.com/flexion/opencode/pull/11
- [ ] After merge, other developers run `install-flex` to pick up all fixes
- [ ] Consider periodically running `install-flex` to stay current with `flex` branch
42 changes: 34 additions & 8 deletions LOCAL_AWS_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

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

## Quick Install

The installer handles all steps below automatically:

```bash
curl -fsSL https://raw.githubusercontent.com/flexion/opencode/flex/install-flex | bash
```

You will be prompted for:
- **Clone directory** (default: `~/opencode`)
- **AWS account ID** (your personal Flexion account)
- **Preferred AWS region** (default: `us-east-1`)

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.

---

## Manual Setup

Follow these steps if you prefer to configure things yourself.

## Prerequisites

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

```ini
[profile ClaudeCodeAccess]
sso_start_url = <your-sso-start-url>
sso_region = <your-sso-region>
sso_start_url = https://identitycenter.amazonaws.com/ssoins-6684680a9b285ea2
sso_region = us-east-2
sso_account_id = <your-account-id>
sso_role_name = AdministratorAccess
region = <your-preferred-region>
sso_role_name = ClaudeCodeAccess
region = <your-preferred-region>
```

### 2. Configure opencode for Bedrock
Expand Down Expand Up @@ -118,20 +139,24 @@ Create `~/.config/opencode/opencode.json`:

### 3. Shell alias

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

```bash
# ── Flexion opencode launcher ─────────────────────────────────────────────────
opencode-work() {
local profile="ClaudeCodeAccess"
local arch os
case "$(uname -m)" in arm64|aarch64) arch="arm64" ;; *) arch="x64" ;; esac
case "$(uname -s)" in Darwin) os="darwin" ;; Linux) os="linux" ;; *)
echo "Unsupported OS: $(uname -s)" && return 1 ;; esac
echo "Logging in to AWS SSO ($profile)..."
aws sso login --profile "$profile" || return 1
eval "$(aws configure export-credentials --profile "$profile" --format env)"
/path/to/opencode/packages/opencode/dist/opencode-darwin-arm64/bin/opencode "${opencode_args[@]}"
"$HOME/opencode/packages/opencode/dist/opencode-${os}-${arch}/bin/opencode" "$@"
}
# ─────────────────────────────────────────────────────────────────────────────
```

Replace `/path/to/opencode` with where you cloned the repo (e.g. `~/Code/personal/flexion-work-items/flexchat-stack/opencode`).

### 4. Usage

```bash
Expand Down Expand Up @@ -174,6 +199,7 @@ See [flexion/opencode#2](https://github.com/flexion/opencode/pull/2) for the ful
| 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 |
| Exclude palmyra from reasoning variant generation | `packages/opencode/src/provider/transform.ts` | Prevents unsupported `reasoningConfig` parameters from being sent to Writer Palmyra models |
| Local build & AWS Bedrock setup docs | `LOCAL_AWS_SETUP.md` | This file |
| Automated installer | `install-flex` | Single-command installer for the entire setup |

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

Expand Down
Loading
Loading