-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-knowledge.sh
More file actions
executable file
·114 lines (99 loc) · 2.11 KB
/
Copy pathsetup-knowledge.sh
File metadata and controls
executable file
·114 lines (99 loc) · 2.11 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
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage:
setup-knowledge.sh --personal <dir> --shared <dir> [--settings <file>]
Creates starter OKF bundle directories and prints an MCP server config.
If --settings is provided, the MCP server entry is merged into that JSON file
when jq is available. Otherwise the config is printed only.
EOF
}
personal=""
shared=""
settings=""
while [[ $# -gt 0 ]]; do
case "$1" in
--personal)
personal="$2"
shift 2
;;
--shared)
shared="$2"
shift 2
;;
--settings)
settings="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage
exit 1
;;
esac
done
if [[ -z "$personal" || -z "$shared" ]]; then
usage
exit 1
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
server_path="$script_dir/mcp-server.mjs"
mkdir -p "$personal/scratch" "$personal/drafts" "$shared/decisions" "$shared/systems" "$shared/runbooks"
write_index() {
local file="$1"
local title="$2"
if [[ ! -f "$file" ]]; then
cat > "$file" <<EOF
---
type: index
title: $title
---
# $title
EOF
fi
}
write_index "$personal/index.md" "Personal Knowledge Index"
write_index "$shared/index.md" "Shared Knowledge Index"
config="$(cat <<EOF
{
"mcpServers": {
"contextcake": {
"command": "node",
"args": [
"$server_path",
"--personal",
"$personal",
"--shared",
"$shared"
]
}
}
}
EOF
)"
if [[ -n "$settings" ]]; then
if ! command -v jq >/dev/null 2>&1; then
echo "jq is required to merge --settings. Config to add:" >&2
echo "$config"
exit 1
fi
mkdir -p "$(dirname "$settings")"
if [[ ! -f "$settings" ]]; then
echo '{}' > "$settings"
fi
tmp="$(mktemp)"
jq --arg server "$server_path" --arg personal "$personal" --arg shared "$shared" \
'.mcpServers["contextcake"] = {
"command": "node",
"args": [$server, "--personal", $personal, "--shared", $shared]
}' "$settings" > "$tmp"
mv "$tmp" "$settings"
echo "Updated $settings"
else
echo "$config"
fi