#!/bin/bash
# wkappbot-code -- Wisdom Kernel installer from a kih checkout (idempotent). Installs the PINNED OpenCode release
# and wires the one kih plugin into the user's OpenCode config (a non-JSON config is left untouched and a
# sidecar wkappbot-code.json is written to merge by hand).
# Spec: wkappbot skill read agent-harness-landscape-2026-howto
# Usage: bash wkappbot-code/install.sh [--no-npm] [--config-dir DIR]
command -v wk_stopwatch_lap >/dev/null 2>&1 && wk_stopwatch_lap "wkappbot-code install"
# ONE INSTALL PATH (2026-11-05): this wraps bin/wkappbot-code.js install, the same code that
# `npm install -g wkappbot-code` puts on PATH, so a checkout and the npm package never install differently.
# The pin lives in package.json wkAppbotCode.opencodeVersion; an existing opencode.json is backed up and
# only the plugin entry is merged in (every other user key is kept).
HERE="$(cd "$(dirname "$0")" && pwd)"
KIH="$(cd "$HERE/.." && pwd)"
NODE="$(command -v node || true)"
[ -z "$NODE" ] && { echo "[wkappbot-code] node not found; install Node.js 18+ first" >&2; exit 1; }
exec "$NODE" "$HERE/bin/wkappbot-code.js" install --kih-dir "$KIH" "$@"
