-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup
More file actions
executable file
·175 lines (162 loc) · 6.36 KB
/
Copy pathsetup
File metadata and controls
executable file
·175 lines (162 loc) · 6.36 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
#!/usr/bin/env bash
# brainstack setup - install the second brain stack for Hermes Agent.
#
# What it does:
# 1. Copies all skills to ~/.hermes/skills/brainstack/ (Hermes loads them
# on the next session).
# 2. Scaffolds vault-template/ into your vault (or creates ~/brain-vault).
# Non-destructive: never overwrites existing files.
# 3. Copies bin/ to ~/.brainstack/bin/ and writes ~/.brainstack/env.sh.
# 4. Wires the nightly dream-cycle cron (skip with --no-cron).
#
# Usage:
# ./setup [--vault PATH] [--no-cron] [--dry-run] [--upgrade] [--embeddings] [--version]
#
# --embeddings create ~/.brainstack/venv and install sentence-transformers
# so semantic search uses real embeddings (optional).
#
# --upgrade refresh skills and bin scripts in place (used by
# `brain upgrade`); vault files are still never touched.
#
# --version print the stack version (VERSION file) and exit.
#
# Config: BRAINSTACK_VAULT env var overrides the vault path.
set -euo pipefail
HERMES_HOME="${HERMES_HOME:-$HOME/.hermes}"
BRAINSTACK_HOME="$HOME/.brainstack"
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VAULT="${BRAINSTACK_VAULT:-}"
case "${1:-}" in
''|--*) ;; # no positional vault, or a flag
*) VAULT="${VAULT:-$1}" ;;
esac
NO_CRON=0
DRY_RUN=0
UPGRADE=0
SHOW_VERSION=0
for arg in "$@"; do
case "$arg" in
--vault=*) VAULT="${arg#--vault=}" ;;
--no-cron) NO_CRON=1 ;;
--dry-run) DRY_RUN=1 ;;
--upgrade) UPGRADE=1 ;;
--embeddings) EMBEDDINGS=1 ;;
--version|-v) SHOW_VERSION=1 ;;
esac
done
EMBEDDINGS="${EMBEDDINGS:-0}"
if [ "$SHOW_VERSION" -eq 1 ]; then
cat "$REPO_DIR/VERSION"
echo
exit 0
fi
VAULT="${VAULT:-$HOME/brain-vault}"
step() { printf "\n\033[1m== %s\033[0m\n" "$*"; }
say() { printf " %s\n" "$*"; }
# ---- 1. Skills --------------------------------------------------------------
step "1/4 Installing skills to Hermes"
SKILLS_DEST="$HERMES_HOME/skills/brainstack"
if [ "$DRY_RUN" -eq 1 ]; then
say "would copy skills/ -> $SKILLS_DEST"
else
mkdir -p "$SKILLS_DEST"
count=0
for skill in "$REPO_DIR"/skills/*/; do
name="$(basename "$skill")"
if [ -e "$SKILLS_DEST/$name" ] && [ "$UPGRADE" -eq 0 ]; then
say "skip (exists): $name"
continue
fi
rm -rf "$SKILLS_DEST/$name"
cp -R "$skill" "$SKILLS_DEST/$name"
say "installed: $name"
count=$((count + 1))
done
say "$count skills installed. They load on the NEXT Hermes session."
say "NOTE: if you already have skills named capture/memory/index, they may"
say " shadow these - rename or remove yours first."
fi
# ---- 2. Vault scaffold -------------------------------------------------------
step "2/4 Scaffolding vault at $VAULT"
if [ "$DRY_RUN" -eq 1 ]; then
say "would scaffold vault-template/ -> $VAULT (non-destructive)"
else
mkdir -p "$VAULT"
# Non-destructive copy: -n never overwrites existing files
cp -Rn "$REPO_DIR"/vault-template/. "$VAULT"/ 2>/dev/null || true
# The operating agreement travels with the vault (never overwrites).
cp -n "$REPO_DIR/AGENTS.md" "$VAULT/AGENTS.md" 2>/dev/null || true
if [ -f "$VAULT/01-Wiki/now/recent.md" ]; then
say "vault scaffolded (existing files preserved)"
else
say "WARNING: scaffold may have failed - check $VAULT"
fi
say "git init recommended: cd \"$VAULT\" && git init && git add -A && git commit -m init"
fi
# ---- 3. bin scripts ----------------------------------------------------------
step "3/4 Installing bin scripts to $BRAINSTACK_HOME"
if [ "$DRY_RUN" -eq 1 ]; then
say "would copy bin/ -> $BRAINSTACK_HOME/bin and write env.sh"
else
mkdir -p "$BRAINSTACK_HOME/bin"
cp -R "$REPO_DIR"/bin/. "$BRAINSTACK_HOME/bin/" 2>/dev/null || true
chmod +x "$BRAINSTACK_HOME"/bin/*.py "$BRAINSTACK_HOME"/bin/*.sh 2>/dev/null || true
cat > "$BRAINSTACK_HOME/env.sh" <<EOF
# brainstack environment - source from your shell rc or cron lines
export BRAINSTACK_VAULT="$VAULT"
export BRAINSTACK_HOME="$BRAINSTACK_HOME"
EOF
printf '%s\n' "$REPO_DIR" > "$BRAINSTACK_HOME/repo-path"
say "env: $BRAINSTACK_HOME/env.sh (BRAINSTACK_VAULT=$VAULT)"
say "add to your shell: source ~/.brainstack/env.sh"
# The `brain` CLI: one entry point for everything in bin/.
mkdir -p "$HOME/.local/bin"
ln -sf "$BRAINSTACK_HOME/bin/brain" "$HOME/.local/bin/brain"
if command -v brain >/dev/null 2>&1; then
say "brain CLI installed (try: brain help)"
else
say "brain CLI installed at ~/.local/bin/brain"
say "add to PATH: export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
fi
# ---- 3b. Optional embeddings venv -------------------------------------------
if [ "$EMBEDDINGS" -eq 1 ] && [ "$DRY_RUN" -eq 0 ]; then
step "3b Optional: embeddings venv (semantic search)"
if [ ! -x "$BRAINSTACK_HOME/venv/bin/pip" ]; then
python3 -m venv "$BRAINSTACK_HOME/venv"
fi
"$BRAINSTACK_HOME/venv/bin/pip" install -q --upgrade sentence-transformers \
&& say "sentence-transformers installed - search uses real embeddings" \
|| say "pip install failed - search will use the keyword fallback"
fi
# ---- 4. Cron -----------------------------------------------------------------
step "4/4 Nightly dream-cycle cron"
CRON_LINE="0 3 * * * source $BRAINSTACK_HOME/env.sh && python3 $BRAINSTACK_HOME/bin/dream-cycle.py >> $BRAINSTACK_HOME/dream-cycle.log 2>&1"
if [ "$NO_CRON" -eq 1 ] || [ "$DRY_RUN" -eq 1 ]; then
say "cron skipped/planned. Add manually if desired:"
say " $CRON_LINE"
elif command -v crontab >/dev/null 2>&1; then
if crontab -l 2>/dev/null | grep -q "dream-cycle.py"; then
say "cron already installed"
else
(crontab -l 2>/dev/null; echo "$CRON_LINE") | crontab -
say "cron installed: dream cycle daily at 03:00"
fi
else
say "crontab not available. Add manually:"
say " $CRON_LINE"
fi
# ---- Done --------------------------------------------------------------------
if [ "$DRY_RUN" -eq 0 ]; then
step "Done - first run checklist"
cat <<'EOF'
1. Open the vault and write today's 3 priorities in 01-Wiki/now/essentials.md
2. Create your first pages: People/, Organizations/ (use templates/)
3. Build the search index: brain index
4. Start a NEW Hermes session - the brainstack skills will be available
5. Run a health check: brain doctor
6. Read ARCHITECTURE.md - the design is the product
Everyday driving: brain inbox | brain search <q> | brain dream | brain sync
Later: brain upgrade / brain uninstall
EOF
fi