-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathmetabot
More file actions
executable file
·289 lines (270 loc) · 9.96 KB
/
Copy pathmetabot
File metadata and controls
executable file
·289 lines (270 loc) · 9.96 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/usr/bin/env bash
# metabot - MetaBot management CLI
# Usage: metabot update | start | stop | restart | logs | status
set -euo pipefail
# Resolve METABOT_HOME: env var > script's parent dir (follows symlinks) > $HOME/metabot
if [[ -z "${METABOT_HOME:-}" ]]; then
_src="${BASH_SOURCE[0]}"
if command -v readlink &>/dev/null; then
_src="$(readlink -f "$_src" 2>/dev/null || echo "$_src")"
fi
_sd="$(cd "$(dirname "$_src")/.." 2>/dev/null && pwd)" || _sd=""
if [[ -n "$_sd" && -d "$_sd/.git" && -f "$_sd/package.json" ]]; then
METABOT_HOME="$_sd"
else
METABOT_HOME="$HOME/metabot"
fi
fi
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
NC='\033[0m'
info() { echo -e "${BLUE}[INFO]${NC} $*"; }
success() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*"; }
cmd_update() {
if [[ ! -d "$METABOT_HOME/.git" ]]; then
error "MetaBot not found at $METABOT_HOME"
echo " Run the installer first: curl -fsSL https://raw.githubusercontent.com/xvirobotics/metabot/main/install.sh | bash"
exit 1
fi
# Always re-exec from the repo copy before doing anything.
# This prevents the running script (e.g. ~/.local/bin/metabot) from being
# overwritten mid-execution when we copy CLI tools later.
if [[ -z "${METABOT_REEXEC:-}" ]] && [[ -f "$METABOT_HOME/bin/metabot" ]]; then
export METABOT_REEXEC=1
exec "$METABOT_HOME/bin/metabot" update
fi
info "Pulling latest code..."
cd "$METABOT_HOME"
local old_head
old_head="$(git rev-parse HEAD)"
git pull --ff-only || { error "git pull failed"; exit 1; }
# Re-exec if git pull updated this script (the repo copy we're running from)
if ! git diff --quiet "$old_head" HEAD -- bin/metabot 2>/dev/null; then
info "metabot CLI updated, re-launching with new version..."
exec "$METABOT_HOME/bin/metabot" update
fi
info "Installing dependencies..."
npm install --production=false
info "Building..."
npm run build
# Update CLI tools in ~/.local/bin
LOCAL_BIN="$HOME/.local/bin"
if [[ -d "$LOCAL_BIN" ]]; then
info "Updating CLI tools..."
for cli in mb mm metabot; do
if [[ -f "$METABOT_HOME/bin/$cli" ]]; then
cp "$METABOT_HOME/bin/$cli" "$LOCAL_BIN/$cli"
chmod +x "$LOCAL_BIN/$cli"
fi
done
success "CLI tools updated"
fi
# Update skills in ~/.claude/skills and ~/.codex/skills
SKILLS_DIR="$HOME/.claude/skills"
CODEX_SKILLS_DIR="$HOME/.codex/skills"
AGENTS_SKILLS_DIR="$HOME/.agents/skills"
mkdir -p "$SKILLS_DIR" "$CODEX_SKILLS_DIR"
info "Updating skills..."
local src=""
local -a lark_skill_names=(
lark-base
lark-calendar
lark-contact
lark-doc
lark-drive
lark-event
lark-im
lark-mail
lark-minutes
lark-openapi-explorer
lark-shared
lark-sheets
lark-skill-maker
lark-task
lark-vc
lark-whiteboard
lark-wiki
lark-workflow-meeting-summary
lark-workflow-standup-report
)
# metaskill / metaschedule are opt-in (not in the default list); CC native
# CronCreate / /loop already cover ad-hoc scheduling. Sources still ship in
# src/skills/* — users who want them can copy manually.
for skill in metamemory metabot voice skill-hub; do
case "$skill" in
metamemory) src="$METABOT_HOME/src/memory/skill" ;;
metabot) src="$METABOT_HOME/src/skills/metabot" ;;
voice) src="$METABOT_HOME/src/skills/voice" ;;
skill-hub) src="$METABOT_HOME/src/skills/skill-hub" ;;
*) src="" ;;
esac
if [[ -n "$src" && -d "$src" ]]; then
for dst_root in "$SKILLS_DIR" "$CODEX_SKILLS_DIR"; do
mkdir -p "$dst_root/$skill"
cp -r "$src/." "$dst_root/$skill/"
done
fi
done
# Clean up legacy feishu-doc skill
if [[ -d "$SKILLS_DIR/feishu-doc" ]]; then
rm -rf "$SKILLS_DIR/feishu-doc"
info "Removed legacy feishu-doc skill"
fi
if [[ -d "$CODEX_SKILLS_DIR/feishu-doc" ]]; then
rm -rf "$CODEX_SKILLS_DIR/feishu-doc"
fi
# Clean up legacy metaskill — now opt-in. Override with KEEP_METASKILL=1.
if [[ -d "$SKILLS_DIR/metaskill" ]] && [[ "${KEEP_METASKILL:-}" != "1" ]]; then
rm -rf "$SKILLS_DIR/metaskill"
info "Removed legacy metaskill (opt-in — set KEEP_METASKILL=1 to keep)"
fi
if [[ -d "$CODEX_SKILLS_DIR/metaskill" ]] && [[ "${KEEP_METASKILL:-}" != "1" ]]; then
rm -rf "$CODEX_SKILLS_DIR/metaskill"
fi
# Update lark-cli and its AI Agent skills only if previously installed.
# New installs still opt in via install.sh; updates keep existing setups fresh.
local has_lark_skills=false
local skill_root
for skill_root in "$AGENTS_SKILLS_DIR" "$SKILLS_DIR" "$CODEX_SKILLS_DIR"; do
if [[ -d "$skill_root/lark-doc" ]]; then
has_lark_skills=true
break
fi
done
if command -v lark-cli &>/dev/null; then
info "Updating lark-cli..."
if npm install -g @larksuite/cli@latest 2>/dev/null || npm install -g --prefix "$HOME/.local" @larksuite/cli@latest 2>/dev/null; then
success "lark-cli updated ($(lark-cli --version 2>/dev/null || echo 'version unknown'))"
else
warn "lark-cli update failed; MetaBot update will continue"
fi
has_lark_skills=true
fi
if [[ "$has_lark_skills" == "true" ]]; then
info "Updating lark-cli AI Agent skills..."
if npx skills add larksuite/cli --all -y -g 2>/dev/null; then
success "lark-cli AI Agent skills updated"
else
warn "lark-cli skills update failed; keeping existing installed copies"
fi
# Mirror lark-cli skills into Claude/Codex skill roots. Recent lark-cli
# installs use ~/.agents/skills, while older installs may use ~/.claude.
local lark_skill
for lark_skill in "${lark_skill_names[@]}"; do
local lark_src=""
for skill_root in "$AGENTS_SKILLS_DIR" "$SKILLS_DIR" "$CODEX_SKILLS_DIR"; do
if [[ -d "$skill_root/$lark_skill" ]]; then
lark_src="$skill_root/$lark_skill"
break
fi
done
if [[ -n "$lark_src" ]]; then
for dst_root in "$SKILLS_DIR" "$CODEX_SKILLS_DIR"; do
mkdir -p "$dst_root/$lark_skill"
if [[ "$lark_src" != "$dst_root/$lark_skill" ]]; then
cp -r "$lark_src/." "$dst_root/$lark_skill/"
fi
done
fi
done
fi
success "Skills updated"
# Update workspace skills if bots.json exists
if [[ -f "$METABOT_HOME/bots.json" ]] && command -v node &>/dev/null; then
local work_dir
work_dir=$(node -e "
const c=JSON.parse(require('fs').readFileSync('$METABOT_HOME/bots.json','utf-8'));
const b=[...(c.feishuBots||[]),...(c.telegramBots||[]),...(c.wechatBots||[])];
if(b[0])console.log(b[0].defaultWorkingDirectory);
" 2>/dev/null || true)
if [[ -n "$work_dir" ]]; then
local ws_skills_dir="$work_dir/.claude/skills"
local ws_codex_skills_dir="$work_dir/.codex/skills"
mkdir -p "$ws_skills_dir" "$ws_codex_skills_dir"
# Copy common skills
for skill in metamemory metabot voice skill-hub; do
if [[ -d "$SKILLS_DIR/$skill" ]]; then
for dst_root in "$ws_skills_dir" "$ws_codex_skills_dir"; do
mkdir -p "$dst_root/$skill"
cp -r "$SKILLS_DIR/$skill/." "$dst_root/$skill/"
done
fi
done
# Mirror opt-in skills (metaskill / metaschedule) only when present.
for skill in metaskill metaschedule; do
if [[ -d "$SKILLS_DIR/$skill" ]]; then
for dst_root in "$ws_skills_dir" "$ws_codex_skills_dir"; do
mkdir -p "$dst_root/$skill"
cp -r "$SKILLS_DIR/$skill/." "$dst_root/$skill/"
done
fi
done
# Copy lark-cli skills if previously installed
if [[ "$has_lark_skills" == "true" ]]; then
local lark_skill
for lark_skill in "${lark_skill_names[@]}"; do
local lark_src=""
for skill_root in "$AGENTS_SKILLS_DIR" "$SKILLS_DIR" "$CODEX_SKILLS_DIR"; do
if [[ -d "$skill_root/$lark_skill" ]]; then
lark_src="$skill_root/$lark_skill"
break
fi
done
if [[ -n "$lark_src" ]]; then
for dst_root in "$ws_skills_dir" "$ws_codex_skills_dir"; do
mkdir -p "$dst_root/$lark_skill"
cp -r "$lark_src/." "$dst_root/$lark_skill/"
done
fi
done
fi
# Clean up legacy feishu-doc in workspace
if [[ -d "$ws_skills_dir/feishu-doc" ]]; then
rm -rf "$ws_skills_dir/feishu-doc"
fi
if [[ -d "$ws_codex_skills_dir/feishu-doc" ]]; then
rm -rf "$ws_codex_skills_dir/feishu-doc"
fi
# Update CLAUDE.md
if [[ -f "$METABOT_HOME/src/workspace/CLAUDE.md" ]]; then
cp "$METABOT_HOME/src/workspace/CLAUDE.md" "$work_dir/CLAUDE.md"
if [[ ! -e "$work_dir/AGENTS.md" ]]; then
cp "$METABOT_HOME/src/workspace/CLAUDE.md" "$work_dir/AGENTS.md"
fi
fi
success "Workspace skills updated"
fi
fi
info "Restarting MetaBot..."
pm2 restart metabot 2>/dev/null || pm2 start ecosystem.config.cjs
pm2 save --force 2>/dev/null || true
success "MetaBot updated and restarted!"
}
cmd_start() { pm2 start "$METABOT_HOME/ecosystem.config.cjs"; pm2 save --force 2>/dev/null || true; }
cmd_stop() { pm2 stop metabot; }
cmd_restart() { pm2 restart metabot; }
cmd_logs() { pm2 logs metabot "${@}"; }
cmd_status() { pm2 describe metabot; }
case "${1:-help}" in
update|up) cmd_update ;;
start) cmd_start ;;
stop) cmd_stop ;;
restart|rs) cmd_restart ;;
logs|log) shift; cmd_logs "$@" ;;
status|st) cmd_status ;;
*)
echo -e "${BOLD}metabot${NC} - MetaBot management CLI"
echo ""
echo " metabot update Pull latest, rebuild, and restart"
echo " metabot start Start MetaBot with PM2"
echo " metabot stop Stop MetaBot"
echo " metabot restart Restart MetaBot"
echo " metabot logs View live logs (pass -n 100 etc.)"
echo " metabot status Show PM2 process status"
;;
esac