-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·248 lines (216 loc) · 7.45 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·248 lines (216 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env bash
# Install Agent Brain OpenClaw plugin (hosted SSE + lifecycle hooks).
#
# Usage:
# ./plugins/openclaw/install.sh \
# --url https://agent-memory.nighthawklabs.org/mcp \
# --agent-id openclaw-you \
# --api-key YOUR_KEY \
# [--config-file ~/.openclaw/openclaw.gemini.json]
#
# Remote (no clone needed):
# curl -fsSL https://raw.githubusercontent.com/realnighthawk/agent-plugins/main/plugins/openclaw/install.sh | bash -s -- --api-key ...
set -euo pipefail
PLUGIN_GITHUB_REPO="${AGENT_PLUGINS_GITHUB_REPO:-realnighthawk/agent-plugins}"
AGENT_PLUGINS_REF="${AGENT_PLUGINS_REF:-main}"
# Detect if running from a local checkout (dev workflow — enables go build fallback for mcp-call).
_script_path="${BASH_SOURCE[0]:-}"
LOCAL_CHECKOUT=""
if [[ -n "${_script_path}" ]]; then
_lib="$(cd "$(dirname "${_script_path}")/../.." 2>/dev/null && pwd)/scripts/lib/install-repo.sh"
if [[ -f "${_lib}" ]]; then
# shellcheck source=../../scripts/lib/install-repo.sh
. "${_lib}"
LOCAL_CHECKOUT="$(plugins_repo_root "${_script_path}")"
fi
fi
MCP_URL="https://agent-memory.nighthawklabs.org/mcp"
AGENT_ID=""
API_KEY="${NIGHTHAWK_API_KEY:-}"
JWT="${NIGHTHAWK_JWT:-}"
USER_TAG="${USER:-you}"
AGENT_PREFIX="openclaw"
MCP_CALL_VERSION="${MCP_CALL_VERSION:-latest}"
SKIP_PLUGIN_INSTALL=0
RESTART_GATEWAY=0
EXTRA_CONFIG_FILE=""
usage() {
sed -n '2,11p' "${BASH_SOURCE[0]:-$0}" | sed 's/^# \{0,1\}//'
exit "${1:-0}"
}
while [[ $# -gt 0 ]]; do
case "$1" in
--url) MCP_URL="$2"; shift 2 ;;
--agent-id) AGENT_ID="$2"; shift 2 ;;
--api-key) API_KEY="$2"; shift 2 ;;
--jwt) JWT="$2"; shift 2 ;;
--user) USER_TAG="$2"; shift 2 ;;
--agent-prefix) AGENT_PREFIX="$2"; shift 2 ;;
--version) MCP_CALL_VERSION="$2"; shift 2 ;;
--config-file) EXTRA_CONFIG_FILE="$2"; shift 2 ;;
--skip-plugin-install) SKIP_PLUGIN_INSTALL=1; shift ;;
--restart) RESTART_GATEWAY=1; shift ;;
-h|--help) usage 0 ;;
*) echo "unknown arg: $1" >&2; usage 1 ;;
esac
done
if [[ -z "$AGENT_ID" ]]; then
AGENT_ID="${AGENT_PREFIX}-${USER_TAG}"
fi
if [[ -z "$API_KEY" && -z "$JWT" ]]; then
echo "Provide --api-key or --jwt (or set NIGHTHAWK_API_KEY / NIGHTHAWK_JWT)." >&2
exit 1
fi
ENV_DIR="${HOME}/.config/agent-brain"
ENV_FILE="${ENV_DIR}/openclaw.env"
OPENCLAW_CONFIG="${HOME}/.openclaw/openclaw.json"
mkdir -p "$ENV_DIR" "$(dirname "$OPENCLAW_CONFIG")"
# Resolve plugin directory: local checkout (dev) or git clone (remote).
# OpenClaw's --link needs a stable on-disk path that persists after install.
# Using git clone means re-running install.sh updates the plugin in place.
resolve_plugin_dir() {
if [[ -n "${LOCAL_CHECKOUT}" ]]; then
echo "${LOCAL_CHECKOUT}/plugins/openclaw"
return
fi
local repo_dest="${HOME}/.local/share/agent-brain/agent-plugins"
local repo_url="https://github.com/${PLUGIN_GITHUB_REPO}.git"
if [[ -d "${repo_dest}/.git" ]]; then
echo "Updating agent-plugins repo at ${repo_dest}..." >&2
git -C "$repo_dest" fetch --depth=1 origin "${AGENT_PLUGINS_REF}" >&2
git -C "$repo_dest" checkout FETCH_HEAD >&2
else
echo "Cloning agent-plugins repo to ${repo_dest}..." >&2
mkdir -p "$(dirname "$repo_dest")"
git clone --depth=1 --branch "${AGENT_PLUGINS_REF}" "$repo_url" "$repo_dest" >&2
fi
plugins_sync_memory_skills "$repo_dest"
echo "${repo_dest}/plugins/openclaw"
}
# Install mcp-call binary to DEST.
# Local dev checkouts delegate to the full fetch script (supports go build fallback).
# Remote installs download directly from GitHub releases.
install_mcp_call() {
local dest="$1"
mkdir -p "$(dirname "$dest")"
if [[ -n "${LOCAL_CHECKOUT}" && -f "${LOCAL_CHECKOUT}/scripts/fetch-mcp-call.sh" ]]; then
export MCP_CALL_VERSION
"${LOCAL_CHECKOUT}/scripts/fetch-mcp-call.sh" "$dest"
return
fi
local os_name arch asset repo ver url tmp
case "$(uname -s)" in
Darwin) os_name=darwin ;;
Linux) os_name=linux ;;
*) echo "unsupported OS: $(uname -s)" >&2; return 1 ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch=amd64 ;;
arm64|aarch64) arch=arm64 ;;
*) echo "unsupported arch: $(uname -m)" >&2; return 1 ;;
esac
asset="mcp-call-${os_name}-${arch}"
repo="${NIGHTHAWK_MCP_CALL_REPO:-realnighthawk/agent-plugins}"
ver="${MCP_CALL_VERSION:-latest}"
if [[ -z "$ver" || "$ver" == "latest" ]]; then
url="https://github.com/${repo}/releases/latest/download/${asset}"
else
url="https://github.com/${repo}/releases/download/v${ver#v}/${asset}"
fi
tmp="${dest}.$$.tmp"
echo "Downloading mcp-call (${asset})..."
curl -fsSL "$url" -o "$tmp"
chmod +x "$tmp"
mv -f "$tmp" "$dest"
echo "Installed ${dest} from release"
}
PLUGIN_DIR="$(resolve_plugin_dir)"
if [[ -n "${LOCAL_CHECKOUT}" ]]; then
plugins_sync_memory_skills "${LOCAL_CHECKOUT}"
fi
echo "Installing mcp-call..."
install_mcp_call "${PLUGIN_DIR}/bin/mcp-call"
cat >"$ENV_FILE" <<EOF
# Agent Brain OpenClaw — generated by install.sh
export NIGHTHAWK_MCP_URL=${MCP_URL}
export NIGHTHAWK_AGENT_ID=${AGENT_ID}
export NIGHTHAWK_AGENT_PREFIX=${AGENT_PREFIX}
EOF
chmod 600 "$ENV_FILE"
if [[ -n "$JWT" ]]; then
echo "export NIGHTHAWK_JWT=${JWT}" >>"$ENV_FILE"
else
echo "export NIGHTHAWK_API_KEY=${API_KEY}" >>"$ENV_FILE"
fi
# Write plugin config into openclaw.json BEFORE --link so OpenClaw's schema
# validation passes (configSchema requires url). Do NOT pre-write
# plugins.slots.memory — openclaw sets it automatically during install and
# will reject it if the plugin isn't registered yet.
merge_openclaw_config() {
local target_file="$1"
local auth_key auth_val
if [[ -n "$JWT" ]]; then
auth_key="jwt"
auth_val="$JWT"
else
auth_key="apiKey"
auth_val="$API_KEY"
fi
local base='{}'
if [[ -f "$target_file" ]]; then
base="$(cat "$target_file")"
fi
echo "$base" | jq \
--arg url "$MCP_URL" \
--arg agent_id "$AGENT_ID" \
--arg auth_key "$auth_key" \
--arg auth_val "$auth_val" \
'
.plugins = (.plugins // {}) |
.plugins.entries = (.plugins.entries // {}) |
.plugins.entries["agent-brain"] = {
enabled: true,
config: ({
url: $url,
agentId: $agent_id,
autoRecall: true,
autoCapture: true,
recallLimit: 8
} + (if $auth_key == "jwt" then {jwt: $auth_val} else {apiKey: $auth_val} end))
}
' >"${target_file}.tmp" && mv "${target_file}.tmp" "$target_file"
echo "Updated ${target_file}"
}
merge_openclaw_config "$OPENCLAW_CONFIG"
if [[ -n "$EXTRA_CONFIG_FILE" ]]; then
if [[ ! -f "$EXTRA_CONFIG_FILE" ]]; then
echo "Error: --config-file path does not exist: ${EXTRA_CONFIG_FILE}" >&2
exit 1
fi
merge_openclaw_config "$EXTRA_CONFIG_FILE"
fi
if [[ "$SKIP_PLUGIN_INSTALL" -eq 0 ]]; then
echo "Linking plugin with OpenClaw..."
openclaw plugins install --link "${PLUGIN_DIR}"
fi
if [[ "$RESTART_GATEWAY" -eq 1 ]]; then
echo "Restarting OpenClaw gateway..."
openclaw gateway restart
fi
echo ""
echo "Installed Agent Brain for OpenClaw"
echo " Plugin path: ${PLUGIN_DIR}"
echo " MCP URL: ${MCP_URL}"
echo " Agent ID: ${AGENT_ID}"
echo " Env file: ${ENV_FILE}"
echo " Config: ${OPENCLAW_CONFIG}"
if [[ -n "$EXTRA_CONFIG_FILE" ]]; then
echo " Extra config: ${EXTRA_CONFIG_FILE}"
fi
echo ""
echo "Optional: source ${ENV_FILE} in your shell for env-based overrides."
echo ""
echo "Server checklist:"
echo " 1. Memory Explorer → Settings: register agent \"${AGENT_ID}\""
echo " 2. openclaw gateway restart"
echo " 3. openclaw plugins inspect agent-brain --runtime --json"