-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·654 lines (568 loc) · 16.5 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·654 lines (568 loc) · 16.5 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
#!/bin/bash
# deploy.sh — copy agent-contexts templates to a target repository
#
# Usage:
# ./deploy.sh --agents <claude|copilot|cursor|devin|windsurf|all> [target-repo]
#
# If --agents is omitted in an interactive terminal, an arrow-key multiselect
# prompt is shown.
set -euo pipefail
VALID_AGENTS=(claude copilot cursor devin windsurf)
SELECTED_AGENTS=()
ENABLED_AGENTS=()
TARGET=""
AGENTS_FLAG_PROVIDED=0
OVERWRITE_MODE="" # "all" | "none" | "" (prompt per-file)
OVERWRITE_FLAG=0
NO_OVERWRITE_FLAG=0
SKIPPED_FILES=()
usage() {
cat <<EOF
Usage: ./deploy.sh --agents <agent ...|all> [target-repo]
Copy agent-contexts templates to a target repository and generate skill wrappers.
If [target-repo] is omitted, deploys to the current directory.
Shared content (always copied):
AGENTS.md → target repo root
.context/ → target .context/ (index + conventions)
standards/ → target .context/standards/
playbooks/ → target .context/playbooks/
Agent-specific files (copied only for selected agents):
claude → CLAUDE.md, .claude/settings.json, .claude/skills/
copilot → .github/copilot-instructions.md, .github/skills/
cursor → .cursor/rules/standards.mdc
devin → .devin/devin.json
windsurf → .windsurfrules
all → all of the above
Options:
--agents Mandatory in non-interactive mode. Supports one or more values:
claude copilot cursor devin windsurf all
--overwrite Overwrite all existing files without prompting
--no-overwrite Skip all existing files without prompting
Default: prompt per-file when conflicts are detected
-h, --help Show this help message and exit
EOF
}
print_banner() {
local c1=$'\033[38;5;39m'
local c2=$'\033[38;5;45m'
local c3=$'\033[38;5;51m'
local c4=$'\033[38;5;220m'
local c_link=$'\033[38;5;81m'
local c_name=$'\033[38;5;213m'
local reset=$'\033[0m'
local repo_url="https://github.com/ldastey-dev/agentic-context"
printf "%b\n" "${c1} __${reset}"
printf "%b\n" "${c2} _(\\\\ |@@|${reset}"
printf "%b\n" "${c3}(__/\\\\__ \\\\--/ __${reset}"
printf "%b\n" "${c1} \\\\___|----| | __${reset}"
printf "%b\n" "${c2} \\\\ }{ /\\\\ )_ / _\\\\${reset}"
printf "%b\n" "${c3} /\\\\__/\\\\ \\\\__O (__${reset}"
printf "%b\n" "${c1} (--/\\\\--) \\\\__/${reset}"
printf "%b\n" "${c2} _)( )(_${reset}"
printf "%b\n" "${c3} \`---''---\`${reset}"
printf "%b\n" "${c4}A comprehensive list of engineering standards for context engineering with AI Agents${reset}"
if [[ -t 1 && "${TERM:-}" != "dumb" ]]; then
printf "%b\033]8;;%s\a%s\033]8;;\a%b\n" "$c_link" "$repo_url" "$repo_url" "$reset"
else
printf "%b%s%b\n" "$c_link" "$repo_url" "$reset"
fi
printf "%b%s%b\n\n" "$c_name" "Written by Leigh Dastey" "$reset"
}
join_by() {
local delimiter="$1"
shift
local first=1
local value
for value in "$@"; do
if [[ $first -eq 1 ]]; then
printf "%s" "$value"
first=0
else
printf "%s%s" "$delimiter" "$value"
fi
done
}
agent_enabled() {
local sought="$1"
local agent
for agent in "${ENABLED_AGENTS[@]}"; do
if [[ "$agent" == "$sought" ]]; then
return 0
fi
done
return 1
}
confirm_overwrite() {
local dst="$1"
# New files always proceed
if [[ ! -e "$dst" ]]; then
return 0
fi
case "$OVERWRITE_MODE" in
all) return 0 ;;
none)
SKIPPED_FILES+=("$dst")
return 1
;;
esac
# Non-interactive without explicit flag → safe default (skip)
if [[ ! -t 0 || ! -t 1 ]]; then
echo " Skipping existing file (non-interactive): $dst"
SKIPPED_FILES+=("$dst")
return 1
fi
while true; do
printf " File already exists: %s\n" "$dst"
printf " Overwrite? [y]es / [n]o / [N]o to all / [a]ll: "
read -r answer
case "$answer" in
y) return 0 ;;
n) SKIPPED_FILES+=("$dst"); return 1 ;;
N) OVERWRITE_MODE="none"; SKIPPED_FILES+=("$dst"); return 1 ;;
a) OVERWRITE_MODE="all"; return 0 ;;
*) echo " Please enter y, n, N, or a." ;;
esac
done
}
copy_file() {
local src="$1"
local dst="$2"
if ! confirm_overwrite "$dst"; then
return 0
fi
mkdir -p "$(dirname "$dst")"
cp "$src" "$dst"
}
copy_dir_contents() {
local src="$1"
local dst="$2"
local rel_path file_dst
while IFS= read -r -d '' file; do
rel_path="${file#"$src"/}"
file_dst="$dst/$rel_path"
copy_file "$file" "$file_dst"
done < <(find "$src" -type f -print0 | sort -z)
}
interactive_select_agents() {
local options=(all "${VALID_AGENTS[@]}" "clear and exit")
local options_count=${#options[@]}
local exit_index=$((options_count - 1))
local -a selected=()
local cursor=0
local key seq1 seq2 i
local colour_green=$'\033[32m'
local colour_reset=$'\033[0m'
local status_msg=""
local first_render=1
for ((i=0; i<options_count; i++)); do
selected[$i]=0
done
render_menu() {
local idx pointer marker label line
if [[ $first_render -eq 0 ]]; then
printf "\033[%dA" "$((options_count + 1))"
fi
for idx in "${!options[@]}"; do
pointer=" "
marker="[ ]"
label="${options[$idx]}"
[[ $idx -eq $cursor ]] && pointer="> "
if [[ ${selected[$idx]} -eq 1 ]]; then
marker="[x]"
fi
line=$(printf "%s%s %s" "$pointer" "$marker" "$label")
if [[ $idx -eq $cursor ]]; then
printf "\r\033[2K%b%s%b\n" "$colour_green" "$line" "$colour_reset"
else
printf "\r\033[2K%s\n" "$line"
fi
done
printf "\r\033[2K%s\n" "$status_msg"
first_render=0
}
restore_cursor() {
printf "\033[?25h"
}
printf "\033[?25l"
echo "Select one or more agents (space to toggle, ↑/↓ to move, Enter to confirm)."
echo "Select 'all' to deploy every supported agent."
echo "Select 'clear and exit' to clear selection and quit."
echo
render_menu
while true; do
key=""
sequence=""
IFS= read -rsn1 key || true
if [[ "$key" == $'\x1b' ]]; then
IFS= read -rsn1 -t 1 seq1 || true
if [[ "$seq1" == "[" ]]; then
IFS= read -rsn1 -t 1 seq2 || true
key+="$seq1$seq2"
else
key+="$seq1"
fi
case "$key" in
$'\x1b[A') cursor=$(( (cursor - 1 + options_count) % options_count )) ;;
$'\x1b[B') cursor=$(( (cursor + 1) % options_count )) ;;
esac
status_msg=""
render_menu
continue
fi
case "$key" in
" ")
if [[ $cursor -eq $exit_index ]]; then
if [[ ${selected[$cursor]} -eq 1 ]]; then
selected[$cursor]=0
status_msg=""
else
for i in "${!selected[@]}"; do
selected[$i]=0
done
selected[$cursor]=1
status_msg="Press Enter to clear selections and exit."
fi
elif [[ "${options[$cursor]}" == "all" ]]; then
if [[ ${selected[$cursor]} -eq 1 ]]; then
for ((i=0; i<exit_index; i++)); do
selected[$i]=0
done
else
for ((i=0; i<exit_index; i++)); do
selected[$i]=1
done
fi
selected[$exit_index]=0
status_msg=""
else
if [[ ${selected[$cursor]} -eq 1 ]]; then
selected[$cursor]=0
else
selected[$cursor]=1
fi
selected[$exit_index]=0
selected[0]=1
for ((i=1; i<exit_index; i++)); do
if [[ ${selected[$i]} -eq 0 ]]; then
selected[0]=0
break
fi
done
status_msg=""
fi
render_menu
;;
$'\n'|$'\r'|"")
if [[ $cursor -eq $exit_index ]]; then
for i in "${!selected[@]}"; do
selected[$i]=0
done
SELECTED_AGENTS=()
status_msg=""
render_menu
restore_cursor
echo "Selection cleared. Exiting."
return 2
fi
local chosen=()
for i in "${!options[@]}"; do
if [[ $i -eq $exit_index ]]; then
continue
fi
if [[ ${selected[$i]} -eq 1 ]]; then
chosen+=("${options[$i]}")
fi
done
if [[ ${#chosen[@]} -eq 0 ]]; then
status_msg="Select at least one option."
render_menu
continue
fi
SELECTED_AGENTS=("${chosen[@]}")
restore_cursor
return 0
;;
*)
status_msg=""
render_menu
;;
esac
done
}
normalise_agents() {
local seen=""
local agent
for agent in "${SELECTED_AGENTS[@]}"; do
case "$agent" in
all)
ENABLED_AGENTS=("${VALID_AGENTS[@]}")
return 0
;;
claude|copilot|cursor|devin|windsurf)
case ",$seen," in
*",$agent,"*)
;;
*)
ENABLED_AGENTS+=("$agent")
seen="${seen:+$seen,}$agent"
;;
esac
;;
*)
echo "Error: unsupported agent '$agent'." >&2
echo "Supported agents: all, $(join_by ', ' "${VALID_AGENTS[@]}")" >&2
exit 1
;;
esac
done
if [[ ${#ENABLED_AGENTS[@]} -eq 0 ]]; then
echo "Error: at least one agent must be selected." >&2
exit 1
fi
}
generate_skill() {
local playbook_path="$1"
local target_dir="$2"
local rel_path="$3"
local allowed_tools="${4:-}"
local name description
name=$(sed -n 's/^name: *//p' "$playbook_path" | head -1)
description=$(sed -n 's/^description: *//p' "$playbook_path" | head -1 | sed 's/^"//;s/"$//')
if [[ -z "$name" || -z "$description" ]]; then
return
fi
local skill_dir="$target_dir/$name"
local skill_file="$skill_dir/SKILL.md"
if ! confirm_overwrite "$skill_file"; then
return
fi
mkdir -p "$skill_dir"
if [[ -n "$allowed_tools" ]]; then
cat > "$skill_file" << SKILL_EOF
---
name: $name
description: "$description"
allowed-tools: "$allowed_tools"
---
Read and follow \`.context/playbooks/$rel_path\` in full.
SKILL_EOF
else
cat > "$skill_file" << SKILL_EOF
---
name: $name
description: "$description"
---
Read and follow \`.context/playbooks/$rel_path\` in full.
SKILL_EOF
fi
}
generate_skills_for_selected_agents() {
local playbook_path="$1"
local rel_path="$2"
local allowed_tools="${3:-Read, Grep, Glob, Bash(git *), Write, Edit, Agent}"
if agent_enabled claude; then
generate_skill "$playbook_path" "$TARGET/.claude/skills" "$rel_path" "$allowed_tools"
fi
if agent_enabled copilot; then
generate_skill "$playbook_path" "$TARGET/.github/skills" "$rel_path" ""
fi
}
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
--agents)
if [[ $AGENTS_FLAG_PROVIDED -eq 1 ]]; then
echo "Error: --agents provided more than once." >&2
exit 1
fi
AGENTS_FLAG_PROVIDED=1
shift
while [[ $# -gt 0 ]]; do
case "$1" in
all|claude|copilot|cursor|devin|windsurf)
SELECTED_AGENTS+=("$1")
shift
;;
--*)
break
;;
*)
break
;;
esac
done
if [[ ${#SELECTED_AGENTS[@]} -eq 0 ]]; then
echo "Error: --agents requires at least one value." >&2
usage >&2
exit 1
fi
;;
--overwrite)
OVERWRITE_MODE="all"
OVERWRITE_FLAG=1
shift
;;
--no-overwrite)
OVERWRITE_MODE="none"
NO_OVERWRITE_FLAG=1
shift
;;
--*)
echo "Error: unknown option '$1'" >&2
echo "" >&2
usage >&2
exit 1
;;
*)
if [[ -z "$TARGET" ]]; then
TARGET="$1"
else
echo "Error: unexpected argument '$1'" >&2
usage >&2
exit 1
fi
shift
;;
esac
done
if [[ $OVERWRITE_FLAG -eq 1 && $NO_OVERWRITE_FLAG -eq 1 ]]; then
echo "Error: --overwrite and --no-overwrite are mutually exclusive." >&2
exit 1
fi
print_banner
if [[ $AGENTS_FLAG_PROVIDED -eq 0 ]]; then
if [[ -t 0 && -t 1 ]]; then
if interactive_select_agents; then
:
else
selector_status=$?
if [[ $selector_status -eq 2 ]]; then
exit 0
fi
exit "$selector_status"
fi
else
echo "Error: --agents is mandatory in non-interactive mode." >&2
usage >&2
exit 1
fi
fi
normalise_agents
if [[ -z "$TARGET" ]]; then
TARGET="."
fi
if [[ ! -d "$TARGET" ]]; then
printf "Directory '%s' does not exist. Create it? [y/N] " "$TARGET"
read -r answer
case "$answer" in
[yY]|[yY][eE][sS])
mkdir -p "$TARGET"
echo "Created '$TARGET'"
;;
*)
echo "Aborted." >&2
exit 1
;;
esac
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "Deploying agent-contexts to $TARGET"
echo " Selected agents: $(join_by ', ' "${ENABLED_AGENTS[@]}")"
echo " Copying shared context files..."
copy_file "$SCRIPT_DIR/core/AGENTS.md" "$TARGET/AGENTS.md"
copy_dir_contents "$SCRIPT_DIR/core/.context" "$TARGET/.context"
if agent_enabled claude; then
echo " Copying Claude Code files..."
copy_file "$SCRIPT_DIR/core/CLAUDE.md" "$TARGET/CLAUDE.md"
copy_file "$SCRIPT_DIR/core/.claude/settings.json" "$TARGET/.claude/settings.json"
fi
if agent_enabled copilot; then
echo " Copying GitHub Copilot files..."
copy_file "$SCRIPT_DIR/core/.github/copilot-instructions.md" "$TARGET/.github/copilot-instructions.md"
fi
if agent_enabled cursor; then
echo " Copying Cursor files..."
copy_file "$SCRIPT_DIR/core/.cursor/rules/standards.mdc" "$TARGET/.cursor/rules/standards.mdc"
fi
if agent_enabled devin; then
echo " Copying Devin files..."
copy_file "$SCRIPT_DIR/core/.devin/devin.json" "$TARGET/.devin/devin.json"
fi
if agent_enabled windsurf; then
echo " Copying Windsurf files..."
copy_file "$SCRIPT_DIR/core/.windsurfrules" "$TARGET/.windsurfrules"
fi
echo " Copying standards/ → $TARGET/.context/standards/"
copy_dir_contents "$SCRIPT_DIR/standards" "$TARGET/.context/standards"
echo " Copying playbooks/ → $TARGET/.context/playbooks/"
copy_dir_contents "$SCRIPT_DIR/playbooks" "$TARGET/.context/playbooks"
if agent_enabled claude || agent_enabled copilot; then
echo " Generating skill wrappers from playbooks..."
if agent_enabled claude; then
echo " → .claude/skills/ (Claude Code)"
mkdir -p "$TARGET/.claude/skills"
fi
if agent_enabled copilot; then
echo " → .github/skills/ (GitHub Copilot)"
mkdir -p "$TARGET/.github/skills"
fi
for playbook in "$SCRIPT_DIR"/playbooks/assess/*.md; do
filename=$(basename "$playbook")
generate_skills_for_selected_agents "$playbook" "assess/$filename"
done
for playbook in "$SCRIPT_DIR"/playbooks/review/*.md; do
filename=$(basename "$playbook")
# Review playbooks get read-only tools for Claude Code
generate_skills_for_selected_agents "$playbook" "review/$filename" "Read, Grep, Glob, Bash(git *)"
done
for playbook in "$SCRIPT_DIR"/playbooks/plan/*.md; do
filename=$(basename "$playbook")
generate_skills_for_selected_agents "$playbook" "plan/$filename"
done
for playbook in "$SCRIPT_DIR"/playbooks/refactor/*.md; do
filename=$(basename "$playbook")
generate_skills_for_selected_agents "$playbook" "refactor/$filename"
done
if [[ -d "$SCRIPT_DIR/playbooks/docs" ]]; then
for playbook in "$SCRIPT_DIR"/playbooks/docs/*.md; do
[[ -f "$playbook" ]] || continue
filename=$(basename "$playbook")
generate_skills_for_selected_agents "$playbook" "docs/$filename"
done
fi
if [[ -d "$SCRIPT_DIR/playbooks/setup" ]]; then
for playbook in "$SCRIPT_DIR"/playbooks/setup/*.md; do
[[ -f "$playbook" ]] || continue
filename=$(basename "$playbook")
generate_skills_for_selected_agents "$playbook" "setup/$filename" \
"Read, Grep, Glob, Bash, Write, Edit, Agent"
done
fi
else
echo " Skipping skill wrapper generation (no selected agent uses skills)."
fi
echo ""
echo "Done. Next steps:"
step=1
next_step() {
echo " $step. $1"
step=$((step + 1))
}
next_step "Fill in [CONFIGURE] sections in $TARGET/AGENTS.md"
if agent_enabled claude; then
next_step "Fill in [CONFIGURE] sections in $TARGET/CLAUDE.md"
next_step "Review $TARGET/.claude/settings.json and adjust permissions/hooks"
fi
if agent_enabled copilot; then
next_step "Review $TARGET/.github/copilot-instructions.md"
fi
if [[ ${#SKIPPED_FILES[@]} -gt 0 ]]; then
echo ""
echo "Skipped files (not overwritten — manual merge may be required):"
for f in "${SKIPPED_FILES[@]}"; do
echo " - $f"
done
fi