-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·298 lines (250 loc) · 8.96 KB
/
setup.sh
File metadata and controls
executable file
·298 lines (250 loc) · 8.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
290
291
292
293
294
295
296
297
298
#!/usr/bin/env bash
set -euo pipefail
VERSION="1.1.3"
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
SKILLS=("compile-wiki" "ask-wiki" "lint-wiki")
usage() {
cat <<EOF
Usage: $(basename "$0") <platform>... [global|local]
$(basename "$0") --uninstall <platform>...
Install PersonalKnowledgeBase skills for your AI coding assistant.
Platforms:
cursor → ~/.cursor/skills/
claude → ~/.claude/skills/
copilot → ~/.copilot/skills/
Scopes (optional; default: global):
global Symlink skills, write global wiki-config next to skills,
create raw/ and output/ in this repo (your cross-project wiki).
local Symlink skills, scaffold a wiki in the current directory
(raw/, output/, wiki/, AGENTS.md, wiki-config.md). Overrides
global when that file exists in the project root.
Examples:
./setup.sh cursor # same as: cursor global
./setup.sh cursor global
./setup.sh cursor claude global
./setup.sh cursor local # init wiki in \$PWD (any project)
To uninstall:
./setup.sh --uninstall cursor
EOF
exit 1
}
resolve_target_dir() {
case "$1" in
cursor) echo "$HOME/.cursor/skills" ;;
claude) echo "$HOME/.claude/skills" ;;
copilot) echo "$HOME/.copilot/skills" ;;
*)
echo "Unknown platform: $1" >&2
echo "Supported: cursor, claude, copilot" >&2
return 1
;;
esac
}
# Symlink skills only (no wiki-config).
install_platform() {
local platform="$1"
local target_dir
target_dir="$(resolve_target_dir "$platform")" || return 1
echo "[$platform] Installing skills (v$VERSION) to $target_dir"
mkdir -p "$target_dir"
for skill in "${SKILLS[@]}"; do
local src="$REPO_DIR/skills/$skill"
local dst="$target_dir/$skill"
if [ -L "$dst" ]; then
local existing
existing="$(readlink -f "$dst")"
if [ "$existing" = "$src" ]; then
echo " $skill → already linked (skipped)"
continue
fi
echo " $skill → updating symlink (was: $existing)"
rm "$dst"
elif [ -d "$dst" ]; then
echo " $skill → WARNING: directory exists and is NOT a symlink."
echo " Back it up manually if needed, then re-run."
continue
fi
ln -s "$src" "$dst"
echo " $skill → linked"
done
echo "[$platform] Skills done."
echo ""
}
write_global_config() {
local platform="$1"
local target_dir
target_dir="$(resolve_target_dir "$platform")" || return 1
cat > "$target_dir/wiki-config.md" <<EOF
# Wiki Configuration
> Generated by setup.sh on $(date '+%Y-%m-%d'). Do not edit manually.
- **Wiki root:** \`$REPO_DIR\`
- **Wiki folder:** \`$REPO_DIR/wiki\`
- **Raw folder:** \`$REPO_DIR/raw\`
- **Output folder:** \`$REPO_DIR/output\`
EOF
echo "[$platform] wiki-config.md → written (global)"
echo ""
}
# Scaffold a project-local wiki in the current working directory.
init_local() {
local local_root
local_root="$(pwd)"
echo "[local] Scaffolding wiki in: $local_root"
mkdir -p "$local_root/raw" "$local_root/output" "$local_root/wiki"
if [ ! -f "$local_root/wiki/index.md" ]; then
if [ -f "$REPO_DIR/wiki/index.md" ]; then
cp "$REPO_DIR/wiki/index.md" "$local_root/wiki/index.md"
else
cat > "$local_root/wiki/index.md" <<'IDX'
# Knowledge Base Index
Welcome to your compounding knowledge base! This file serves as the master taxonomy of all topics extracted from your raw files.
## Topics
<!-- Topics will appear here as you process raw files with compile-wiki.
Each entry follows the format: "- Topic Name: One-line description" -->
---
*Note: Topics are extracted to prioritize general concepts, abstract ideas, processes, and subject matters rather than specific authors or individuals.*
IDX
fi
echo " wiki/index.md → created"
else
echo " wiki/index.md → already exists (skipped)"
fi
if [ ! -f "$local_root/wiki/log.md" ]; then
if [ -f "$REPO_DIR/wiki/log.md" ]; then
cp "$REPO_DIR/wiki/log.md" "$local_root/wiki/log.md"
else
cat > "$local_root/wiki/log.md" <<'LOG'
# Knowledge Base Processing Log
This log tracks which files from the `raw/` folder have been processed and when they were added to the wiki. It prevents the agent from needlessly re-processing old files.
| Date/Time | File Processed | Key Topics Extracted | Status |
|-----------|----------------|----------------------|--------|
LOG
fi
echo " wiki/log.md → created"
else
echo " wiki/log.md → already exists (skipped)"
fi
if [ ! -f "$local_root/AGENTS.md" ]; then
cp "$REPO_DIR/AGENTS.md" "$local_root/AGENTS.md"
echo " AGENTS.md → copied from template"
else
echo " AGENTS.md → already exists (skipped)"
fi
if [ ! -f "$local_root/lint_graph.js" ] && [ -f "$REPO_DIR/lint_graph.js" ]; then
cp "$REPO_DIR/lint_graph.js" "$local_root/lint_graph.js"
echo " lint_graph.js → copied from template (for /lint-wiki)"
elif [ -f "$local_root/lint_graph.js" ]; then
echo " lint_graph.js → already exists (skipped)"
fi
if [ ! -d "$local_root/wiki/.obsidian" ] && [ -d "$REPO_DIR/wiki/.obsidian" ]; then
cp -R "$REPO_DIR/wiki/.obsidian" "$local_root/wiki/.obsidian"
echo " wiki/.obsidian/ → copied from template"
elif [ -d "$local_root/wiki/.obsidian" ]; then
echo " wiki/.obsidian/ → already exists (skipped)"
else
echo " wiki/.obsidian/ → template missing (skipped)"
fi
cat > "$local_root/wiki-config.md" <<EOF
# Wiki Configuration
> Generated by setup.sh (local) on $(date '+%Y-%m-%d'). Do not edit manually.
- **Wiki root:** \`$local_root\`
- **Wiki folder:** \`$local_root/wiki\`
- **Raw folder:** \`$local_root/raw\`
- **Output folder:** \`$local_root/output\`
EOF
echo " wiki-config.md → written (project root)"
echo "[local] Done."
echo ""
}
uninstall_platform() {
local platform="$1"
local target_dir
target_dir="$(resolve_target_dir "$platform")" || return 1
echo "[$platform] Removing skill symlinks from $target_dir"
for skill in "${SKILLS[@]}"; do
local dst="$target_dir/$skill"
if [ -L "$dst" ]; then
rm "$dst"
echo " $skill → removed"
elif [ -e "$dst" ]; then
echo " $skill → skipped (not a symlink, won't touch it)"
else
echo " $skill → not found (skipped)"
fi
done
if [ -f "$target_dir/wiki-config.md" ]; then
rm "$target_dir/wiki-config.md"
echo " wiki-config.md → removed"
fi
echo "[$platform] Uninstalled."
echo ""
}
# --- Main ---
[ $# -eq 0 ] && usage
UNINSTALL=false
PLATFORMS=()
SCOPE=global
SCOPE_COUNT=0
for arg in "$@"; do
case "$arg" in
--uninstall) UNINSTALL=true ;;
--help|-h) usage ;;
global)
SCOPE=global
SCOPE_COUNT=$((SCOPE_COUNT + 1))
;;
local)
SCOPE=local
SCOPE_COUNT=$((SCOPE_COUNT + 1))
;;
*)
PLATFORMS+=("$arg")
;;
esac
done
[ ${#PLATFORMS[@]} -eq 0 ] && usage
if [ "$SCOPE_COUNT" -gt 1 ]; then
echo "Error: specify only one of 'global' or 'local'." >&2
exit 1
fi
if $UNINSTALL; then
for p in "${PLATFORMS[@]}"; do
uninstall_platform "$p"
done
exit 0
fi
if [ "$SCOPE" = "global" ]; then
# Disconnect from the template origin (repo only)
if git -C "$REPO_DIR" remote get-url origin 2>/dev/null | grep -qi "PersonalKnowledgeBaseCreator"; then
echo "Disconnecting from template repository to prevent accidental pushes..."
git -C "$REPO_DIR" remote rename origin template-origin
echo " origin → renamed to 'template-origin'"
echo " To push your wiki to your own repo, run:"
echo " git remote add origin <your-repo-url>"
echo ""
fi
mkdir -p "$REPO_DIR/raw" "$REPO_DIR/output"
fi
for p in "${PLATFORMS[@]}"; do
install_platform "$p"
if [ "$SCOPE" = "global" ]; then
write_global_config "$p"
fi
done
if [ "$SCOPE" = "local" ]; then
init_local
fi
echo "Setup complete. Skills are symlinked — git pull updates them automatically."
echo ""
echo "Quick start:"
if [ "$SCOPE" = "global" ]; then
echo " 1. Edit AGENTS.md and fill in your focus areas"
echo " 2. Drop files into raw/"
echo " 3. Open in your AI assistant and say: 'Compile the wiki'"
echo " 4. Browse wiki/ in any editor (Obsidian optional — open wiki/ as a vault for graph view)"
else
echo " 1. Edit AGENTS.md in this directory and fill in your focus areas"
echo " 2. Drop files into raw/"
echo " 3. Open in your AI assistant and say: 'Compile the wiki'"
echo " 4. Browse wiki/ in any editor (Obsidian optional — open wiki/ as a vault for graph view)"
fi