-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathae
More file actions
executable file
·909 lines (826 loc) · 31.6 KB
/
ae
File metadata and controls
executable file
·909 lines (826 loc) · 31.6 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
#!/bin/bash
# ae — agenticEvolve CLI (v2)
# Single entrypoint for humans and agents.
set -euo pipefail
EXODIR="$HOME/.agenticEvolve"
# Load v1 config if it exists (backward compat)
[ -f "$EXODIR/config.sh" ] && source "$EXODIR/config.sh" || true
# Helper: read from tty if available, otherwise return empty
_prompt() {
local prompt="$1"
REPLY=""
{ read -p "$prompt" REPLY </dev/tty; } 2>/dev/null || REPLY=""
echo "$REPLY"
}
CMD="${1:-}"
shift 2>/dev/null || true
# ── Default: Interactive Chat REPL ──────────────────────────
# No subcommand → launch the TUI (or --classic for old Rich REPL)
if [ -z "$CMD" ] || [ "$CMD" = "--resume" ] || [ "$CMD" = "-r" ] || [ "$CMD" = "--classic" ]; then
RESUME=""
USE_CLASSIC=false
if [ "$CMD" = "--classic" ]; then
USE_CLASSIC=true
CMD="${1:-}"
shift 2>/dev/null || true
fi
if [ "$CMD" = "--resume" ] || [ "$CMD" = "-r" ]; then
RESUME="${1:-}"
shift 2>/dev/null || true
fi
# Ensure deps are available
if ! python3 -c "import textual" 2>/dev/null; then
echo "Installing dependencies (textual)..."
python3 -m pip install -q textual
fi
cd "$EXODIR"
if $USE_CLASSIC; then
# Fallback to old Rich REPL
if [ -n "$RESUME" ]; then
python3 -c "
import sys; sys.path.insert(0, '$EXODIR')
from gateway.cli import main
main(resume_session='$RESUME')
"
else
python3 -c "
import sys; sys.path.insert(0, '$EXODIR')
from gateway.cli import main
main()
"
fi
else
# New Textual TUI
if [ -n "$RESUME" ]; then
python3 -c "
import sys; sys.path.insert(0, '$EXODIR')
from gateway.tui import main
main(resume_session='$RESUME')
"
else
python3 -c "
import sys; sys.path.insert(0, '$EXODIR')
from gateway.tui import main
main()
"
fi
fi
exit 0
fi
case "$CMD" in
# ── v2: Gateway ─────────────────────────────────────────────
gateway)
SUB="${1:-start}"
shift 2>/dev/null || true
case "$SUB" in
start)
# Kill existing if running
EXISTING=$(pgrep -f 'python3 -m gateway.run' || true)
if [ -n "$EXISTING" ]; then
echo "Stopping existing gateway (PID $EXISTING)..."
kill "$EXISTING" 2>/dev/null
sleep 2
kill -9 "$EXISTING" 2>/dev/null
sleep 1
fi
if [ "${1:-}" = "--background" ] || [ "${1:-}" = "-d" ]; then
mkdir -p "$EXODIR/logs"
cd "$EXODIR" && nohup python3 -m gateway.run >> "$EXODIR/logs/gateway-stdout.log" 2>> "$EXODIR/logs/gateway-stderr.log" &
GW_PID=$!
echo "$GW_PID" > "$EXODIR/gateway.pid"
sleep 3
if kill -0 "$GW_PID" 2>/dev/null; then
echo "Gateway started in background (PID $GW_PID)"
echo "Logs: ~/.agenticEvolve/logs/"
else
echo "Gateway failed to start. Check logs: ~/.agenticEvolve/logs/gateway-stderr.log"
fi
else
echo "Starting agenticEvolve gateway... (Ctrl+C to stop)"
echo "Tip: use 'ae gateway start -d' to run in background"
cd "$EXODIR" && python3 -m gateway.run
fi
;;
stop)
PID=""
if [ -f "$EXODIR/gateway.pid" ]; then
PID=$(cat "$EXODIR/gateway.pid")
if ! kill -0 "$PID" 2>/dev/null; then
PID=""
rm -f "$EXODIR/gateway.pid"
fi
fi
# Fallback to pgrep if no valid PID file
if [ -z "$PID" ]; then
PID=$(pgrep -f 'python3 -m gateway.run' || true)
fi
if [ -n "$PID" ]; then
kill "$PID" 2>/dev/null
sleep 2
kill -9 "$PID" 2>/dev/null
rm -f "$EXODIR/gateway.pid"
echo "Gateway stopped (PID $PID)"
else
echo "Gateway not running"
fi
;;
status)
if [ -f "$EXODIR/gateway.pid" ]; then
PID=$(cat "$EXODIR/gateway.pid")
if kill -0 "$PID" 2>/dev/null; then
echo "Gateway running (PID $PID)"
else
echo "Gateway not running (stale PID)"
rm -f "$EXODIR/gateway.pid"
fi
else
echo "Gateway not running"
fi
;;
install)
echo "Installing gateway as launchd service..."
PLIST="$HOME/Library/LaunchAgents/com.agenticevolve.gateway.plist"
cat > "$PLIST" <<PLIST_EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.agenticevolve.gateway</string>
<key>ProgramArguments</key>
<array>
<string>$(which python3)</string>
<string>-m</string>
<string>gateway.run</string>
</array>
<key>WorkingDirectory</key>
<string>$EXODIR</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>$EXODIR/logs/gateway-stdout.log</string>
<key>StandardErrorPath</key>
<string>$EXODIR/logs/gateway-stderr.log</string>
</dict>
</plist>
PLIST_EOF
launchctl load "$PLIST"
echo "Installed: $PLIST"
echo "Use 'launchctl unload $PLIST' to remove"
;;
*)
echo "Usage: ae gateway [start|stop|status|install]"
;;
esac
;;
# ── v2: Memory ──────────────────────────────────────────────
memory)
SUB="${1:-show}"
shift 2>/dev/null || true
case "$SUB" in
show)
echo "=== MEMORY.md ($(wc -c < "$EXODIR/memory/MEMORY.md" | tr -d ' ')/2200 chars) ==="
cat "$EXODIR/memory/MEMORY.md"
echo ""
echo "=== USER.md ($(wc -c < "$EXODIR/memory/USER.md" | tr -d ' ')/1375 chars) ==="
cat "$EXODIR/memory/USER.md"
;;
reset)
confirm=$(_prompt "Reset all memory? This cannot be undone. [y/N] ")
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
echo "" > "$EXODIR/memory/MEMORY.md"
echo "" > "$EXODIR/memory/USER.md"
echo "Memory cleared."
else
echo "Cancelled."
fi
;;
*)
echo "Usage: ae memory [show|reset]"
;;
esac
;;
# ── v2: Sessions ────────────────────────────────────────────
sessions)
SUB="${1:-list}"
shift 2>/dev/null || true
case "$SUB" in
list)
python3 -c "
import sys; sys.path.insert(0, '$EXODIR')
from gateway.session_db import list_sessions
rows = list_sessions(limit=20)
if not rows:
print('No sessions.')
else:
for r in rows:
msgs = r.get('message_count', 0)
src = r.get('source', '?')
ts = r.get('started_at', '?')[:19]
sid = r.get('id', '?')
print(f' {ts} {src:10s} {msgs:3d} msgs {sid}')
"
;;
search)
QUERY="${1:?Usage: ae sessions search <query>}"
python3 -c "
import sys, json; sys.path.insert(0, '$EXODIR')
from gateway.session_db import search_sessions
results = search_sessions('$QUERY', limit=5)
if not results:
print('No results.')
else:
for r in results:
print(f'--- {r[\"session_id\"]} ({r[\"source\"]}) ---')
for m in r.get('matches', [])[:3]:
role = m['role']
text = m['content'][:200]
print(f' [{role}] {text}')
print()
"
;;
stats)
python3 -c "
import sys; sys.path.insert(0, '$EXODIR')
from gateway.session_db import stats
s = stats()
print(f'Sessions: {s[\"total_sessions\"]}')
print(f'Messages: {s[\"total_messages\"]}')
for src, cnt in s.get('sources', {}).items():
print(f' {src}: {cnt}')
print(f'DB size: {s[\"db_size_mb\"]} MB')
"
;;
*)
echo "Usage: ae sessions [list|search <query>|stats]"
;;
esac
;;
# ── v2: Config ──────────────────────────────────────────────
config)
SUB="${1:-show}"
shift 2>/dev/null || true
case "$SUB" in
show)
if [ -f "$EXODIR/config.yaml" ]; then
cat "$EXODIR/config.yaml"
else
echo "No config.yaml found. Run 'ae setup' first."
fi
;;
edit)
"${EDITOR:-vim}" "$EXODIR/config.yaml"
;;
*)
echo "Usage: ae config [show|edit]"
;;
esac
;;
# ── v2: Setup ───────────────────────────────────────────────
setup)
echo ""
echo " ╔══════════════════════════════════════╗"
echo " ║ agenticEvolve — setup wizard ║"
echo " ╚══════════════════════════════════════╝"
echo ""
ERRORS=0
# ── 1. Prerequisites ───────────────────────────────────
echo "Checking prerequisites..."
echo ""
# Python 3.11+
if command -v python3 &>/dev/null; then
PY_VER=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
PY_MAJOR=$(echo "$PY_VER" | cut -d. -f1)
PY_MINOR=$(echo "$PY_VER" | cut -d. -f2)
if [ "$PY_MAJOR" -ge 3 ] && [ "$PY_MINOR" -ge 11 ]; then
echo " [OK] Python $PY_VER"
else
echo " [!!] Python $PY_VER (need 3.11+)"
ERRORS=$((ERRORS+1))
fi
else
echo " [!!] Python 3 not found. Install: https://python.org"
ERRORS=$((ERRORS+1))
fi
# Claude Code
if command -v claude &>/dev/null; then
echo " [OK] Claude Code $(claude --version 2>/dev/null || echo 'installed')"
else
echo " [!!] Claude Code not found"
echo " Install: npm install -g @anthropic-ai/claude-code"
echo " Then run: claude (to authenticate)"
ERRORS=$((ERRORS+1))
fi
# Node.js (needed for Claude Code, ABP browser)
if command -v node &>/dev/null; then
echo " [OK] Node.js $(node --version)"
else
echo " [--] Node.js not found (needed for Claude Code + ABP browser)"
fi
if [ "$ERRORS" -gt 0 ]; then
echo ""
echo " Fix the issues above before continuing."
echo " Re-run: ae setup"
exit 1
fi
# ── 2. Directories ─────────────────────────────────────
echo ""
echo "Creating directories..."
mkdir -p "$EXODIR/memory" "$EXODIR/logs" "$EXODIR/cron" "$EXODIR/signals" \
"$EXODIR/skills-queue" "$EXODIR/cache" "$EXODIR/models"
echo " [OK] ~/.agenticEvolve/"
# ── 3. Config files ────────────────────────────────────
echo ""
echo "Setting up config files..."
# config.yaml
if [ -f "$EXODIR/config.yaml" ]; then
echo " [OK] config.yaml (exists)"
elif [ -f "$EXODIR/config.yaml.example" ]; then
cp "$EXODIR/config.yaml.example" "$EXODIR/config.yaml"
echo " [OK] config.yaml (created from example)"
else
echo " [!!] config.yaml.example not found"
fi
# .env
if [ -f "$EXODIR/.env" ]; then
echo " [OK] .env (exists)"
elif [ -f "$EXODIR/.env.example" ]; then
cp "$EXODIR/.env.example" "$EXODIR/.env"
echo " [OK] .env (created from example)"
else
echo " [!!] .env.example not found"
fi
# ── 4. Python deps ─────────────────────────────────────
echo ""
echo "Installing Python dependencies..."
if [ -f "$EXODIR/requirements.txt" ]; then
pip install -r "$EXODIR/requirements.txt" -q 2>/dev/null && echo " [OK] pip install" || echo " [!!] pip install failed"
fi
# ── 5. Telegram setup (interactive) ────────────────────
echo ""
echo "─── Telegram Setup ───"
echo ""
# Check if token already set
EXISTING_TOKEN=""
if [ -f "$EXODIR/.env" ]; then
EXISTING_TOKEN=$(grep -E "^TELEGRAM_BOT_TOKEN=.+" "$EXODIR/.env" 2>/dev/null | cut -d= -f2- || true)
fi
if [ -n "$EXISTING_TOKEN" ] && [ "$EXISTING_TOKEN" != "" ]; then
echo " Telegram bot token: already set"
else
echo " 1. Open Telegram and message @BotFather"
echo " 2. Send /newbot and follow the prompts"
echo " 3. Copy the bot token"
echo ""
BOT_TOKEN=$(_prompt " Paste your Telegram bot token (or press Enter to skip): ")
if [ -n "$BOT_TOKEN" ]; then
# Update .env
if grep -q "^TELEGRAM_BOT_TOKEN=" "$EXODIR/.env" 2>/dev/null; then
sed -i '' "s|^TELEGRAM_BOT_TOKEN=.*|TELEGRAM_BOT_TOKEN=$BOT_TOKEN|" "$EXODIR/.env"
else
echo "TELEGRAM_BOT_TOKEN=$BOT_TOKEN" >> "$EXODIR/.env"
fi
echo " [OK] Token saved to .env"
else
echo " [--] Skipped (set TELEGRAM_BOT_TOKEN in .env later)"
fi
fi
echo ""
# Check if telegram allowed_users has a numeric ID set
EXISTING_USERS=$(python3 -c "
import yaml
try:
cfg = yaml.safe_load(open('$EXODIR/config.yaml'))
users = cfg.get('platforms',{}).get('telegram',{}).get('allowed_users',[])
if users: print(users[0])
except: pass
" 2>/dev/null || true)
if [ -n "$EXISTING_USERS" ]; then
echo " Allowed user ID: $EXISTING_USERS"
else
echo " To find your Telegram user ID:"
echo " → Message @userinfobot on Telegram"
echo " → It replies with your numeric ID"
echo ""
USER_ID=$(_prompt " Enter your Telegram user ID (or press Enter to skip): ")
if [ -n "$USER_ID" ]; then
# Update config.yaml (telegram section only, preserves comments)
if [ -f "$EXODIR/config.yaml" ]; then
python3 -c "
import re
with open('$EXODIR/config.yaml') as f: text = f.read()
# Find telegram section and replace its allowed_users
text = re.sub(
r'(telegram:.*?allowed_users:\s*)\[.*?\]',
r'\g<1>[$USER_ID]',
text, count=1, flags=re.DOTALL)
with open('$EXODIR/config.yaml','w') as f: f.write(text)
" 2>/dev/null
echo " [OK] User ID saved to config.yaml"
fi
# Also set TELEGRAM_CHAT_ID in .env
if grep -q "^TELEGRAM_CHAT_ID=" "$EXODIR/.env" 2>/dev/null; then
sed -i '' "s|^TELEGRAM_CHAT_ID=.*|TELEGRAM_CHAT_ID=$USER_ID|" "$EXODIR/.env"
else
echo "TELEGRAM_CHAT_ID=$USER_ID" >> "$EXODIR/.env"
fi
echo " [OK] Chat ID saved to .env (for cron delivery)"
else
echo " [--] Skipped (set allowed_users in config.yaml later)"
fi
fi
# ── 6. Optional: Voice ─────────────────────────────────
echo ""
echo "─── Voice Support (optional) ───"
echo ""
if command -v whisper-cli &>/dev/null; then
echo " [OK] whisper-cli installed"
else
echo " [--] whisper-cli not found"
echo " Install: brew install whisper-cpp ffmpeg"
echo " Then download the model:"
echo " curl -L -o ~/.agenticEvolve/models/ggml-small.bin \\"
echo " https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin"
fi
# ── 7. Optional: Daemon ────────────────────────────────
echo ""
INSTALL_DAEMON=$(_prompt "Install as background service (launchd)? [y/N] ")
if [ "$INSTALL_DAEMON" = "y" ] || [ "$INSTALL_DAEMON" = "Y" ]; then
mkdir -p "$EXODIR/logs"
PLIST="$HOME/Library/LaunchAgents/com.agenticevolve.gateway.plist"
cat > "$PLIST" <<PLIST_EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.agenticevolve.gateway</string>
<key>ProgramArguments</key>
<array>
<string>$(which python3)</string>
<string>-m</string>
<string>gateway.run</string>
</array>
<key>WorkingDirectory</key>
<string>$EXODIR</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>$EXODIR/logs/gateway-stdout.log</string>
<key>StandardErrorPath</key>
<string>$EXODIR/logs/gateway-stderr.log</string>
</dict>
</plist>
PLIST_EOF
launchctl load "$PLIST"
echo " [OK] Installed as launchd service (auto-starts on login)"
echo " Logs: ~/.agenticEvolve/logs/"
else
echo " [--] Skipped (run manually with: ae gateway start)"
fi
# ── Summary ────────────────────────────────────────────
echo ""
echo " ╔══════════════════════════════════════╗"
echo " ║ Setup complete! ║"
echo " ╚══════════════════════════════════════╝"
echo ""
echo " Start the gateway:"
echo " ae gateway start"
echo ""
echo " Or run diagnostics:"
echo " ae doctor"
echo ""
echo " Then message your bot on Telegram!"
echo ""
;;
# ── v2: Doctor ──────────────────────────────────────────────
doctor)
FIX=false
if [ "${1:-}" = "--fix" ]; then
FIX=true
shift 2>/dev/null || true
fi
echo "=== agenticEvolve doctor ==="
$FIX && echo "(auto-fix mode)" || true
echo ""
ISSUES=0
# Claude Code
if command -v claude &>/dev/null; then
echo "[OK] Claude Code installed"
else
echo "[!!] Claude Code not found"
ISSUES=$((ISSUES+1))
fi
# Python
if command -v python3 &>/dev/null; then
echo "[OK] Python $(python3 --version 2>&1 | awk '{print $2}')"
else
echo "[!!] Python 3 not found"
ISSUES=$((ISSUES+1))
fi
# Node (for WhatsApp)
if command -v node &>/dev/null; then
echo "[OK] Node.js $(node --version)"
else
echo "[--] Node.js not found (needed for WhatsApp only)"
fi
# Config files
if [ -f "$EXODIR/config.yaml" ]; then
echo "[OK] config.yaml"
else
echo "[!!] config.yaml missing"
ISSUES=$((ISSUES+1))
if $FIX; then
if [ -f "$EXODIR/config.yaml.example" ]; then
cp "$EXODIR/config.yaml.example" "$EXODIR/config.yaml"
echo " -> copied from config.yaml.example"
else
echo " -> config.yaml.example not found, cannot fix"
fi
fi
fi
if [ -f "$EXODIR/.env" ]; then
echo "[OK] .env"
else
echo "[--] .env missing (no platform tokens)"
ISSUES=$((ISSUES+1))
if $FIX; then
if [ -f "$EXODIR/.env.example" ]; then
cp "$EXODIR/.env.example" "$EXODIR/.env"
echo " -> copied from .env.example"
else
echo " -> .env.example not found, cannot fix"
fi
fi
fi
[ -f "$EXODIR/SOUL.md" ] && echo "[OK] SOUL.md" || echo "[--] SOUL.md missing"
# Memory directory
if [ -d "$EXODIR/memory" ]; then
echo "[OK] memory/"
else
echo "[!!] memory/ directory missing"
ISSUES=$((ISSUES+1))
if $FIX; then
mkdir -p "$EXODIR/memory"
echo " -> created memory/"
fi
fi
# MEMORY.md
if [ -f "$EXODIR/memory/MEMORY.md" ]; then
echo "[OK] MEMORY.md ($(wc -c < "$EXODIR/memory/MEMORY.md" | tr -d ' ')/2200)"
else
echo "[!!] MEMORY.md missing"
ISSUES=$((ISSUES+1))
if $FIX; then
mkdir -p "$EXODIR/memory"
touch "$EXODIR/memory/MEMORY.md"
echo " -> created MEMORY.md"
fi
fi
# USER.md
if [ -f "$EXODIR/memory/USER.md" ]; then
echo "[OK] USER.md ($(wc -c < "$EXODIR/memory/USER.md" | tr -d ' ')/1375)"
else
echo "[!!] USER.md missing"
ISSUES=$((ISSUES+1))
if $FIX; then
mkdir -p "$EXODIR/memory"
touch "$EXODIR/memory/USER.md"
echo " -> created USER.md"
fi
fi
# Logs directory
if [ -d "$EXODIR/logs" ]; then
echo "[OK] logs/"
else
echo "[!!] logs/ directory missing"
ISSUES=$((ISSUES+1))
if $FIX; then
mkdir -p "$EXODIR/logs"
echo " -> created logs/"
fi
fi
# Python deps
if [ -f "$EXODIR/requirements.txt" ]; then
if python3 -c "
import pkg_resources, sys
with open('$EXODIR/requirements.txt') as f:
reqs = [l.strip() for l in f if l.strip() and not l.startswith('#')]
try:
pkg_resources.require(reqs)
except Exception:
sys.exit(1)
" 2>/dev/null; then
echo "[OK] Python deps installed"
else
echo "[!!] Python deps missing or outdated"
ISSUES=$((ISSUES+1))
if $FIX; then
echo " -> running pip install -r requirements.txt ..."
pip install -r "$EXODIR/requirements.txt" -q 2>/dev/null \
&& echo " -> deps installed" \
|| echo " -> pip install failed"
fi
fi
else
echo "[--] requirements.txt not found"
fi
# Gateway
if [ -f "$EXODIR/gateway.pid" ]; then
PID=$(cat "$EXODIR/gateway.pid")
if kill -0 "$PID" 2>/dev/null; then
echo "[OK] Gateway running (PID $PID)"
else
echo "[!!] Stale gateway.pid (PID $PID not running)"
ISSUES=$((ISSUES+1))
if $FIX; then
rm -f "$EXODIR/gateway.pid"
echo " -> removed stale gateway.pid"
fi
fi
else
echo "[--] Gateway not running"
fi
# Skills
SKILL_COUNT=$(ls -d "$HOME/.claude/skills"/*/SKILL.md 2>/dev/null | wc -l | tr -d ' ')
echo "[OK] $SKILL_COUNT Claude Code skills installed"
# Summary
echo ""
if [ "$ISSUES" -eq 0 ]; then
echo "No issues found."
elif $FIX; then
echo "Fixed $ISSUES issue(s). Re-run 'ae doctor' to verify."
else
echo "Found $ISSUES issue(s). Run 'ae doctor --fix' to auto-fix."
fi
;;
# ── v2: Update ──────────────────────────────────────────────
update)
echo "=== agenticEvolve update ==="
echo ""
# Pull latest code
echo "Pulling latest changes..."
if git -C "$EXODIR" pull --ff-only 2>&1; then
echo "[OK] Code updated"
else
echo "[!!] git pull failed — resolve conflicts manually"
exit 1
fi
# Update deps
echo "Updating dependencies..."
pip install -r "$EXODIR/requirements.txt" -q 2>/dev/null && echo "[OK] Dependencies updated" || true
# Restart gateway if running
GW_PID=$(pgrep -f 'python3 -m gateway.run' || true)
if [ -n "$GW_PID" ]; then
echo "Restarting gateway..."
kill "$GW_PID" 2>/dev/null
sleep 2
kill -9 "$GW_PID" 2>/dev/null
sleep 1
cd "$EXODIR" && nohup python3 -m gateway.run > /dev/null 2>&1 &
sleep 3
NEW_PID=$(pgrep -f 'python3 -m gateway.run' || true)
if [ -n "$NEW_PID" ]; then
echo "[OK] Gateway restarted (PID $NEW_PID)"
else
echo "[!!] Gateway failed to restart"
fi
else
echo "[--] Gateway not running (start with: ae gateway start)"
fi
echo ""
echo "Update complete."
;;
# ── v1 Legacy Commands ──────────────────────────────────────
init)
if [ -f "$EXODIR/prompts/initialize.md" ]; then
echo "Running agenticEvolve initializer..."
claude -p "$(cat "$EXODIR/prompts/initialize.md")" \
--model sonnet \
--dangerously-skip-permissions
else
echo "v1 init prompt not found. Use 'ae setup' for v2."
fi
;;
cycle)
if [ -f "$EXODIR/run-cycle.sh" ]; then
bash "$EXODIR/run-cycle.sh"
else
echo "v1 run-cycle.sh not found."
fi
;;
collect)
SOURCE="${1:-all}"
if [ "$SOURCE" = "all" ]; then
bash "$EXODIR/collectors/github.sh" || true
bash "$EXODIR/collectors/hackernews.sh" || true
bash "$EXODIR/collectors/x-search.sh" || true
elif [ -f "$EXODIR/collectors/$SOURCE.sh" ]; then
bash "$EXODIR/collectors/$SOURCE.sh"
else
echo "Unknown collector: $SOURCE"
echo "Available: github, hackernews, x-search"
exit 1
fi
;;
status)
echo "=== agenticEvolve status ==="
echo ""
# Gateway status
if [ -f "$EXODIR/gateway.pid" ]; then
PID=$(cat "$EXODIR/gateway.pid")
kill -0 "$PID" 2>/dev/null && echo "Gateway: running (PID $PID)" || echo "Gateway: not running"
else
echo "Gateway: not running"
fi
echo ""
# Memory
if [ -f "$EXODIR/memory/MEMORY.md" ]; then
MEM_CHARS=$(wc -c < "$EXODIR/memory/MEMORY.md" | tr -d ' ')
echo "Memory: ${MEM_CHARS}/2200 chars"
fi
echo ""
# Sessions
python3 -c "
import sys; sys.path.insert(0, '$EXODIR')
try:
from gateway.session_db import stats
s = stats()
print(f'Sessions: {s[\"total_sessions\"]} total, {s[\"total_messages\"]} messages')
except Exception:
print('Sessions: DB not initialized')
" 2>/dev/null || echo "Sessions: unavailable"
# Cost
if [ -f "$EXODIR/logs/cost.log" ]; then
TODAY_DATE=$(date +%Y-%m-%d)
TODAY_COST=$(grep "$TODAY_DATE" "$EXODIR/logs/cost.log" 2>/dev/null | awk -F'\t' '{gsub(/\$/, "", $4); sum+=$4} END{printf "%.2f", sum+0}') || TODAY_COST="0.00"
echo "Cost today: \$$TODAY_COST"
fi
;;
cost)
if [ -f "$EXODIR/logs/cost.log" ]; then
TODAY_DATE=$(date +%Y-%m-%d)
TODAY_COST=$(grep "$TODAY_DATE" "$EXODIR/logs/cost.log" 2>/dev/null | awk -F'\t' '{gsub(/\$/, "", $4); sum+=$4} END{printf "%.2f", sum+0}') || TODAY_COST="0.00"
TOTAL_LINES=$(wc -l < "$EXODIR/logs/cost.log" | tr -d ' ')
echo "Today: \$$TODAY_COST"
echo "Total entries: $TOTAL_LINES"
echo ""
echo "Last 10 entries:"
tail -10 "$EXODIR/logs/cost.log"
else
echo "No cost data yet."
fi
;;
notify)
MSG="${1:?Usage: ae notify <message>}"
if [ -f "$EXODIR/notify.sh" ]; then
bash "$EXODIR/notify.sh" "$MSG"
else
echo "v1 notify.sh not found. Use 'ae gateway' for v2 messaging."
fi
;;
# ── Help ────────────────────────────────────────────────────
help)
cat <<'EOF'
ae — agenticEvolve CLI (v2)
CHAT
ae Interactive REPL (default)
ae --resume ID Resume a previous session
GATEWAY
ae gateway [start] Start the messaging gateway (foreground)
ae gateway start -d Start in background (detached)
ae gateway stop Stop the gateway
ae gateway status Check if gateway is running
ae gateway install Install as launchd service (auto-restart)
MEMORY
ae memory Show bounded memory state
ae memory reset Clear all memory
SESSIONS
ae sessions list Browse past sessions
ae sessions search Q FTS5 search across conversations
ae sessions stats Session statistics
CONFIG
ae config Show config.yaml
ae config edit Open config.yaml in editor
ae setup First-time setup wizard
ae update Update to latest version + restart gateway
ae doctor Diagnose issues
ae doctor --fix Diagnose and auto-fix common issues
STATUS & COST
ae status System status overview
ae cost Cost breakdown
LEGACY (v1)
ae cycle Run one v1 signal cycle
ae collect [source] Run collectors
ae notify <msg> Send Telegram notification (v1)
EOF
;;
*)
echo "Unknown command: $CMD"
echo "Run 'ae help' for usage."
;;
esac