-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·322 lines (273 loc) · 9.59 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·322 lines (273 loc) · 9.59 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
#!/bin/bash
set -eo pipefail
# Detect script location BEFORE any cd operations
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ----- Prerequisites -----
check_command() {
if ! command -v "$1" &> /dev/null; then
echo -e "\033[0;31mRequired: '$1' is not installed.\033[0m"
echo "Please install $1 and try again."
exit 1
fi
}
check_command python3
check_command git
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
BOLD='\033[1m'
echo ""
echo -e "${CYAN}${BOLD}llm-wiki setup${NC}"
echo -e "${CYAN}Build Karpathy's LLM Wiki with Claude Code${NC}"
echo ""
# ----- Step 1: Tool selection -----
echo -e "${BOLD}Which note-taking tool do you use?${NC}"
echo " 1) Logseq"
echo " 2) Obsidian"
read -p "Enter choice [1/2]: " tool_choice
case $tool_choice in
1) TOOL="logseq" ;;
2) TOOL="obsidian" ;;
*) echo -e "${RED}Invalid choice. Exiting.${NC}"; exit 1 ;;
esac
echo -e "${GREEN}Selected: $TOOL${NC}"
echo ""
# ----- Step 2: Wiki path -----
if [ "$TOOL" = "logseq" ]; then
DEFAULT_PATH="$HOME/Documents/Logseq"
else
DEFAULT_PATH="$HOME/Documents/ObsidianVault"
fi
echo -e "${BOLD}Where is your $TOOL graph/vault?${NC}"
read -p "Path [$DEFAULT_PATH]: " wiki_path
wiki_path="${wiki_path:-$DEFAULT_PATH}"
# Expand ~ to $HOME
wiki_path="${wiki_path/#\~/$HOME}"
if [ ! -d "$wiki_path" ]; then
echo -e "${YELLOW}Directory does not exist. Create it? [y/n]${NC}"
read -p "" create_dir
if [ "$create_dir" = "y" ] || [ "$create_dir" = "Y" ]; then
mkdir -p "$wiki_path"
echo -e "${GREEN}Created: $wiki_path${NC}"
else
echo -e "${RED}Exiting. Please create the directory first.${NC}"
exit 1
fi
fi
echo ""
# ----- Step 3: Pages directory -----
if [ "$TOOL" = "logseq" ]; then
PAGES_DIR="pages"
else
PAGES_DIR=""
fi
pages_path="$wiki_path/$PAGES_DIR"
if [ -n "$PAGES_DIR" ] && [ ! -d "$pages_path" ]; then
mkdir -p "$pages_path"
fi
# ----- Step 4: Namespaces -----
DEFAULT_NS="Business Tech Content Projects People Learning Reference"
echo -e "${BOLD}Which namespaces do you want?${NC}"
echo -e "Default: ${CYAN}$DEFAULT_NS${NC}"
read -p "Enter space-separated list (or press Enter for default): " custom_ns
NAMESPACES="${custom_ns:-$DEFAULT_NS}"
# Validate namespace names (no spaces within names, no special characters)
for ns in $NAMESPACES; do
if [[ ! "$ns" =~ ^[A-Za-z][A-Za-z0-9-]*$ ]]; then
echo -e "${RED}Invalid namespace name: '$ns'${NC}"
echo "Namespace names must start with a letter and contain only letters, numbers, and hyphens."
exit 1
fi
done
echo -e "${GREEN}Namespaces: $NAMESPACES${NC}"
echo ""
# ----- Step 5: Memory path -----
echo -e "${BOLD}Where is your Claude Code memory directory?${NC}"
echo -e "(Usually: ~/.claude/projects/<project>/memory/)"
read -p "Path [skip]: " memory_path
memory_path="${memory_path/#\~/$HOME}"
echo ""
# ----- Step 6: Git init -----
if [ ! -d "$wiki_path/.git" ]; then
echo -e "${BOLD}Initialize git in $wiki_path?${NC} [y/n]"
read -p "" init_git
if [ "$init_git" = "y" ] || [ "$init_git" = "Y" ]; then
cd "$wiki_path"
git init
# Create .gitignore
if [ "$TOOL" = "logseq" ]; then
cat > .gitignore << 'GITIGNORE'
logseq/bak/
logseq/.recycle/
.DS_Store
.logseq/
GITIGNORE
else
cat > .gitignore << 'GITIGNORE'
.obsidian/workspace.json
.obsidian/workspace-mobile.json
.DS_Store
.trash/
GITIGNORE
fi
echo -e "${GREEN}Git initialized with .gitignore${NC}"
fi
fi
echo ""
# ----- Step 7: Set template directory -----
TEMPLATE_DIR="$SCRIPT_DIR/templates/$TOOL"
if [ ! -d "$TEMPLATE_DIR" ]; then
echo -e "${RED}Templates not found at $TEMPLATE_DIR${NC}"
echo "Make sure you're running this from the llm-wiki repository."
exit 1
fi
# ----- Step 8: Create wiki pages via Python (handles multiline templates) -----
echo -e "${BOLD}Creating wiki pages...${NC}"
TODAY=$(date +%Y-%m-%d)
python3 << PYEOF
import os
tool = "$TOOL"
pages_path = "$pages_path"
wiki_path = "$wiki_path"
template_dir = "$TEMPLATE_DIR"
namespaces = "$NAMESPACES".split()
today = "$TODAY"
def read_template(name):
with open(os.path.join(template_dir, name)) as f:
return f.read()
def write_file(path, content):
os.makedirs(os.path.dirname(path), exist_ok=True)
if os.path.exists(path):
print(f" Skipped (already exists): {os.path.basename(path)}")
return False
with open(path, 'w') as f:
f.write(content)
return True
if tool == "logseq":
# Schema
ns_list = ", ".join(f"Wiki/{ns}" for ns in namespaces)
schema = read_template("Schema.md")
schema = schema.replace("{{NAMESPACES}}", ns_list)
schema = schema.replace("{{DATE}}", today)
if write_file(os.path.join(pages_path, "Wiki___Schema.md"), schema):
print(f" Created: Wiki/Schema")
# Dashboard
ns_links = "\n".join(f"\t- [[Wiki/{ns}]]" for ns in namespaces)
dashboard = read_template("Dashboard.md")
dashboard = dashboard.replace("{{NAMESPACE_LINKS}}", ns_links)
dashboard = dashboard.replace("{{DATE}}", today)
if write_file(os.path.join(pages_path, "Wiki___Dashboard.md"), dashboard):
print(f" Created: Wiki/Dashboard")
# Hub pages
hub_tpl = read_template("Hub.md")
for ns in namespaces:
hub = hub_tpl.replace("{{NAMESPACE}}", ns).replace("{{DATE}}", today)
if write_file(os.path.join(pages_path, f"Wiki___{ns}.md"), hub):
print(f" Created: Wiki/{ns}")
# Access-Log (append-only LRU signal for /wiki prune)
access_log = read_template("Access-Log.md").replace("{{DATE}}", today)
if write_file(os.path.join(pages_path, "Wiki___Reference___Access-Log.md"), access_log):
print(f" Created: Wiki/Reference/Access-Log")
else:
wiki_dir = os.path.join(wiki_path, "Wiki")
os.makedirs(wiki_dir, exist_ok=True)
# Schema
ns_list = ", ".join(f"Wiki/{ns}" for ns in namespaces)
schema = read_template("Schema.md")
schema = schema.replace("{{NAMESPACES}}", ns_list)
schema = schema.replace("{{DATE}}", today)
if write_file(os.path.join(wiki_dir, "Schema.md"), schema):
print(f" Created: Wiki/Schema.md")
# Dashboard
ns_links = "\n".join(f"- [[Wiki/{ns}]]" for ns in namespaces)
dashboard = read_template("Dashboard.md")
dashboard = dashboard.replace("{{NAMESPACE_LINKS}}", ns_links)
dashboard = dashboard.replace("{{DATE}}", today)
if write_file(os.path.join(wiki_dir, "Dashboard.md"), dashboard):
print(f" Created: Wiki/Dashboard.md")
# Hub pages
hub_tpl = read_template("Hub.md")
for ns in namespaces:
ns_dir = os.path.join(wiki_dir, ns)
os.makedirs(ns_dir, exist_ok=True)
hub = hub_tpl.replace("{{NAMESPACE}}", ns).replace("{{DATE}}", today)
if write_file(os.path.join(ns_dir, "_index.md"), hub):
print(f" Created: Wiki/{ns}/_index.md")
# Access-Log (append-only LRU signal for /wiki prune)
ref_dir = os.path.join(wiki_dir, "Reference")
os.makedirs(ref_dir, exist_ok=True)
access_log = read_template("Access-Log.md").replace("{{DATE}}", today)
if write_file(os.path.join(ref_dir, "Access-Log.md"), access_log):
print(f" Created: Wiki/Reference/Access-Log.md")
PYEOF
# ----- Step 9: Create llm-wiki.yml -----
CONFIG_FILE="$wiki_path/llm-wiki.yml"
write_config() {
cat > "$CONFIG_FILE" << YAML
# llm-wiki configuration
# Generated by setup.sh on $(date +%Y-%m-%d)
tool: $TOOL
wiki_path: $wiki_path
pages_dir: $PAGES_DIR
memory_path: ${memory_path:-""}
namespaces:
$(for ns in $NAMESPACES; do echo " - $ns"; done)
YAML
echo -e " ${GREEN}Created: llm-wiki.yml${NC}"
}
if [ -f "$CONFIG_FILE" ]; then
echo -e "${YELLOW}llm-wiki.yml already exists. Overwrite? [y/n]${NC}"
read -p "" overwrite_config
if [ "$overwrite_config" = "y" ] || [ "$overwrite_config" = "Y" ]; then
write_config
else
echo -e " Keeping existing config."
fi
else
write_config
fi
# ----- Step 10: Install /wiki skill -----
echo ""
echo -e "${BOLD}Install /wiki skill for Claude Code?${NC}"
echo "This copies wiki.md to your project's .claude/commands/ directory."
read -p "Project path (or 'skip'): " project_path
if [ "$project_path" != "skip" ] && [ -n "$project_path" ]; then
project_path="${project_path/#\~/$HOME}"
COMMANDS_DIR="$project_path/.claude/commands"
mkdir -p "$COMMANDS_DIR"
cp "$SCRIPT_DIR/wiki.md" "$COMMANDS_DIR/wiki.md"
# Patch config path into skill
if [ "$(uname)" = "Darwin" ]; then
sed -i '' "s|<CONFIG_PATH>|$CONFIG_FILE|g" "$COMMANDS_DIR/wiki.md"
else
sed -i "s|<CONFIG_PATH>|$CONFIG_FILE|g" "$COMMANDS_DIR/wiki.md"
fi
echo -e "${GREEN}Installed /wiki skill to $COMMANDS_DIR/wiki.md${NC}"
fi
# ----- Step 11: Initial commit -----
if [ -d "$wiki_path/.git" ]; then
echo ""
cd "$wiki_path"
git add -A
git commit -m "wiki: initial setup via llm-wiki
Schema, Dashboard, and hub pages for $(echo $NAMESPACES | wc -w | tr -d ' ') namespaces.
Tool: $TOOL
Generated by https://github.com/MehmetGoekce/llm-wiki" 2>/dev/null || true
echo -e "${GREEN}Initial commit created.${NC}"
fi
# ----- Done -----
echo ""
echo -e "${CYAN}${BOLD}Setup complete!${NC}"
echo ""
echo -e "Your wiki is at: ${BOLD}$wiki_path${NC}"
echo -e "Config file: ${BOLD}$CONFIG_FILE${NC}"
echo ""
echo -e "Next steps:"
echo -e " 1. Open your wiki in $TOOL"
echo -e " 2. In Claude Code, try: ${CYAN}/wiki ingest \"your first source\"${NC}"
echo -e " 3. Run ${CYAN}/wiki status${NC} to see your wiki metrics"
echo ""
echo -e "Documentation: ${CYAN}https://github.com/MehmetGoekce/llm-wiki${NC}"