-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·691 lines (591 loc) · 18.9 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·691 lines (591 loc) · 18.9 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
#!/usr/bin/env bash
# Copyright (C) 2026 Gregory R. Warnes
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# This file is part of Oboe MCP.
# For commercial licensing, contact greg@warnes-innovations.com
set -euo pipefail
BLUE='\033[0;34m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_SOURCE="$SCRIPT_DIR"
TIMESTAMP="$(date +%Y%m%d_%H%M%S)"
SELECTED_TOOLS=()
INSTALL_SCOPE=""
PROJECT_DIR=""
UPDATED_PATHS=()
DEV_MODE=false
print_header() {
echo -e "${BLUE}oboe-mcp installer${NC}"
echo "================="
echo ""
echo "This script installs the oboe-mcp MCP server from the current checkout:"
echo " $REPO_SOURCE"
echo ""
echo "It will ask which clients you use, wire oboe-mcp into their MCP config,"
echo "and install the packaged workflow instructions into the right place."
echo ""
}
detect_vscode_user_dir() {
case "$(uname -s)" in
Darwin*) echo "$HOME/Library/Application Support/Code/User" ;;
Linux*) echo "$HOME/.config/Code/User" ;;
CYGWIN*|MINGW*|MSYS*) echo "$HOME/AppData/Roaming/Code/User" ;;
*)
echo -e "${RED}Unsupported operating system: $(uname -s)${NC}" >&2
exit 1
;;
esac
}
detect_cline_settings_path() {
case "$(uname -s)" in
Darwin*) echo "$HOME/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json" ;;
Linux*) echo "$HOME/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json" ;;
CYGWIN*|MINGW*|MSYS*) echo "$HOME/AppData/Roaming/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json" ;;
*)
echo -e "${RED}Unsupported operating system: $(uname -s)${NC}" >&2
exit 1
;;
esac
}
say() {
echo -e "${BLUE}$1${NC}"
}
warn() {
echo -e "${YELLOW}$1${NC}"
}
success() {
echo -e "${GREEN}$1${NC}"
}
require_command() {
local command_name="$1"
if ! command -v "$command_name" >/dev/null 2>&1; then
echo -e "${RED}Missing required command: $command_name${NC}" >&2
exit 1
fi
}
ensure_dir() {
local dir_path="$1"
mkdir -p "$dir_path"
}
record_path() {
UPDATED_PATHS+=("$1")
}
backup_file() {
local file_path="$1"
if [ -f "$file_path" ]; then
local backup_path="${file_path}.bak.${TIMESTAMP}"
cp "$file_path" "$backup_path"
warn "Backed up $file_path to $backup_path"
fi
}
copy_with_backup() {
local source_path="$1"
local target_path="$2"
ensure_dir "$(dirname "$target_path")"
if [ -f "$target_path" ] && cmp -s "$source_path" "$target_path"; then
success "Up to date: $target_path"
return 0
fi
if [ -f "$target_path" ]; then
backup_file "$target_path"
fi
cp "$source_path" "$target_path"
success "Installed $target_path"
record_path "$target_path"
}
merge_markdown_block() {
local source_path="$1"
local target_path="$2"
local start_marker="$3"
local end_marker="$4"
local temp_output
ensure_dir "$(dirname "$target_path")"
temp_output="$(mktemp)"
python3 - "$source_path" "$target_path" "$start_marker" "$end_marker" > "$temp_output" <<'PY'
from pathlib import Path
import re
import sys
source_path, target_path, start_marker, end_marker = sys.argv[1:5]
source_text = Path(source_path).read_text()
target = Path(target_path)
target_text = target.read_text() if target.exists() else ""
block = f"{start_marker}\n{source_text.rstrip()}\n{end_marker}\n"
pattern = re.compile(re.escape(start_marker) + r".*?" + re.escape(end_marker) + r"\n?", re.S)
if pattern.search(target_text):
updated = pattern.sub(block, target_text, count=1)
elif target_text.strip():
updated = target_text.rstrip() + "\n\n" + block
else:
updated = block
sys.stdout.write(updated)
PY
if [ -f "$target_path" ] && cmp -s "$temp_output" "$target_path"; then
rm -f "$temp_output"
success "Up to date: $target_path"
return 0
fi
if [ -f "$target_path" ]; then
backup_file "$target_path"
fi
mv "$temp_output" "$target_path"
success "Merged OBO instructions into $target_path"
record_path "$target_path"
}
merge_vscode_mcp_server() {
local target_path="$1"
local real_path
local temp_output
# Resolve symlink so we write to the real file and don't replace the symlink
real_path="$(python3 -c "import os,sys; p=sys.argv[1]; print(os.path.realpath(p))" "$target_path" 2>/dev/null || echo "")"
if [[ -z "$real_path" ]]; then
real_path="$target_path"
fi
ensure_dir "$(dirname "$real_path")"
temp_output="$(mktemp)"
python3 - "$real_path" "$REPO_SOURCE" "$DEV_MODE" > "$temp_output" <<'PY'
import json
from pathlib import Path
import sys
target_path = Path(sys.argv[1])
repo_source = sys.argv[2]
dev_mode = sys.argv[3] == "true"
if target_path.exists():
data = json.loads(target_path.read_text())
else:
data = {}
servers = data.get("servers")
if not isinstance(servers, dict):
servers = {}
if dev_mode:
servers["oboe-mcp"] = {
"type": "stdio",
"command": "uv",
"args": ["run", "--directory", repo_source, "oboe-mcp"],
}
else:
servers["oboe-mcp"] = {
"type": "stdio",
"command": "uvx",
"args": ["--from", "git+https://github.com/warnes-innovations/oboe-mcp", "oboe-mcp"],
}
data["servers"] = servers
if "inputs" not in data or not isinstance(data["inputs"], list):
data["inputs"] = []
sys.stdout.write(json.dumps(data, indent=2) + "\n")
PY
if [ -f "$real_path" ] && cmp -s "$temp_output" "$real_path"; then
rm -f "$temp_output"
success "Up to date: $real_path"
return 0
fi
if [ -f "$real_path" ]; then
backup_file "$real_path"
fi
mv "$temp_output" "$real_path"
success "Updated VS Code MCP config at $real_path"
record_path "$real_path"
}
merge_json_mcp_server() {
local target_path="$1"
local root_key="$2"
local temp_output
ensure_dir "$(dirname "$target_path")"
temp_output="$(mktemp)"
python3 - "$target_path" "$root_key" "$REPO_SOURCE" "$DEV_MODE" > "$temp_output" <<'PY'
import json
from pathlib import Path
import sys
target_path = Path(sys.argv[1])
root_key = sys.argv[2]
repo_source = sys.argv[3]
dev_mode = sys.argv[4] == "true"
if target_path.exists():
data = json.loads(target_path.read_text())
else:
data = {}
bucket = data.get(root_key)
if not isinstance(bucket, dict):
bucket = {}
if dev_mode:
bucket["oboe-mcp"] = {
"type": "stdio",
"command": "uv",
"args": ["run", "--directory", repo_source, "oboe-mcp"],
}
else:
bucket["oboe-mcp"] = {
"type": "stdio",
"command": "uvx",
"args": ["--from", "git+https://github.com/warnes-innovations/oboe-mcp", "oboe-mcp"],
}
data[root_key] = bucket
sys.stdout.write(json.dumps(data, indent=2) + "\n")
PY
if [ -f "$target_path" ] && cmp -s "$temp_output" "$target_path"; then
rm -f "$temp_output"
success "Up to date: $target_path"
return 0
fi
if [ -f "$target_path" ]; then
backup_file "$target_path"
fi
mv "$temp_output" "$target_path"
success "Updated $target_path"
record_path "$target_path"
}
merge_codex_config() {
local target_path="$1"
local temp_output
ensure_dir "$(dirname "$target_path")"
temp_output="$(mktemp)"
python3 - "$target_path" "$REPO_SOURCE" "$DEV_MODE" > "$temp_output" <<'PY'
from pathlib import Path
import re
import sys
target_path = Path(sys.argv[1])
repo_source = sys.argv[2]
dev_mode = sys.argv[3] == "true"
if dev_mode:
block = (
'[mcp_servers.oboe-mcp]\n'
'command = "uv"\n'
f'args = ["run", "--directory", "{repo_source}", "oboe-mcp"]\n'
)
else:
block = (
'[mcp_servers.oboe-mcp]\n'
'command = "uvx"\n'
'args = ["--from", "git+https://github.com/warnes-innovations/oboe-mcp", "oboe-mcp"]\n'
)
text = target_path.read_text() if target_path.exists() else ""
pattern = re.compile(r'^\[mcp_servers\.oboe-mcp\]\n(?:^(?!\[).*$\n?)*', re.M)
if pattern.search(text):
updated = pattern.sub(block, text, count=1)
elif text.strip():
updated = text.rstrip() + "\n\n" + block
else:
updated = block
sys.stdout.write(updated)
PY
if [ -f "$target_path" ] && cmp -s "$temp_output" "$target_path"; then
rm -f "$temp_output"
success "Up to date: $target_path"
return 0
fi
if [ -f "$target_path" ]; then
backup_file "$target_path"
fi
mv "$temp_output" "$target_path"
success "Updated Codex MCP config at $target_path"
record_path "$target_path"
}
has_tool() {
local requested="$1"
local tool_name
for tool_name in "${SELECTED_TOOLS[@]}"; do
if [ "$tool_name" = "$requested" ]; then
return 0
fi
done
return 1
}
prompt_tools() {
local selection
local token
echo "Choose the client(s) you want to configure:"
echo " 1) GitHub Copilot"
echo " 2) Codex"
echo " 3) Claude Code"
echo " 4) Cline"
echo " 5) All of the above"
echo ""
read -r -p "Enter a comma-separated list (for example 1,3 or 5): " selection
selection="${selection// /}"
if [ -z "$selection" ] || [ "$selection" = "5" ] || [ "$selection" = "all" ] || [ "$selection" = "ALL" ]; then
SELECTED_TOOLS=("copilot" "codex" "claude" "cline")
return
fi
IFS=',' read -r -a raw_tokens <<< "$selection"
for token in "${raw_tokens[@]}"; do
case "$token" in
1|copilot|Copilot) SELECTED_TOOLS+=("copilot") ;;
2|codex|Codex) SELECTED_TOOLS+=("codex") ;;
3|claude|Claude) SELECTED_TOOLS+=("claude") ;;
4|cline|Cline) SELECTED_TOOLS+=("cline") ;;
*)
echo -e "${RED}Unrecognized selection: $token${NC}" >&2
exit 1
;;
esac
done
if [ "${#SELECTED_TOOLS[@]}" -eq 0 ]; then
echo -e "${RED}No tools selected.${NC}" >&2
exit 1
fi
}
prompt_scope() {
local selection
echo ""
echo "Choose where to install workflow instructions:"
echo " 1) User-level, when the client supports shared instructions"
echo " 2) Project-level in a target repository"
echo ""
echo "Codex, Claude Code, and Cline still use project files for workflow guidance,"
echo "so the script will ask for a project directory if you select them."
echo ""
read -r -p "Enter 1 or 2 [2]: " selection
selection="${selection:-2}"
case "$selection" in
1) INSTALL_SCOPE="user" ;;
2) INSTALL_SCOPE="project" ;;
*)
echo -e "${RED}Invalid scope selection: $selection${NC}" >&2
exit 1
;;
esac
}
needs_project_dir() {
if [ "$INSTALL_SCOPE" = "project" ]; then
return 0
fi
has_tool "codex" && return 0
has_tool "claude" && return 0
has_tool "cline" && return 0
return 1
}
prompt_project_dir() {
local input_path
echo ""
read -r -p "Enter the target project directory for repo-scoped instruction files: " input_path
if [ -z "$input_path" ]; then
echo -e "${RED}A project directory is required for this selection.${NC}" >&2
exit 1
fi
# Expand ~ to $HOME
input_path="${input_path/#\~/$HOME}"
if [ ! -d "$input_path" ]; then
echo -e "${RED}Directory does not exist: $input_path${NC}" >&2
exit 1
fi
PROJECT_DIR="$(cd "$input_path" && pwd)"
}
copilot_instruction_target() {
local vscode_user_dir
vscode_user_dir="$(detect_vscode_user_dir)"
if [ "$INSTALL_SCOPE" = "user" ]; then
echo "$vscode_user_dir/copilot-instructions.md"
else
echo "$PROJECT_DIR/.github/copilot-instructions.md"
fi
}
copilot_skill_target() {
local vscode_user_dir
vscode_user_dir="$(detect_vscode_user_dir)"
if [ "$INSTALL_SCOPE" = "user" ]; then
echo "$vscode_user_dir/skills/one-by-one/SKILL.md"
else
echo "$PROJECT_DIR/.github/skills/one-by-one/SKILL.md"
fi
}
copilot_prompt_target() {
local vscode_user_dir
vscode_user_dir="$(detect_vscode_user_dir)"
if [ "$INSTALL_SCOPE" = "user" ]; then
echo "$vscode_user_dir/prompts/obo.prompt.md"
else
echo "$PROJECT_DIR/.github/prompts/obo.prompt.md"
fi
}
copilot_release_instruction_target() {
local vscode_user_dir
vscode_user_dir="$(detect_vscode_user_dir)"
if [ "$INSTALL_SCOPE" = "user" ]; then
echo "$vscode_user_dir/instructions/release-workflow.instructions.md"
else
echo "$PROJECT_DIR/.github/instructions/release-workflow.instructions.md"
fi
}
claude_instruction_target() {
if [ -f "$PROJECT_DIR/.claude/CLAUDE.md" ] || [ -d "$PROJECT_DIR/.claude" ]; then
echo "$PROJECT_DIR/.claude/CLAUDE.md"
else
echo "$PROJECT_DIR/CLAUDE.md"
fi
}
install_copilot() {
local vscode_user_dir
local instruction_target
local skill_target
local prompt_target
local release_instruction_target
say "Installing GitHub Copilot configuration"
vscode_user_dir="$(detect_vscode_user_dir)"
merge_vscode_mcp_server "$vscode_user_dir/mcp.json"
instruction_target="$(copilot_instruction_target)"
skill_target="$(copilot_skill_target)"
prompt_target="$(copilot_prompt_target)"
release_instruction_target="$(copilot_release_instruction_target)"
merge_markdown_block \
"$SCRIPT_DIR/templates/agent-setup/copilot/copilot-instructions.md" \
"$instruction_target" \
"<!-- oboe-mcp:start -->" \
"<!-- oboe-mcp:end -->"
copy_with_backup \
"$SCRIPT_DIR/templates/agent-setup/copilot/skills/one-by-one/SKILL.md" \
"$skill_target"
copy_with_backup \
"$SCRIPT_DIR/templates/agent-setup/copilot/prompts/obo.prompt.md" \
"$prompt_target"
copy_with_backup \
"$SCRIPT_DIR/templates/agent-setup/copilot/instructions/release-workflow.instructions.md" \
"$release_instruction_target"
echo ""
}
install_codex() {
local codex_config="$HOME/.codex/config.toml"
local agents_target="$PROJECT_DIR/AGENTS.md"
say "Installing Codex configuration"
merge_codex_config "$codex_config"
merge_markdown_block \
"$SCRIPT_DIR/templates/agent-setup/AGENTS.md" \
"$agents_target" \
"<!-- oboe-mcp:start -->" \
"<!-- oboe-mcp:end -->"
echo ""
}
install_claude() {
local claude_config="$HOME/.claude/settings.json"
local claude_target
say "Installing Claude Code configuration"
merge_json_mcp_server "$claude_config" "mcpServers"
claude_target="$(claude_instruction_target)"
merge_markdown_block \
"$SCRIPT_DIR/templates/agent-setup/CLAUDE.md" \
"$claude_target" \
"<!-- oboe-mcp:start -->" \
"<!-- oboe-mcp:end -->"
echo ""
}
install_cline() {
local cline_config
local cline_rules_target="$PROJECT_DIR/.clinerules"
say "Installing Cline configuration"
cline_config="$(detect_cline_settings_path)"
merge_json_mcp_server "$cline_config" "mcpServers"
merge_markdown_block \
"$SCRIPT_DIR/templates/agent-setup/AGENTS.md" \
"$cline_rules_target" \
"<!-- oboe-mcp:start -->" \
"<!-- oboe-mcp:end -->"
echo ""
}
print_plan() {
echo "Selected clients: ${SELECTED_TOOLS[*]}"
echo "Instruction scope: $INSTALL_SCOPE"
if [ -n "$PROJECT_DIR" ]; then
echo "Project directory: $PROJECT_DIR"
fi
echo ""
if $DEV_MODE; then
echo "The MCP server entries will run from this local checkout:"
echo " uv run --directory $REPO_SOURCE oboe-mcp"
else
echo "The MCP server entries will use the published GitHub release:"
echo " uvx --from git+https://github.com/warnes-innovations/oboe-mcp oboe-mcp"
fi
echo ""
echo "Installing oboe-mcp also installs the oboe-cli command-line tool."
echo "After installation you can run:"
echo " oboe-cli --help"
echo ""
}
print_summary() {
local updated_path
echo "Installation complete."
echo ""
if [ "${#UPDATED_PATHS[@]}" -gt 0 ]; then
echo "Updated files:"
for updated_path in "${UPDATED_PATHS[@]}"; do
echo " - $updated_path"
done
echo ""
fi
echo "The oboe-cli command is installed alongside oboe-mcp and provides"
echo "a human-friendly CLI for the same session files the MCP tools operate on."
echo "Run 'oboe-cli --help' to see all available commands."
echo ""
if $DEV_MODE; then
echo "MCP is configured for local dev (edits reflected immediately)."
echo "Run ./install.sh (without --dev) to switch to the published GitHub release."
else
echo "MCP is configured for the published GitHub release."
echo "Run ./install.sh --dev to use the local checkout instead."
fi
}
main() {
require_command python3
print_header
prompt_tools
prompt_scope
if needs_project_dir; then
prompt_project_dir
fi
print_plan
has_tool "copilot" && install_copilot
has_tool "codex" && install_codex
has_tool "claude" && install_claude
has_tool "cline" && install_cline
print_summary
}
# ------------------------------------------------------------------
# Parse flags (main() prompts interactively for remaining choices)
# ------------------------------------------------------------------
while [[ $# -gt 0 ]]; do
case "$1" in
--dev) DEV_MODE=true ;;
-h|--help)
echo "Usage: $0 [--dev]"
echo " --dev Use local repo (uv run --directory) instead of published GitHub URL."
echo " If MCP is on dev and --dev is omitted, prompts to switch to published."
exit 0
;;
*)
echo "Unknown argument: $1" >&2
exit 1
;;
esac
shift
done
# ------------------------------------------------------------------
# If VS Code MCP is currently on dev and --dev not given, prompt to revert
# ------------------------------------------------------------------
_VSCODE_USER_MCP="$(detect_vscode_user_dir)/mcp.json"
if ! $DEV_MODE; then
_CURRENT_MODE="$(python3 - "$_VSCODE_USER_MCP" <<'PYEOF'
import json, os, sys
path = os.path.realpath(sys.argv[1]) if os.path.exists(sys.argv[1]) else ""
if not path:
print("unknown")
sys.exit(0)
try:
cfg = json.load(open(path))
entry = cfg.get("servers", {}).get("oboe-mcp", {})
print("dev" if entry.get("command") == "uv" else "published")
except Exception:
print("unknown")
PYEOF
)"
if [[ "$_CURRENT_MODE" == "dev" ]]; then
echo "MCP is currently configured for local dev."
read -r -p "Switch to published (uvx from GitHub)? [y/N]: " _MCP_CHOICE
case "${_MCP_CHOICE,,}" in
y|yes) ;; # DEV_MODE stays false → merge writes published config
*) DEV_MODE=true ;; # keep dev
esac
fi
fi
main