From ea055e0e874052393e39d1907f8332d7ec5250e8 Mon Sep 17 00:00:00 2001 From: Break Date: Sun, 12 Apr 2026 23:19:19 +0800 Subject: [PATCH] fix: add opencode setup support --- hosts/opencode.ts | 4 +- setup | 119 ++++++++++++++++++++++++++++++++++-- test/gen-skill-docs.test.ts | 23 +++++-- test/host-config.test.ts | 15 +++++ 4 files changed, 151 insertions(+), 10 deletions(-) diff --git a/hosts/opencode.ts b/hosts/opencode.ts index dc4a5bfc..3ad0901e 100644 --- a/hosts/opencode.ts +++ b/hosts/opencode.ts @@ -31,9 +31,9 @@ const opencode: HostConfig = { suppressedResolvers: ['GBRAIN_CONTEXT_LOAD', 'GBRAIN_SAVE_RESULTS'], runtimeRoot: { - globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'], + globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'design/dist', 'gstack-upgrade', 'ETHOS.md', 'review/specialists', 'qa/templates', 'qa/references', 'plan-devex-review/dx-hall-of-fame.md'], globalFiles: { - 'review': ['checklist.md', 'TODOS-format.md'], + 'review': ['checklist.md', 'design-checklist.md', 'greptile-triage.md', 'TODOS-format.md'], }, }, diff --git a/setup b/setup index 5b974e23..94731421 100755 --- a/setup +++ b/setup @@ -22,6 +22,8 @@ CODEX_SKILLS="$HOME/.codex/skills" CODEX_GSTACK="$CODEX_SKILLS/gstack" FACTORY_SKILLS="$HOME/.factory/skills" FACTORY_GSTACK="$FACTORY_SKILLS/gstack" +OPENCODE_SKILLS="$HOME/.config/opencode/skills" +OPENCODE_GSTACK="$OPENCODE_SKILLS/gstack" IS_WINDOWS=0 case "$(uname -s)" in @@ -41,7 +43,7 @@ TEAM_MODE=0 NO_TEAM_MODE=0 while [ $# -gt 0 ]; do case "$1" in - --host) [ -z "$2" ] && echo "Missing value for --host (expected claude, codex, kiro, or auto)" >&2 && exit 1; HOST="$2"; shift 2 ;; + --host) [ -z "$2" ] && echo "Missing value for --host (expected claude, codex, kiro, opencode, or auto)" >&2 && exit 1; HOST="$2"; shift 2 ;; --host=*) HOST="${1#--host=}"; shift ;; --local) LOCAL_INSTALL=1; shift ;; --prefix) SKILL_PREFIX=1; SKILL_PREFIX_FLAG=1; shift ;; @@ -54,7 +56,7 @@ while [ $# -gt 0 ]; do done case "$HOST" in - claude|codex|kiro|factory|auto) ;; + claude|codex|kiro|factory|opencode|auto) ;; openclaw) echo "" echo "OpenClaw integration uses a different model — OpenClaw spawns Claude Code" @@ -89,7 +91,7 @@ case "$HOST" in echo "GBrain setup and brain skills ship from the GBrain repo." echo "" exit 0 ;; - *) echo "Unknown --host value: $HOST (expected claude, codex, kiro, factory, openclaw, hermes, gbrain, or auto)" >&2; exit 1 ;; + *) echo "Unknown --host value: $HOST (expected claude, codex, kiro, factory, opencode, openclaw, hermes, gbrain, or auto)" >&2; exit 1 ;; esac # ─── Resolve skill prefix preference ───────────────────────── @@ -152,13 +154,15 @@ INSTALL_CLAUDE=0 INSTALL_CODEX=0 INSTALL_KIRO=0 INSTALL_FACTORY=0 +INSTALL_OPENCODE=0 if [ "$HOST" = "auto" ]; then command -v claude >/dev/null 2>&1 && INSTALL_CLAUDE=1 command -v codex >/dev/null 2>&1 && INSTALL_CODEX=1 command -v kiro-cli >/dev/null 2>&1 && INSTALL_KIRO=1 command -v droid >/dev/null 2>&1 && INSTALL_FACTORY=1 + command -v opencode >/dev/null 2>&1 && INSTALL_OPENCODE=1 # If none found, default to claude - if [ "$INSTALL_CLAUDE" -eq 0 ] && [ "$INSTALL_CODEX" -eq 0 ] && [ "$INSTALL_KIRO" -eq 0 ] && [ "$INSTALL_FACTORY" -eq 0 ]; then + if [ "$INSTALL_CLAUDE" -eq 0 ] && [ "$INSTALL_CODEX" -eq 0 ] && [ "$INSTALL_KIRO" -eq 0 ] && [ "$INSTALL_FACTORY" -eq 0 ] && [ "$INSTALL_OPENCODE" -eq 0 ]; then INSTALL_CLAUDE=1 fi elif [ "$HOST" = "claude" ]; then @@ -169,6 +173,8 @@ elif [ "$HOST" = "kiro" ]; then INSTALL_KIRO=1 elif [ "$HOST" = "factory" ]; then INSTALL_FACTORY=1 +elif [ "$HOST" = "opencode" ]; then + INSTALL_OPENCODE=1 fi migrate_direct_codex_install() { @@ -271,6 +277,16 @@ if [ "$INSTALL_FACTORY" -eq 1 ] && [ "$NEEDS_BUILD" -eq 0 ]; then ) fi +# 1d. Generate .opencode/ OpenCode skill docs +if [ "$INSTALL_OPENCODE" -eq 1 ] && [ "$NEEDS_BUILD" -eq 0 ]; then + log "Generating .opencode/ skill docs..." + ( + cd "$SOURCE_GSTACK_DIR" + bun install --frozen-lockfile 2>/dev/null || bun install + bun run gen:skill-docs --host opencode + ) +fi + # 2. Ensure Playwright's Chromium is available if ! ensure_playwright_browser; then echo "Installing Playwright Chromium..." @@ -596,6 +612,59 @@ create_factory_runtime_root() { fi } +create_opencode_runtime_root() { + local gstack_dir="$1" + local opencode_gstack="$2" + local opencode_dir="$gstack_dir/.opencode/skills" + + if [ -L "$opencode_gstack" ]; then + rm -f "$opencode_gstack" + elif [ -d "$opencode_gstack" ] && [ "$opencode_gstack" != "$gstack_dir" ]; then + rm -rf "$opencode_gstack" + fi + + mkdir -p "$opencode_gstack" "$opencode_gstack/browse" "$opencode_gstack/design" "$opencode_gstack/gstack-upgrade" "$opencode_gstack/review" "$opencode_gstack/qa" "$opencode_gstack/plan-devex-review" + + if [ -f "$opencode_dir/gstack/SKILL.md" ]; then + ln -snf "$opencode_dir/gstack/SKILL.md" "$opencode_gstack/SKILL.md" + fi + if [ -d "$gstack_dir/bin" ]; then + ln -snf "$gstack_dir/bin" "$opencode_gstack/bin" + fi + if [ -d "$gstack_dir/browse/dist" ]; then + ln -snf "$gstack_dir/browse/dist" "$opencode_gstack/browse/dist" + fi + if [ -d "$gstack_dir/browse/bin" ]; then + ln -snf "$gstack_dir/browse/bin" "$opencode_gstack/browse/bin" + fi + if [ -d "$gstack_dir/design/dist" ]; then + ln -snf "$gstack_dir/design/dist" "$opencode_gstack/design/dist" + fi + if [ -f "$opencode_dir/gstack-upgrade/SKILL.md" ]; then + ln -snf "$opencode_dir/gstack-upgrade/SKILL.md" "$opencode_gstack/gstack-upgrade/SKILL.md" + fi + for f in checklist.md design-checklist.md greptile-triage.md TODOS-format.md; do + if [ -f "$gstack_dir/review/$f" ]; then + ln -snf "$gstack_dir/review/$f" "$opencode_gstack/review/$f" + fi + done + if [ -d "$gstack_dir/review/specialists" ]; then + ln -snf "$gstack_dir/review/specialists" "$opencode_gstack/review/specialists" + fi + if [ -d "$gstack_dir/qa/templates" ]; then + ln -snf "$gstack_dir/qa/templates" "$opencode_gstack/qa/templates" + fi + if [ -d "$gstack_dir/qa/references" ]; then + ln -snf "$gstack_dir/qa/references" "$opencode_gstack/qa/references" + fi + if [ -f "$gstack_dir/plan-devex-review/dx-hall-of-fame.md" ]; then + ln -snf "$gstack_dir/plan-devex-review/dx-hall-of-fame.md" "$opencode_gstack/plan-devex-review/dx-hall-of-fame.md" + fi + if [ -f "$gstack_dir/ETHOS.md" ]; then + ln -snf "$gstack_dir/ETHOS.md" "$opencode_gstack/ETHOS.md" + fi +} + link_factory_skill_dirs() { local gstack_dir="$1" local skills_dir="$2" @@ -628,6 +697,38 @@ link_factory_skill_dirs() { fi } +link_opencode_skill_dirs() { + local gstack_dir="$1" + local skills_dir="$2" + local opencode_dir="$gstack_dir/.opencode/skills" + local linked=() + + if [ ! -d "$opencode_dir" ]; then + echo " Generating .opencode/ skill docs..." + ( cd "$gstack_dir" && bun run gen:skill-docs --host opencode ) + fi + + if [ ! -d "$opencode_dir" ]; then + echo " warning: .opencode/skills/ generation failed — run 'bun run gen:skill-docs --host opencode' manually" >&2 + return 1 + fi + + for skill_dir in "$opencode_dir"/gstack*/; do + if [ -f "$skill_dir/SKILL.md" ]; then + skill_name="$(basename "$skill_dir")" + [ "$skill_name" = "gstack" ] && continue + target="$skills_dir/$skill_name" + if [ -L "$target" ] || [ ! -e "$target" ]; then + ln -snf "$skill_dir" "$target" + linked+=("$skill_name") + fi + fi + done + if [ ${#linked[@]} -gt 0 ]; then + echo " linked skills: ${linked[*]}" + fi +} + # 4. Install for Claude (default) SKILLS_BASENAME="$(basename "$INSTALL_SKILLS_DIR")" SKILLS_PARENT_BASENAME="$(basename "$(dirname "$INSTALL_SKILLS_DIR")")" @@ -790,6 +891,16 @@ if [ "$INSTALL_FACTORY" -eq 1 ]; then echo " factory skills: $FACTORY_SKILLS" fi +# 6c. Install for OpenCode +if [ "$INSTALL_OPENCODE" -eq 1 ]; then + mkdir -p "$OPENCODE_SKILLS" + create_opencode_runtime_root "$SOURCE_GSTACK_DIR" "$OPENCODE_GSTACK" + link_opencode_skill_dirs "$SOURCE_GSTACK_DIR" "$OPENCODE_SKILLS" + echo "gstack ready (opencode)." + echo " browse: $BROWSE_BIN" + echo " opencode skills: $OPENCODE_SKILLS" +fi + # 7. Create .agents/ sidecar symlinks for the real Codex skill target. # The root Codex skill ends up pointing at $SOURCE_GSTACK_DIR/.agents/skills/gstack, # so the runtime assets must live there for both global and repo-local installs. diff --git a/test/gen-skill-docs.test.ts b/test/gen-skill-docs.test.ts index a555104d..00c104d8 100644 --- a/test/gen-skill-docs.test.ts +++ b/test/gen-skill-docs.test.ts @@ -2115,15 +2115,16 @@ describe('setup script validation', () => { expect(fnBody).toContain('rm -f "$target"'); }); - test('setup supports --host auto|claude|codex|kiro', () => { + test('setup supports --host auto|claude|codex|kiro|opencode', () => { expect(setupContent).toContain('--host'); - expect(setupContent).toContain('claude|codex|kiro|factory|auto'); + expect(setupContent).toContain('claude|codex|kiro|factory|opencode|auto'); }); - test('auto mode detects claude, codex, and kiro binaries', () => { + test('auto mode detects claude, codex, kiro, and opencode binaries', () => { expect(setupContent).toContain('command -v claude'); expect(setupContent).toContain('command -v codex'); expect(setupContent).toContain('command -v kiro-cli'); + expect(setupContent).toContain('command -v opencode'); }); // T1: Sidecar skip guard — prevents .agents/skills/gstack from being linked as a skill @@ -2143,7 +2144,6 @@ describe('setup script validation', () => { expect(content).toContain('$GSTACK_BIN/'); }); - // T3: Kiro host support in setup script test('setup supports --host kiro with install section and sed rewrites', () => { expect(setupContent).toContain('INSTALL_KIRO='); expect(setupContent).toContain('kiro-cli'); @@ -2151,6 +2151,21 @@ describe('setup script validation', () => { expect(setupContent).toContain('~/.kiro/skills/gstack'); }); + test('setup supports --host opencode with install section and OpenCode skill path vars', () => { + expect(setupContent).toContain('INSTALL_OPENCODE='); + expect(setupContent).toContain('OPENCODE_SKILLS="$HOME/.config/opencode/skills"'); + expect(setupContent).toContain('OPENCODE_GSTACK="$OPENCODE_SKILLS/gstack"'); + }); + + test('setup installs OpenCode skills into a nested gstack runtime root', () => { + expect(setupContent).toContain('create_opencode_runtime_root'); + expect(setupContent).toContain('.opencode/skills'); + expect(setupContent).toContain('review/specialists'); + expect(setupContent).toContain('qa/templates'); + expect(setupContent).toContain('qa/references'); + expect(setupContent).toContain('dx-hall-of-fame.md'); + }); + test('create_agents_sidecar links runtime assets', () => { // Sidecar must link bin, browse, review, qa const fnStart = setupContent.indexOf('create_agents_sidecar()'); diff --git a/test/host-config.test.ts b/test/host-config.test.ts index 712376b2..57705703 100644 --- a/test/host-config.test.ts +++ b/test/host-config.test.ts @@ -354,6 +354,21 @@ describe('host-config-export.ts CLI', () => { expect(lines).toContain('review/checklist.md'); }); + test('opencode symlinks returns nested runtime assets', () => { + const { stdout, exitCode } = run('symlinks', 'opencode'); + expect(exitCode).toBe(0); + const lines = stdout.split('\n'); + expect(lines).toContain('bin'); + expect(lines).toContain('browse/dist'); + expect(lines).toContain('browse/bin'); + expect(lines).toContain('review/design-checklist.md'); + expect(lines).toContain('review/greptile-triage.md'); + expect(lines).toContain('review/specialists'); + expect(lines).toContain('qa/templates'); + expect(lines).toContain('qa/references'); + expect(lines).toContain('plan-devex-review/dx-hall-of-fame.md'); + }); + test('symlinks with missing host exits 1', () => { const { exitCode } = run('symlinks'); expect(exitCode).toBe(1);