Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·1543 lines (1392 loc) · 63.2 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·1543 lines (1392 loc) · 63.2 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
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Loci — Memory Palace for AI
# Interactive setup script. Pure bash, zero dependencies.
# Inspired by oh-my-zsh, rustup, and create-next-app.
# Note: NOT using set -e — interactive reads return non-zero which would kill the script
# ─── Colors & Formatting ────────────────────────────────────────────────────
CYAN='\033[0;36m'
BOLD_CYAN='\033[1;36m'
WHITE='\033[1;37m'
DIM='\033[2m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m'
# ─── Globals ─────────────────────────────────────────────────────────────────
BRAIN_PATH="$(cd "$(dirname "$0")" && pwd)"
BRAIN_CONFIG_PATH="$BRAIN_PATH"
LANG_CHOICE="en"
USER_NAME=""
USER_NICKNAME=""
USER_ROLE=""
USER_FOCUS=""
USER_SCHEDULE=""
USER_ABOUT=""
CONNECT_CLAUDE=1
CONNECT_CODEX=1
CONNECT_WORKBUDDY=0
CONNECT_LABEL=""
TOTAL_STEPS=4
CURRENT_STEP=0
NON_INTERACTIVE=0
FORCE_SETUP=0
SCHEDULE_CHOICE=""
CONNECT_CHOICE="auto"
# ─── Ctrl+C handler ─────────────────────────────────────────────────────────
cleanup() {
echo ""
echo ""
echo -e "${DIM}Setup interrupted. No changes were made.${NC}"
echo -e "${DIM}Run ./setup.sh again when you're ready.${NC}"
echo ""
tput cnorm 2>/dev/null # restore cursor
exit 1
}
trap cleanup INT TERM
# ─── Utilities ───────────────────────────────────────────────────────────────
print_step() {
echo ""
echo -e "${DIM}[$CURRENT_STEP/$TOTAL_STEPS]${NC} ${BOLD_CYAN}$1${NC}"
echo -e "${DIM}$(printf '%.0s─' {1..50})${NC}"
}
print_check() {
echo -e " ${GREEN}✓${NC} $1"
}
print_warn() {
echo -e " ${YELLOW}!${NC} $1"
}
print_fail() {
echo -e " ${RED}✗${NC} $1"
}
# Convert a shell path before passing it to native Windows Node. Git Bash may
# expose drives as /d/... and virtual mounts as /tmp/..., neither of which Node
# can resolve reliably without asking MSYS. POSIX Node receives paths unchanged.
node_fs_path() {
local value="$1"
local node_platform
node_platform=$(node -p 'process.platform' 2>/dev/null | tr -d '\r' || printf '')
if [ "$node_platform" = "win32" ] && command -v cygpath >/dev/null 2>&1; then
cygpath -m "$value"
elif [ "$node_platform" = "win32" ] && command -v wslpath >/dev/null 2>&1 && [[ "$value" == /mnt/* ]]; then
wslpath -m "$value"
else
printf '%s\n' "$value"
fi
}
# Spinner animation for file generation
spin() {
local msg="$1"
local pid=$!
local frames='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
local i=0
tput civis 2>/dev/null # hide cursor
while kill -0 "$pid" 2>/dev/null; do
printf "\r ${CYAN}${frames:$i:1}${NC} %s" "$msg"
i=$(( (i + 1) % ${#frames} ))
sleep 0.08
done
wait "$pid"
printf "\r ${GREEN}✓${NC} %s\n" "$msg"
tput cnorm 2>/dev/null # restore cursor
}
# Prompt with default value
ask() {
local prompt="$1"
local default="$2"
local var_name="$3"
if [ -n "$default" ]; then
printf " ${WHITE}%s${NC} ${DIM}(%s)${NC}: " "$prompt" "$default"
else
printf " ${WHITE}%s${NC}: " "$prompt"
fi
read -r input
if [ -z "$input" ] && [ -n "$default" ]; then
input="$default"
fi
eval "$var_name=\"\$input\""
}
# Flush stdin buffer (prevents arrow key leaking into next read)
# Uses perl for sub-second timeout (bash 3.2 on macOS doesn't support fractional -t)
flush_input() {
if command -v perl &>/dev/null; then
perl -e 'use IO::Select; my $s=IO::Select->new(\*STDIN); while($s->can_read(0.05)){sysread(STDIN,$_,1)}' 2>/dev/null
fi
}
# Text input with left-arrow-to-go-back support
# Sets INPUT_RESULT to the text, or "__BACK__" if user pressed left arrow on empty input
read_text() {
INPUT_RESULT=""
printf " ${CYAN}▸ ${NC}"
tput cnorm 2>/dev/null
while true; do
read -rsn1 ch
if [[ "$ch" == $'\x1b' ]]; then
# Read arrow sequence — bash 3.2 supports integer timeout only
read -rsn2 -t 1 seq
if [[ "$seq" == '[D' ]] && [ -z "$INPUT_RESULT" ]; then
# Left arrow on empty input = go back
INPUT_RESULT="__BACK__"
return
fi
# All other escape sequences (up/down/right) silently ignored
elif [[ "$ch" == "" ]]; then
return
elif [[ "$ch" == $'\x7f' ]] || [[ "$ch" == $'\x08' ]]; then
if [ -n "$INPUT_RESULT" ]; then
INPUT_RESULT="${INPUT_RESULT%?}"
printf "\b \b"
fi
else
INPUT_RESULT="${INPUT_RESULT}${ch}"
printf "%s" "$ch"
fi
done
}
# Interactive arrow-key menu selection (Claude Code style)
# Up/Down = select option, Left = previous question, Right/Enter = confirm
# Returns MENU_RESULT=1..N for selection, MENU_RESULT=0 for "go back"
# Accepts ALLOW_BACK, QUESTION_NUM, QUESTION_TOTAL as env vars
choose() {
local prompt="$1"
local allow_back="${ALLOW_BACK:-0}"
local q_num="${QUESTION_NUM:-0}"
local q_total="${QUESTION_TOTAL:-0}"
shift
local options=("$@")
local selected=0
local count=${#options[@]}
printf "\n"
# Progress dots: ● for current/done, ○ for remaining
if [ "$q_total" -gt 0 ]; then
printf " "
for (( i=1; i<=q_total; i++ )); do
if [ "$i" -lt "$q_num" ]; then
printf "${GREEN}●${NC} "
elif [ "$i" -eq "$q_num" ]; then
printf "${CYAN}●${NC} "
else
printf "${DIM}○${NC} "
fi
done
printf "\n"
fi
printf " ${WHITE}${prompt}${NC}\n"
tput civis 2>/dev/null # hide cursor
# Draw initial menu
for i in "${!options[@]}"; do
if [ "$i" -eq "$selected" ]; then
printf " ${CYAN}● ${WHITE}${options[$i]}${NC}\n"
else
printf " ${DIM}○ ${options[$i]}${NC}\n"
fi
done
# Read arrow keys and enter
while true; do
read -rsn1 key
if [[ "$key" == $'\x1b' ]]; then
# Read arrow sequence (bash 3.2: only integer timeouts)
# 1s timeout distinguishes arrow keys (instant) from bare Esc
read -rsn2 -t 1 arrow
case "$arrow" in
'[A') # Up = previous option
if [ "$selected" -gt 0 ]; then
selected=$((selected - 1))
fi
;;
'[B') # Down = next option
if [ "$selected" -lt $((count - 1)) ]; then
selected=$((selected + 1))
fi
;;
'[D') # Left = go back to previous question
if [ "$allow_back" = "1" ]; then
tput cnorm 2>/dev/null
MENU_RESULT=0
flush_input
return
fi
;;
'[C') # Right = confirm selection (same as Enter)
break
;;
'') # Bare Esc (timeout) = go back
if [ "$allow_back" = "1" ]; then
tput cnorm 2>/dev/null
MENU_RESULT=0
flush_input
return
fi
;;
esac
elif [[ "$key" == "" ]]; then
break
elif [[ "$key" =~ ^[0-9]$ ]] && [ "$key" -ge 1 ] && [ "$key" -le "$count" ]; then
selected=$((key - 1))
break
fi
# Redraw menu (move cursor up N lines)
printf "\033[${count}A"
for i in "${!options[@]}"; do
printf "\r\033[K"
if [ "$i" -eq "$selected" ]; then
printf " ${CYAN}● ${WHITE}${options[$i]}${NC}\n"
else
printf " ${DIM}○ ${options[$i]}${NC}\n"
fi
done
done
tput cnorm 2>/dev/null
# Collapse menu to single selected line
printf "\033[${count}A"
for i in "${!options[@]}"; do
printf "\r\033[K"
done
printf "\033[${count}A"
printf " ${GREEN}● ${WHITE}${options[$selected]}${NC}\n"
for (( i=1; i<count; i++ )); do
printf "\033[K\n"
done
MENU_RESULT=$((selected + 1))
flush_input
}
# Bilingual text helper — returns text based on language choice
t() {
local en="$1"
local zh="$2"
case "$LANG_CHOICE" in
zh) echo "$zh" ;;
mix) echo "$zh ($en)" ;;
*) echo "$en" ;;
esac
}
# Get today's date (cross-platform)
today() {
date +%Y-%m-%d
}
# ─── CLI Arguments (non-interactive mode, for AI agents & scripts) ───────────
show_help() {
cat << 'HELPEOF'
Loci setup
Usage:
./setup.sh Interactive wizard (default)
./setup.sh --non-interactive --name "Alex" [...] Scriptable setup, no prompts
Non-interactive options:
--non-interactive, -y Run without any prompts. Requires --name.
--name <name> Your name (required in non-interactive mode)
--nickname <text> How the AI should address you (default: your name)
--role <text> What you do, free text (default: Developer)
--focus <text> Most important focus right now (default: Set up my second brain)
--schedule <word> morning|daytime|evening|night|irregular (default: daytime)
--about <text> Anything else worth knowing (optional)
--lang <code> en | zh | mix (default: en)
--connect <target> auto | all | both | claude | codex | workbuddy | none
auto detects installed tools (default: auto)
both = Claude Code + Codex; all adds WorkBuddy too
--force Re-run setup even if this brain is already set up
--help, -h Show this help
Example (what an AI agent typically runs):
./setup.sh --non-interactive --name "Alex" --role "Developer" \
--focus "Ship my product" --lang en --connect auto
HELPEOF
}
parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
--non-interactive|-y) NON_INTERACTIVE=1 ;;
--name) USER_NAME="$2"; shift ;;
--nickname) USER_NICKNAME="$2"; shift ;;
--role) USER_ROLE="$2"; shift ;;
--focus) USER_FOCUS="$2"; shift ;;
--schedule) SCHEDULE_CHOICE="$2"; shift ;;
--about) USER_ABOUT="$2"; shift ;;
--lang) LANG_CHOICE="$2"; shift ;;
--connect) CONNECT_CHOICE="$2"; shift ;;
--force) FORCE_SETUP=1 ;;
--help|-h) show_help; exit 0 ;;
*) echo "Unknown option: $1 (see ./setup.sh --help)"; exit 1 ;;
esac
shift
done
}
apply_non_interactive_config() {
if [ -z "$USER_NAME" ]; then
echo "Error: --non-interactive requires --name. See ./setup.sh --help"
exit 1
fi
USER_ROLE="${USER_ROLE:-Developer}"
USER_FOCUS="${USER_FOCUS:-Set up my second brain}"
case "$LANG_CHOICE" in
en|zh|mix) ;;
*) echo "Error: --lang must be en, zh, or mix"; exit 1 ;;
esac
case "${SCHEDULE_CHOICE:-daytime}" in
morning) USER_SCHEDULE=1 ;;
daytime) USER_SCHEDULE=2 ;;
evening) USER_SCHEDULE=3 ;;
night) USER_SCHEDULE=4 ;;
irregular) USER_SCHEDULE=5 ;;
*) echo "Error: --schedule must be morning, daytime, evening, night, or irregular"; exit 1 ;;
esac
local has_claude=0 has_codex=0 has_workbuddy=0
if command -v claude &>/dev/null || [ -d "$HOME/.claude" ]; then has_claude=1; fi
if command -v codex &>/dev/null || [ -d "$HOME/.codex" ]; then has_codex=1; fi
if [ -d "$HOME/.workbuddy" ]; then has_workbuddy=1; fi
case "$CONNECT_CHOICE" in
auto) CONNECT_CLAUDE=$has_claude; CONNECT_CODEX=$has_codex; CONNECT_WORKBUDDY=$has_workbuddy ;;
all) CONNECT_CLAUDE=1; CONNECT_CODEX=1; CONNECT_WORKBUDDY=1 ;;
both) CONNECT_CLAUDE=1; CONNECT_CODEX=1; CONNECT_WORKBUDDY=0 ;;
claude) CONNECT_CLAUDE=1; CONNECT_CODEX=0; CONNECT_WORKBUDDY=0 ;;
codex) CONNECT_CLAUDE=0; CONNECT_CODEX=1; CONNECT_WORKBUDDY=0 ;;
workbuddy) CONNECT_CLAUDE=0; CONNECT_CODEX=0; CONNECT_WORKBUDDY=1 ;;
none) CONNECT_CLAUDE=0; CONNECT_CODEX=0; CONNECT_WORKBUDDY=0 ;;
*) echo "Error: --connect must be auto, all, both, claude, codex, workbuddy, or none"; exit 1 ;;
esac
CONNECT_LABEL=""
[ "$CONNECT_CLAUDE" -eq 1 ] && CONNECT_LABEL="Claude Code"
[ "$CONNECT_CODEX" -eq 1 ] && CONNECT_LABEL="${CONNECT_LABEL:+$CONNECT_LABEL + }Codex"
[ "$CONNECT_WORKBUDDY" -eq 1 ] && CONNECT_LABEL="${CONNECT_LABEL:+$CONNECT_LABEL + }WorkBuddy"
[ -z "$CONNECT_LABEL" ] && CONNECT_LABEL="Brain only"
}
# ─── Colors for gradient ─────────────────────────────────────────────────────
PURPLE='\033[35m'
LIGHT_PURPLE='\033[95m'
BOLD_PURPLE='\033[1;35m'
TEAL='\033[36m'
LIGHT_TEAL='\033[96m'
# ─── ASCII Art Logo ──────────────────────────────────────────────────────────
show_logo() {
clear
printf "\n"
# Seahorse: proportionally scaled ~50% of v3 original (16 lines, all sections kept)
printf "${LIGHT_PURPLE} ,${NC}\n"
printf "${LIGHT_PURPLE} , /^\\ ___${NC}\n"
printf "${LIGHT_PURPLE} /^\\_/ '...' /\`${NC}\n"
printf "${PURPLE} ,_\\ ,' ~ (${NC}\n"
printf "${PURPLE} \\__ \\\\.' .-. )${NC}\n"
printf "${PURPLE} / (== ( ${LIGHT_TEAL}◉${PURPLE} ) \\\\${NC} ${BOLD_CYAN}██╗ ██████╗ ██████╗██╗${NC}\n"
printf "${TEAL} ,/ ~~~| \`-' )${NC} ${BOLD_CYAN}██║ ██╔═══██╗██╔════╝██║${NC}\n"
printf "${TEAL} \"\") |~| \"\"\". ~/${NC} ${BOLD_CYAN}██║ ██║ ██║██║ ██║${NC}\n"
printf "${TEAL} / \\~\\ \". \\\\${NC} ${BOLD_CYAN}██║ ██║ ██║██║ ██║${NC}\n"
printf "${LIGHT_TEAL} (_ =\\ ─┼─ |~| \".\`;${NC} ${BOLD_CYAN}███████╗╚██████╔╝╚██████╗██║${NC}\n"
printf "${LIGHT_TEAL} (_ ~ ══|~/${NC} ${BOLD_CYAN}╚══════╝ ╚═════╝ ╚═════╝╚═╝${NC}\n"
printf "${LIGHT_TEAL} (_ _/ | .\"${NC}\n"
printf "${LIGHT_TEAL} (\\_/ )/${NC}\n"
printf "${LIGHT_TEAL} | ( .-' \`-.${NC}\n"
printf "${LIGHT_TEAL} \\ :\`. \`-' |${NC}\n"
printf "${LIGHT_TEAL} \`-._.'^'./${NC}\n"
printf "\n"
printf " ${DIM}──────${NC} ${BOLD_CYAN}Memory Palace for AI${NC} ${DIM}──────${NC}\n"
printf "\n"
}
# ─── Step 0: Pre-flight Checks ──────────────────────────────────────────────
preflight() {
clear
CURRENT_STEP=0
print_step "Pre-flight checks"
# Detect OS
local os_name
case "$(uname -s)" in
Darwin*) os_name="macOS" ;;
Linux*)
if grep -qi microsoft /proc/version 2>/dev/null; then
os_name="Linux (WSL)"
else
os_name="Linux"
fi
;;
*) os_name="$(uname -s)" ;;
esac
print_check "OS: ${os_name}"
# Check git
if command -v git &>/dev/null; then
print_check "git $(git --version | cut -d' ' -f3)"
else
print_fail "git not found — please install git first"
exit 1
fi
# Check claude CLI (optional)
if command -v claude &>/dev/null; then
print_check "Claude Code available"
else
print_warn "Claude Code not found (optional — install later)"
print_warn " https://docs.anthropic.com/en/docs/claude-code/overview"
fi
# Check if already set up
if [ -f "$BRAIN_PATH/plan.md" ]; then
local status
status=$(sed -n '/^---$/,/^---$/p' "$BRAIN_PATH/plan.md" | grep 'status:' | head -1 | sed 's/.*status:[[:space:]]*//')
if [ "$status" != "template" ] && [ -n "$status" ]; then
if [ "$NON_INTERACTIVE" -eq 1 ]; then
if [ "$FORCE_SETUP" -eq 0 ]; then
echo ""
print_warn "This brain is already set up (plan.md status: ${status}). Nothing changed."
echo -e " ${DIM}Re-run with --force to overwrite the existing setup.${NC}"
exit 0
fi
else
echo ""
print_warn "This brain appears to be already set up (plan.md status: ${status})"
printf " ${WHITE}Re-run setup? This will overwrite existing config.${NC} ${DIM}(y/N)${NC}: "
read -r confirm
if [[ ! "$confirm" =~ ^[yY] ]]; then
echo ""
echo -e " ${DIM}Exiting. Your brain is untouched.${NC}"
exit 0
fi
fi
fi
fi
echo ""
sleep 1
}
# ─── Step 1: Interactive Questions (state machine with back navigation) ──────
# 5 questions total. Left/Right = prev/next question. Up/Down = select option.
collect_info() {
CURRENT_STEP=1
LANG_LABEL=""
SCHEDULE_LABEL=""
local Q_TOTAL=6
USER_ABOUT=""
local step=0 # 0=lang, 1=name, 2=role, 3=focus, 4=schedule, 5=about
while [ "$step" -le 5 ]; do
local q_num=$((step + 1))
# Render screen: header + previous answers + current question
clear
printf "\n"
printf " ${DIM}[1/$TOTAL_STEPS]${NC} ${BOLD_CYAN}$(t "Tell me about yourself" "聊聊你自己")${NC}\n"
printf " ${DIM}$(printf '%.0s─' {1..50})${NC}\n"
# Show completed answers
[ "$step" -gt 0 ] && [ -n "$LANG_LABEL" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Language" "语言")${NC} ${WHITE}${LANG_LABEL}${NC}\n"
[ "$step" -gt 1 ] && [ -n "$USER_NAME" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Name" "名字")${NC} ${WHITE}${USER_NAME}${NC}\n"
[ "$step" -gt 2 ] && [ -n "$USER_ROLE" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Role" "角色")${NC} ${WHITE}${USER_ROLE}${NC}\n"
[ "$step" -gt 3 ] && [ -n "$USER_FOCUS" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Focus" "重点")${NC} ${WHITE}${USER_FOCUS}${NC}\n"
[ "$step" -gt 4 ] && [ -n "$SCHEDULE_LABEL" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Schedule" "作息")${NC} ${WHITE}${SCHEDULE_LABEL}${NC}\n"
case "$step" in
0) # Language
ALLOW_BACK=0 QUESTION_NUM=$q_num QUESTION_TOTAL=$Q_TOTAL \
choose "Language / 语言" "English" "中文"
case $MENU_RESULT in
1) LANG_CHOICE="en"; LANG_LABEL="English" ;;
2) LANG_CHOICE="zh"; LANG_LABEL="中文" ;;
esac
step=1
;;
1) # Name
printf "\n"
# Progress dots
printf " "
for (( i=1; i<=Q_TOTAL; i++ )); do
if [ "$i" -lt "$q_num" ]; then printf "${GREEN}●${NC} "
elif [ "$i" -eq "$q_num" ]; then printf "${CYAN}●${NC} "
else printf "${DIM}○${NC} "; fi
done
printf "\n"
printf " ${WHITE}$(t "Your name" "你的名字")${NC}\n"
read_text
if [ "$INPUT_RESULT" = "__BACK__" ]; then
step=0; continue
elif [ -z "$INPUT_RESULT" ]; then
continue
else
USER_NAME="$INPUT_RESULT"
printf "\n"
printf " ${WHITE}$(t "What should your AI call you?" "想让 AI 怎么称呼你?")${NC}\n"
printf " ${DIM}$(t "A nickname, a title, anything — press Enter to just use your name" "昵称、称号都行——按回车直接用名字")${NC}\n"
read_text
if [ "$INPUT_RESULT" = "__BACK__" ]; then
step=1; continue
fi
USER_NICKNAME="$INPUT_RESULT"
step=2
fi
;;
2) # Role
ALLOW_BACK=1 QUESTION_NUM=$q_num QUESTION_TOTAL=$Q_TOTAL \
choose "$(t "What do you do?" "你是做什么的?")" \
"$(t "Developer" "开发者")" \
"$(t "Designer" "设计师")" \
"$(t "Creator" "创作者")" \
"$(t "Student" "学生")" \
"$(t "Other" "其他")"
if [ "$MENU_RESULT" -eq 0 ]; then
step=1; continue
fi
case $MENU_RESULT in
1) USER_ROLE="Developer" ;;
2) USER_ROLE="Designer" ;;
3) USER_ROLE="Creator" ;;
4) USER_ROLE="Student" ;;
5)
clear
printf "\n"
printf " ${DIM}[1/$TOTAL_STEPS]${NC} ${BOLD_CYAN}$(t "Tell me about yourself" "聊聊你自己")${NC}\n"
printf " ${DIM}$(printf '%.0s─' {1..50})${NC}\n"
[ -n "$LANG_LABEL" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Language" "语言")${NC} ${WHITE}${LANG_LABEL}${NC}\n"
[ -n "$USER_NAME" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Name" "名字")${NC} ${WHITE}${USER_NAME}${NC}\n"
printf "\n"
printf " "
for (( i=1; i<=Q_TOTAL; i++ )); do
if [ "$i" -lt "$q_num" ]; then printf "${GREEN}●${NC} "
elif [ "$i" -eq "$q_num" ]; then printf "${CYAN}●${NC} "
else printf "${DIM}○${NC} "; fi
done
printf "\n"
printf " ${WHITE}$(t "What do you do?" "你是做什么的?")${NC}\n"
read_text
if [ "$INPUT_RESULT" = "__BACK__" ]; then
step=2; continue
fi
USER_ROLE="${INPUT_RESULT:-Other}"
;;
esac
step=3
;;
3) # Focus
ALLOW_BACK=1 QUESTION_NUM=$q_num QUESTION_TOTAL=$Q_TOTAL \
choose "$(t "Most important focus right now?" "你目前最重要的事情是什么?")" \
"$(t "Ship a product" "做产品上线")" \
"$(t "Learn a skill" "学一项技能")" \
"$(t "Build an audience" "做自媒体/涨粉")" \
"$(t "Get a job" "找工作")" \
"$(t "Other" "其他")"
if [ "$MENU_RESULT" -eq 0 ]; then
step=2; continue
fi
case $MENU_RESULT in
1) USER_FOCUS="Ship a product" ;;
2) USER_FOCUS="Learn a skill" ;;
3) USER_FOCUS="Build an audience" ;;
4) USER_FOCUS="Get a job" ;;
5)
clear
printf "\n"
printf " ${DIM}[1/$TOTAL_STEPS]${NC} ${BOLD_CYAN}$(t "Tell me about yourself" "聊聊你自己")${NC}\n"
printf " ${DIM}$(printf '%.0s─' {1..50})${NC}\n"
[ -n "$LANG_LABEL" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Language" "语言")${NC} ${WHITE}${LANG_LABEL}${NC}\n"
[ -n "$USER_NAME" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Name" "名字")${NC} ${WHITE}${USER_NAME}${NC}\n"
[ -n "$USER_ROLE" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Role" "角色")${NC} ${WHITE}${USER_ROLE}${NC}\n"
printf "\n"
printf " "
for (( i=1; i<=Q_TOTAL; i++ )); do
if [ "$i" -lt "$q_num" ]; then printf "${GREEN}●${NC} "
elif [ "$i" -eq "$q_num" ]; then printf "${CYAN}●${NC} "
else printf "${DIM}○${NC} "; fi
done
printf "\n"
printf " ${WHITE}$(t "Most important focus right now?" "你目前最重要的事情是什么?")${NC}\n"
read_text
if [ "$INPUT_RESULT" = "__BACK__" ]; then
step=3; continue
fi
USER_FOCUS="${INPUT_RESULT:-My current project}"
;;
esac
step=4
;;
4) # Schedule
ALLOW_BACK=1 QUESTION_NUM=$q_num QUESTION_TOTAL=$Q_TOTAL \
choose "$(t "When do you usually work?" "你通常什么时候工作?")" \
"$(t "Morning (6am-12pm)" "早晨型 (6am-12pm)")" \
"$(t "Daytime (9am-6pm)" "白天型 (9am-6pm)")" \
"$(t "Evening (6pm-12am)" "晚间型 (6pm-12am)")" \
"$(t "Night owl (10pm-6am)" "夜猫子 (10pm-6am)")" \
"$(t "Irregular / varies" "不固定")"
if [ "$MENU_RESULT" -eq 0 ]; then
step=3; continue
fi
USER_SCHEDULE=$MENU_RESULT
case $USER_SCHEDULE in
1) SCHEDULE_LABEL="$(t "Morning" "早晨型")" ;;
2) SCHEDULE_LABEL="$(t "Daytime" "白天型")" ;;
3) SCHEDULE_LABEL="$(t "Evening" "晚间型")" ;;
4) SCHEDULE_LABEL="$(t "Night owl" "夜猫子")" ;;
5) SCHEDULE_LABEL="$(t "Irregular" "不固定")" ;;
esac
step=5
;;
5) # About you (optional)
printf "\n"
# Progress dots
printf " "
for (( i=1; i<=Q_TOTAL; i++ )); do
if [ "$i" -lt "$q_num" ]; then printf "${GREEN}●${NC} "
elif [ "$i" -eq "$q_num" ]; then printf "${CYAN}●${NC} "
else printf "${DIM}○${NC} "; fi
done
printf "\n"
printf " ${WHITE}$(t "Anything else you'd like me to know?" "还有什么想让我知道的吗?")${NC}\n"
printf " ${DIM}$(t "Habits, birthday, hobbies — optional, press Enter to skip" "习惯、生日、爱好——可选,按回车跳过")${NC}\n"
read_text
if [ "$INPUT_RESULT" = "__BACK__" ]; then
step=4; continue
else
USER_ABOUT="$INPUT_RESULT"
step=6
fi
;;
esac
done
# Show final summary
clear
printf "\n"
printf " ${DIM}[1/$TOTAL_STEPS]${NC} ${BOLD_CYAN}$(t "Tell me about yourself" "聊聊你自己")${NC}\n"
printf " ${DIM}$(printf '%.0s─' {1..50})${NC}\n"
printf " ${GREEN}✓${NC} ${DIM}$(t "Language" "语言")${NC} ${WHITE}${LANG_LABEL}${NC}\n"
printf " ${GREEN}✓${NC} ${DIM}$(t "Name" "名字")${NC} ${WHITE}${USER_NAME}${NC}\n"
[ -n "$USER_NICKNAME" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "Call you" "称呼")${NC} ${WHITE}${USER_NICKNAME}${NC}\n"
printf " ${GREEN}✓${NC} ${DIM}$(t "Role" "角色")${NC} ${WHITE}${USER_ROLE}${NC}\n"
printf " ${GREEN}✓${NC} ${DIM}$(t "Focus" "重点")${NC} ${WHITE}${USER_FOCUS}${NC}\n"
printf " ${GREEN}✓${NC} ${DIM}$(t "Schedule" "作息")${NC} ${WHITE}${SCHEDULE_LABEL}${NC}\n"
[ -n "$USER_ABOUT" ] && printf " ${GREEN}✓${NC} ${DIM}$(t "About" "关于你")${NC} ${WHITE}${USER_ABOUT}${NC}\n"
printf "\n"
printf " ${GREEN}✓${NC} $(t "Got it, ${USER_NAME}!" "收到,${USER_NAME}!")\n"
sleep 1
}
select_ai_tools() {
CURRENT_STEP=1
local has_claude=0
local has_codex=0
local has_workbuddy=0
if command -v claude &>/dev/null || [ -d "$HOME/.claude" ]; then
has_claude=1
fi
if command -v codex &>/dev/null || [ -d "$HOME/.codex" ]; then
has_codex=1
fi
if [ -d "$HOME/.workbuddy" ]; then
has_workbuddy=1
fi
clear
printf "\n"
printf " ${DIM}[1/$TOTAL_STEPS]${NC} ${BOLD_CYAN}$(t "Connect AI tools" "连接 AI 工具")${NC}\n"
printf " ${DIM}$(printf '%.0s─' {1..50})${NC}\n"
printf " ${DIM}$(t "Loci gives all your AI tools one shared local brain." "Loci 让你的所有 AI 工具共用一个本地大脑。")${NC}\n"
printf "\n"
[ "$has_claude" -eq 1 ] && printf " ${GREEN}✓${NC} Claude Code\n" || printf " ${YELLOW}!${NC} Claude Code $(t "not detected" "未检测到")\n"
[ "$has_codex" -eq 1 ] && printf " ${GREEN}✓${NC} Codex\n" || printf " ${YELLOW}!${NC} Codex $(t "not detected" "未检测到")\n"
[ "$has_workbuddy" -eq 1 ] && printf " ${GREEN}✓${NC} WorkBuddy\n"
if [ "$has_claude" -eq 1 ] && [ "$has_codex" -eq 1 ]; then
ALLOW_BACK=0 QUESTION_NUM=6 QUESTION_TOTAL=6 \
choose "$(t "Which tools should share this brain?" "哪些工具要共用这个大脑?")" \
"$(t "Claude Code + Codex (Recommended)" "Claude Code + Codex(推荐)")" \
"$(t "Claude Code only" "只接 Claude Code")" \
"$(t "Codex only" "只接 Codex")" \
"$(t "Create brain only" "只创建本地大脑")"
case $MENU_RESULT in
1) CONNECT_CLAUDE=1; CONNECT_CODEX=1; CONNECT_LABEL="Claude Code + Codex" ;;
2) CONNECT_CLAUDE=1; CONNECT_CODEX=0; CONNECT_LABEL="Claude Code" ;;
3) CONNECT_CLAUDE=0; CONNECT_CODEX=1; CONNECT_LABEL="Codex" ;;
4) CONNECT_CLAUDE=0; CONNECT_CODEX=0; CONNECT_LABEL="$(t "Brain only" "仅本地大脑")" ;;
esac
elif [ "$has_claude" -eq 1 ]; then
ALLOW_BACK=0 QUESTION_NUM=6 QUESTION_TOTAL=6 \
choose "$(t "Connect Loci to Claude Code?" "要接入 Claude Code 吗?")" \
"$(t "Claude Code (Recommended)" "Claude Code(推荐)")" \
"$(t "Create brain only" "只创建本地大脑")"
case $MENU_RESULT in
1) CONNECT_CLAUDE=1; CONNECT_CODEX=0; CONNECT_LABEL="Claude Code" ;;
2) CONNECT_CLAUDE=0; CONNECT_CODEX=0; CONNECT_LABEL="$(t "Brain only" "仅本地大脑")" ;;
esac
elif [ "$has_codex" -eq 1 ]; then
ALLOW_BACK=0 QUESTION_NUM=6 QUESTION_TOTAL=6 \
choose "$(t "Connect Loci to Codex?" "要接入 Codex 吗?")" \
"$(t "Codex (Recommended)" "Codex(推荐)")" \
"$(t "Create brain only" "只创建本地大脑")"
case $MENU_RESULT in
1) CONNECT_CLAUDE=0; CONNECT_CODEX=1; CONNECT_LABEL="Codex" ;;
2) CONNECT_CLAUDE=0; CONNECT_CODEX=0; CONNECT_LABEL="$(t "Brain only" "仅本地大脑")" ;;
esac
else
CONNECT_CLAUDE=0
CONNECT_CODEX=0
CONNECT_LABEL="$(t "Brain only" "仅本地大脑")"
printf "\n"
print_warn "$(t "No Claude Code or Codex install detected. Creating the brain only." "没有检测到 Claude Code 或 Codex,先只创建本地大脑。")"
sleep 1
fi
if [ "$has_workbuddy" -eq 1 ]; then
ALLOW_BACK=0 QUESTION_NUM=6 QUESTION_TOTAL=6 \
choose "$(t "WorkBuddy detected — connect it to the same brain?" "检测到 WorkBuddy——也接入同一个大脑吗?")" \
"$(t "Yes, connect WorkBuddy (Recommended)" "接入 WorkBuddy(推荐)")" \
"$(t "Skip WorkBuddy" "跳过 WorkBuddy")"
case $MENU_RESULT in
1)
CONNECT_WORKBUDDY=1
if [ "$CONNECT_LABEL" = "$(t "Brain only" "仅本地大脑")" ]; then
CONNECT_LABEL="WorkBuddy"
else
CONNECT_LABEL="$CONNECT_LABEL + WorkBuddy"
fi
;;
2) CONNECT_WORKBUDDY=0 ;;
esac
fi
}
# ─── Step 2: File Generation ────────────────────────────────────────────────
generate_files() {
CURRENT_STEP=2
echo ""
print_step "$(t "Setting up your brain" "配置你的大脑")"
local today_date
today_date="$(today)"
local now_iso task_slug task_id json_focus
now_iso="$(date '+%Y-%m-%dT%H:%M:%S%z')"
task_slug="$(printf "%s" "$USER_FOCUS" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9][^a-z0-9]*/_/g; s/^_*//; s/_*$//; s/^\(.\{48\}\).*/\1/')"
[ -z "$task_slug" ] && task_slug="first_task"
task_id="task_$(printf "%s" "$today_date" | tr -d '-')_${task_slug}"
json_focus="${USER_FOCUS//\\/\\\\}"
json_focus="${json_focus//\"/\\\"}"
# --- me/identity.md ---
(
cat > "$BRAIN_PATH/me/identity.md" << IDEOF
---
created: ${today_date}
updated: ${today_date}
tags: [identity, core]
status: active
---
# Who I Am
## Basics
- **Name**: ${USER_NAME}
- **Role**: ${USER_ROLE}
## Current Season
- **Focus**: ${USER_FOCUS}
$([ -n "${USER_ABOUT}" ] && printf "\n## About Me\n${USER_ABOUT}")
IDEOF
) &
spin "$(t "me/identity.md" "me/identity.md")"
# --- me/preferences.md ---
local pref_call="${USER_NICKNAME:-$USER_NAME}"
local pref_lang
case "$LANG_CHOICE" in
zh) pref_lang="中文" ;;
mix) pref_lang="中文为主,中英混用" ;;
*) pref_lang="English" ;;
esac
(
cat > "$BRAIN_PATH/me/preferences.md" << PREFEOF
---
created: ${today_date}
updated: ${today_date}
tags: [preferences, core]
status: active
---
# How to Work With Me
## Address Me As
- **Call me**: ${pref_call}
## Language & Tone
- **Language**: ${pref_lang}
## Reply Style
<!-- e.g. "short answers first" / "no emoji" — tell your AI and it lands here -->
## Work
<!-- work defaults, e.g. "docs start with a TL;DR" / "外发内容先给我看草稿" -->
## Do / Don't
<!-- standing rules for your AI, e.g. "Don't schedule anything before 10am" -->
PREFEOF
) &
spin "$(t "me/preferences.md" "me/preferences.md")"
# --- plan.md ---
(
cat > "$BRAIN_PATH/plan.md" << PLANEOF
---
created: ${today_date}
updated: ${today_date}
status: active
---
# Life Direction & Goals
> Your north star. Everything day-to-day should trace back here.
## Mission
<!-- Define your mission — what drives you? -->
## Current Goals
### Goal 1: ${USER_FOCUS}
- Status: Just started
- Key results: (define what success looks like)
PLANEOF
) &
spin "$(t "plan.md" "plan.md")"
# --- tasks/tasks.json ---
(
cat > "$BRAIN_PATH/tasks/tasks.json" << TASKDBEOF
{
"tasks": [
{
"id": "${task_id}",
"title": "${json_focus}",
"status": "open",
"date": null,
"startTime": null,
"endTime": null,
"project": null,
"source": "setup",
"createdAt": "${now_iso}",
"updatedAt": "${now_iso}",
"completedAt": null,
"archivedAt": null
}
]
}
TASKDBEOF
) &
spin "$(t "tasks/tasks.json" "tasks/tasks.json")"
# --- tasks/active.md ---
(
cat > "$BRAIN_PATH/tasks/active.md" << TASKEOF
---
updated: ${today_date}
schema: task-view-v1
source: tasks.json
---
# Active Tasks
> Generated context cache from \`tasks/tasks.json\`. Do not edit by hand.
## Open
- [ ] ${USER_FOCUS} <!-- id: ${task_id}; source: setup; updated: ${now_iso} -->
## Stale
<!-- No stale tasks. -->
## Recently Done
<!-- No recently completed tasks. -->
TASKEOF
) &
spin "$(t "tasks/active.md" "tasks/active.md")"
# Re-render active.md with the authoritative renderer so it is byte-identical
# to what `loci-task.js validate` expects (avoids a day-one "stale" warning).
if command -v node >/dev/null 2>&1 && [ -f "$BRAIN_PATH/scripts/loci-task.js" ]; then
node "$(node_fs_path "$BRAIN_PATH/scripts/loci-task.js")" rebuild >/dev/null 2>&1 || true
fi
# --- .loci/config.yml ---
local wake_time wind_time wellbeing_enabled
case $USER_SCHEDULE in
1) wake_time="05:30"; wind_time="21:00"; wellbeing_enabled="true" ;;
2) wake_time="07:00"; wind_time="22:30"; wellbeing_enabled="true" ;;
3) wake_time="10:00"; wind_time="01:00"; wellbeing_enabled="true" ;;
4) wake_time="14:00"; wind_time="04:00"; wellbeing_enabled="true" ;;
5) wake_time="07:00"; wind_time="22:30"; wellbeing_enabled="false" ;;
esac
(
cat > "$BRAIN_PATH/.loci/config.yml" << CFGEOF
# Loci Configuration
# Modify these settings to customize your brain's behavior.
version: 1
language: ${LANG_CHOICE} # en | zh | mix
persistence:
mode: auto # auto | manual
notify: true # show save notifications
wellbeing:
enabled: ${wellbeing_enabled}
wind_down_time: "${wind_time}"
wake_up_time: "${wake_time}"
max_reminders: 2
CFGEOF
) &
spin "$(t ".loci/config.yml" ".loci/config.yml")"
# --- .loci/status.yml (user state — local, gitignored) ---
if [ ! -f "$BRAIN_PATH/.loci/status.yml" ]; then
cat > "$BRAIN_PATH/.loci/status.yml" << STEOF
# User State — Auto-updated by the AI based on conversation signals.
# You can also set it manually by telling the AI how you feel.
#
# Fields:
# state: fresh-start | focused | exploring | winding-down | low-energy | away
# energy: low | moderate | high
# updated: ISO timestamp of last update
# ttl: how long this state is valid (e.g. "4h", "1d")
# context: free-text description of current situation
# override: user-set values (highest priority, expires after ttl)
state: fresh-start
energy: null