Implement opencode adapter.

Co-Authored-By: win0na <winnie@winneon.moe>

feat(lib.sh): add install_plugins helper for opencode JS plugins

build(adapters): opencode adapter skeleton with capability/event tables

build(opencode): adapter_translate_dispatcher (DISPATCHER.md → AGENTS.md)

build(opencode): adapter_translate_references and adapter_translate_skills

Implements Task 4 and Task 5:
- adapter_translate_references: Copies reference markdown files to .opencode/references/
- adapter_translate_skills: Copies skill SKILL.md files to .opencode/skills/<name>/ with exclude filtering

Both functions respect framework filtering via should_include().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): adapter_translate_agents with capability→permission mapping

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): bash-executor template for spawning hook scripts

build(opencode): plugin-stub template for mbifc-hooks.js

build(opencode): adapter_translate_hooks with JS plugin generation

Implements _oc_hook_registry_json and adapter_translate_hooks in the
opencode adapter. Copies hook scripts to .opencode/hooks/, generates a
single .opencode/plugins/mbifc-hooks.js by inlining bash-executor.js and
synthesising a hook registry from *.hook.yaml files. Uses python3 for
template substitution to safely handle multi-line JS content. Adds 3
unit tests (copies scripts, registry entries, noop when no hooks dir).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): adapter_translate_mcp with local/remote handling

build(opencode): adapter_finalize and complete adapter_build wiring

Add adapter_finalize placeholder and wire adapter_translate_mcp into
adapter_build; add end-to-end integration test (14/14 pass).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(launchme): branch on --framework for opencode install layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(updateme): branch on --framework for opencode install layout

Mirror the same case "$FRAMEWORK" block from launchme.sh: framework-specific
DIST_COMPONENTS_DIR, VAULT_COMPONENTS_DIR, DISPATCHER_SRC/DST, MCP_SRC/DST,
HAS_PLUGINS; conditional install_plugins; conditional install_settings;
framework-aware vault-setup check; framework-neutral summary messages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nunziati
2026-04-08 21:51:37 +00:00
parent 24b84ca414
commit 3f5d89bee3
7 changed files with 972 additions and 28 deletions

View File

@@ -90,14 +90,39 @@ bash "$SCRIPT_DIR/build.sh" --framework "$FRAMEWORK"
DIST_DIR="$REPO_DIR/dist/$FRAMEWORK"
[[ -d "$DIST_DIR" ]] || die "Build did not produce $DIST_DIR"
# ── Framework-specific install layout ────────────────────────────────────────
case "$FRAMEWORK" in
claude-code)
DIST_COMPONENTS_DIR="$DIST_DIR/.claude"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.claude"
DISPATCHER_SRC="$DIST_DIR/CLAUDE.md"
DISPATCHER_DST="$VAULT_DIR/CLAUDE.md"
MCP_SRC="$DIST_DIR/.mcp.json"
MCP_DST="$VAULT_DIR/.mcp.json"
HAS_PLUGINS=0
;;
opencode)
DIST_COMPONENTS_DIR="$DIST_DIR/.opencode"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.opencode"
DISPATCHER_SRC="$DIST_DIR/AGENTS.md"
DISPATCHER_DST="$VAULT_DIR/AGENTS.md"
MCP_SRC="$DIST_DIR/opencode.json"
MCP_DST="$VAULT_DIR/opencode.json"
HAS_PLUGINS=1
;;
*)
die "Unknown framework: $FRAMEWORK (install layout not defined)"
;;
esac
# ── Migrate legacy manifests (if any) ────────────────────────────────────────
manifest_migrate
# ── Deprecate agents/refs removed from repo (reinstall only) ─────────────────
DEP_COUNT=0
if [[ $EXISTING -eq 1 ]]; then
DEP_COUNT=$(deprecate_removed "agents" "$DIST_DIR/.claude/agents" "$VAULT_DIR/.claude/agents")
DEP_COUNT=$((DEP_COUNT + $(deprecate_removed "references" "$DIST_DIR/.claude/references" "$VAULT_DIR/.claude/references")))
DEP_COUNT=$(deprecate_removed "agents" "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
DEP_COUNT=$((DEP_COUNT + $(deprecate_removed "references" "$DIST_COMPONENTS_DIR/references" "$VAULT_COMPONENTS_DIR/references")))
fi
# ── Ensure vault support dirs ─────────────────────────────────────────────────
@@ -105,19 +130,19 @@ mkdir -p "$VAULT_DIR/Meta/states"
# ── Install components ────────────────────────────────────────────────────────
info "Installing agents..."
AGENT_COUNT=$(install_agents "$DIST_DIR/.claude/agents" "$VAULT_DIR/.claude/agents")
AGENT_COUNT=$(install_agents "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
success "Agents: $AGENT_COUNT installed/updated"
info "Installing references..."
REF_COUNT=$(install_refs "$DIST_DIR/.claude/references" "$VAULT_DIR/.claude/references")
REF_COUNT=$(install_refs "$DIST_COMPONENTS_DIR/references" "$VAULT_COMPONENTS_DIR/references")
success "References: $REF_COUNT installed/updated"
info "Installing skills..."
SKILL_COUNT=$(install_skills "$DIST_DIR/.claude/skills" "$VAULT_DIR/.claude/skills")
SKILL_COUNT=$(install_skills "$DIST_COMPONENTS_DIR/skills" "$VAULT_COMPONENTS_DIR/skills")
success "Skills: $SKILL_COUNT installed/updated"
info "Installing hooks..."
HOOK_COUNT=$(install_hooks "$DIST_DIR/.claude/hooks" "$VAULT_DIR/.claude/hooks")
HOOK_COUNT=$(install_hooks "$DIST_COMPONENTS_DIR/hooks" "$VAULT_COMPONENTS_DIR/hooks")
success "Hooks: $HOOK_COUNT installed/updated"
# ── Deprecate stale orchestra scripts on reinstall ──────────────────────────
@@ -158,10 +183,23 @@ fi
install_settings "$DIST_DIR/.claude/settings.json" "$VAULT_DIR/.claude"
install_dispatcher "$DIST_DIR/CLAUDE.md" "$VAULT_DIR/CLAUDE.md"
PLUGIN_COUNT=0
if [[ $HAS_PLUGINS -eq 1 && -d "$DIST_COMPONENTS_DIR/plugins" ]]; then
info "Installing plugins..."
PLUGIN_COUNT=$(install_plugins "$DIST_COMPONENTS_DIR/plugins" "$VAULT_COMPONENTS_DIR/plugins")
success "Plugins: $PLUGIN_COUNT installed/updated"
fi
# ── MCP servers ───────────────────────────────────────────────────────────────
if [[ -f "$DIST_DIR/.mcp.json" ]]; then
copy_if_changed "$DIST_DIR/.mcp.json" "$VAULT_DIR/.mcp.json"
# settings.json only exists for claude-code (hook config lives in the JS plugin on opencode)
if [[ -f "$DIST_COMPONENTS_DIR/settings.json" ]]; then
install_settings "$DIST_COMPONENTS_DIR/settings.json" "$VAULT_COMPONENTS_DIR"
fi
install_dispatcher "$DISPATCHER_SRC" "$DISPATCHER_DST"
# ── MCP / opencode.json ───────────────────────────────────────────────────────
if [[ -f "$MCP_SRC" ]]; then
copy_if_changed "$MCP_SRC" "$MCP_DST"
fi
# ── Done ──────────────────────────────────────────────────────────────────────

View File

@@ -376,6 +376,30 @@ install_hooks() {
printf '%d' "$count"
}
# install_plugins <src_dir> <dst_dir>
# Copies *.js plugin files from src to dst. Mirrors install_hooks but for
# opencode plugins (the opencode framework expects JavaScript files under
# .opencode/plugins/). Tracked in the manifest under key "plugins".
install_plugins() {
local src_dir="$1" dst_dir="$2"
local count=0 manifest=()
[[ -d "$src_dir" ]] || { printf '0'; return 0; }
mkdir -p "$dst_dir"
for src in "$src_dir/"*.js; do
[[ -f "$src" ]] || continue
local name; name="$(basename "$src")"
local dst="$dst_dir/$name"
manifest+=("$name")
copy_if_changed "$src" "$dst"
if [[ $_LAST_CHANGED -eq 1 ]]; then
[[ $VERBOSE_COPY -eq 1 ]] && info "Updated plugin: $name" || true
count=$((count + 1))
fi
done
manifest_write "plugins" "${manifest[@]}"
printf '%d' "$count"
}
# install_settings <src_json> <dst_dir>
# Always syncs settings.json from src to dst when they differ.
# Creates a .bak of the previous version so users can recover custom entries.

View File

@@ -37,8 +37,13 @@ done
print_banner "Update "
# ── Check vault has been set up ───────────────────────────────────────────────
[[ -d "$VAULT_DIR/.claude/agents" ]] \
|| die "No .claude/agents/ found in $VAULT_DIR — run launchme.sh first"
case "$FRAMEWORK" in
claude-code) _SETUP_CHECK="$VAULT_DIR/.claude/agents" ;;
opencode) _SETUP_CHECK="$VAULT_DIR/.opencode/agents" ;;
*) _SETUP_CHECK="$VAULT_DIR/.claude/agents" ;;
esac
[[ -d "$_SETUP_CHECK" ]] \
|| die "No agents/ found in $VAULT_DIR for framework '$FRAMEWORK' — run launchme.sh first"
# ── Confirm ───────────────────────────────────────────────────────────────────
echo -e "${BOLD}This will update core agents, skills, references, hooks, and CLAUDE.md.${NC}"
@@ -60,12 +65,37 @@ bash "$SCRIPT_DIR/build.sh" --framework "$FRAMEWORK"
DIST_DIR="$REPO_DIR/dist/$FRAMEWORK"
[[ -d "$DIST_DIR" ]] || die "Build did not produce $DIST_DIR"
# ── Framework-specific install layout ────────────────────────────────────────
case "$FRAMEWORK" in
claude-code)
DIST_COMPONENTS_DIR="$DIST_DIR/.claude"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.claude"
DISPATCHER_SRC="$DIST_DIR/CLAUDE.md"
DISPATCHER_DST="$VAULT_DIR/CLAUDE.md"
MCP_SRC="$DIST_DIR/.mcp.json"
MCP_DST="$VAULT_DIR/.mcp.json"
HAS_PLUGINS=0
;;
opencode)
DIST_COMPONENTS_DIR="$DIST_DIR/.opencode"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.opencode"
DISPATCHER_SRC="$DIST_DIR/AGENTS.md"
DISPATCHER_DST="$VAULT_DIR/AGENTS.md"
MCP_SRC="$DIST_DIR/opencode.json"
MCP_DST="$VAULT_DIR/opencode.json"
HAS_PLUGINS=1
;;
*)
die "Unknown framework: $FRAMEWORK (install layout not defined)"
;;
esac
# ── Migrate legacy manifests (if any) ────────────────────────────────────────
manifest_migrate
# ── Deprecate agents/refs removed from repo ──────────────────────────────────
DEP_COUNT=$(deprecate_removed "agents" "$DIST_DIR/.claude/agents" "$VAULT_DIR/.claude/agents")
DEP_COUNT=$((DEP_COUNT + $(deprecate_removed "references" "$DIST_DIR/.claude/references" "$VAULT_DIR/.claude/references")))
DEP_COUNT=$(deprecate_removed "agents" "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
DEP_COUNT=$((DEP_COUNT + $(deprecate_removed "references" "$DIST_COMPONENTS_DIR/references" "$VAULT_COMPONENTS_DIR/references")))
# ── Ensure vault support dirs ─────────────────────────────────────────────────
mkdir -p "$VAULT_DIR/Meta/states"
@@ -73,33 +103,43 @@ mkdir -p "$VAULT_DIR/Meta/states"
# ── Update components (per-file logging enabled) ─────────────────────────────
VERBOSE_COPY=1
AGENT_COUNT=$(install_agents "$DIST_DIR/.claude/agents" "$VAULT_DIR/.claude/agents")
REF_COUNT=$(install_refs "$DIST_DIR/.claude/references" "$VAULT_DIR/.claude/references")
SKILL_COUNT=$(install_skills "$DIST_DIR/.claude/skills" "$VAULT_DIR/.claude/skills")
HOOK_COUNT=$(install_hooks "$DIST_DIR/.claude/hooks" "$VAULT_DIR/.claude/hooks")
AGENT_COUNT=$(install_agents "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
REF_COUNT=$(install_refs "$DIST_COMPONENTS_DIR/references" "$VAULT_COMPONENTS_DIR/references")
SKILL_COUNT=$(install_skills "$DIST_COMPONENTS_DIR/skills" "$VAULT_COMPONENTS_DIR/skills")
HOOK_COUNT=$(install_hooks "$DIST_COMPONENTS_DIR/hooks" "$VAULT_COMPONENTS_DIR/hooks")
install_settings "$DIST_DIR/.claude/settings.json" "$VAULT_DIR/.claude"
SETTINGS_CHANGED=$_LAST_CHANGED
PLUGIN_COUNT=0
if [[ $HAS_PLUGINS -eq 1 && -d "$DIST_COMPONENTS_DIR/plugins" ]]; then
info "Installing plugins..."
PLUGIN_COUNT=$(install_plugins "$DIST_COMPONENTS_DIR/plugins" "$VAULT_COMPONENTS_DIR/plugins")
success "Plugins: $PLUGIN_COUNT installed/updated"
fi
install_dispatcher "$DIST_DIR/CLAUDE.md" "$VAULT_DIR/CLAUDE.md"
SETTINGS_CHANGED=0
if [[ -f "$DIST_COMPONENTS_DIR/settings.json" ]]; then
install_settings "$DIST_COMPONENTS_DIR/settings.json" "$VAULT_COMPONENTS_DIR"
SETTINGS_CHANGED=$_LAST_CHANGED
fi
install_dispatcher "$DISPATCHER_SRC" "$DISPATCHER_DST"
CLAUDE_MD_CHANGED=$_LAST_CHANGED
# ── MCP servers ───────────────────────────────────────────────────────────────
if [[ -f "$DIST_DIR/.mcp.json" ]]; then
copy_if_changed "$DIST_DIR/.mcp.json" "$VAULT_DIR/.mcp.json"
# ── MCP / opencode.json ───────────────────────────────────────────────────────
if [[ -f "$MCP_SRC" ]]; then
copy_if_changed "$MCP_SRC" "$MCP_DST"
fi
# ── Summary ───────────────────────────────────────────────────────────────────
echo ""
TOTAL=$((AGENT_COUNT + REF_COUNT + SKILL_COUNT + HOOK_COUNT + SETTINGS_CHANGED + CLAUDE_MD_CHANGED))
TOTAL=$((AGENT_COUNT + REF_COUNT + SKILL_COUNT + HOOK_COUNT + PLUGIN_COUNT + SETTINGS_CHANGED + CLAUDE_MD_CHANGED))
if [[ $TOTAL -eq 0 && $DEP_COUNT -eq 0 ]]; then
success "Everything is already up to date!"
else
success "Updated $AGENT_COUNT agent(s), $SKILL_COUNT skill(s), $REF_COUNT reference(s), $HOOK_COUNT hook(s)"
success "Updated $AGENT_COUNT agent(s), $SKILL_COUNT skill(s), $REF_COUNT reference(s), $HOOK_COUNT hook(s)${PLUGIN_COUNT:+, $PLUGIN_COUNT plugin(s)}"
[[ $SETTINGS_CHANGED -eq 1 ]] && info "settings.json updated (backup saved as settings.json.bak)"
[[ $CLAUDE_MD_CHANGED -eq 1 ]] && info "CLAUDE.md updated"
[[ $DEP_COUNT -gt 0 ]] && warn "$DEP_COUNT file(s) deprecated (moved to .claude/deprecated/)"
[[ $CLAUDE_MD_CHANGED -eq 1 ]] && info "Dispatcher file updated"
[[ $DEP_COUNT -gt 0 ]] && warn "$DEP_COUNT file(s) deprecated (moved to deprecated/)"
fi
echo ""
echo -e " ${DIM}Restart Claude Code to pick up the changes.${NC}"
echo -e " ${DIM}Restart $FRAMEWORK to pick up the changes.${NC}"
echo ""