-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·555 lines (511 loc) · 17.9 KB
/
install.sh
File metadata and controls
executable file
·555 lines (511 loc) · 17.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
#!/usr/bin/env bash
set -euo pipefail
VERSION="1.3.0"
REPO="ajhcs/healthcare-agents"
REPO_URL="https://github.com/$REPO"
AGENTS_DIR=""
TARGETS=()
FORCE=false
DRY_RUN=false
UNINSTALL=false
DOCTOR=false
CUSTOM_PATH=""
ALL=false
EXPLICIT=false
TOTAL_INSTALLED=0
AGENT_SLUG=""
if [[ -z "${NO_COLOR:-}" ]] && [[ -t 1 ]]; then
GREEN=$'\033[32m' RED=$'\033[31m' YELLOW=$'\033[33m'
BOLD=$'\033[1m' DIM=$'\033[2m' RESET=$'\033[0m'
else
GREEN="" RED="" YELLOW="" BOLD="" DIM="" RESET=""
fi
ok() { printf " ${GREEN}%s${RESET} %s\n" "+" "$1"; }
skip() { printf " ${DIM}%s${RESET} %s\n" "-" "$1"; }
err() { printf "${RED}error:${RESET} %s\n" "$1" >&2; }
warn() { printf "${YELLOW}warn:${RESET} %s\n" "$1" >&2; }
usage() {
cat <<EOF
${BOLD}Healthcare Agents Installer v$VERSION${RESET}
Usage: install.sh [OPTIONS]
Targets: --claude --claude-code --codex --codex-app --gemini
--cursor --windsurf --copilot --cline --amazonq
--aider --continue
--claude-skills --claude-desktop --claude-cowork
--opencode --agent-skills --skills
--all (force all) --path DIR (custom directory)
Flags: --force Overwrite existing files
--uninstall Remove agents from detected paths
--dry-run Preview without changes
--doctor Report detected tools, paths, and existing installs
--version Print version
-h, --help Show this help
Single agent:
install.sh revenue-cycle-specialist --codex
EOF
exit 0
}
while [[ $# -gt 0 ]]; do
case "$1" in
--claude|--claude-code) TARGETS+=(claude); EXPLICIT=true; shift ;;
--codex|--codex-app) TARGETS+=(codex); EXPLICIT=true; shift ;;
--gemini) TARGETS+=(gemini); EXPLICIT=true; shift ;;
--cursor) TARGETS+=(cursor); EXPLICIT=true; shift ;;
--windsurf) TARGETS+=(windsurf); EXPLICIT=true; shift ;;
--copilot) TARGETS+=(copilot); EXPLICIT=true; shift ;;
--cline) TARGETS+=(cline); EXPLICIT=true; shift ;;
--amazonq) TARGETS+=(amazonq); EXPLICIT=true; shift ;;
--aider) TARGETS+=(aider); EXPLICIT=true; shift ;;
--continue) TARGETS+=(continue); EXPLICIT=true; shift ;;
--claude-skills|--claude-desktop|--claude-cowork|--cowork)
TARGETS+=(claude-skills); EXPLICIT=true; shift ;;
--opencode) TARGETS+=(opencode); EXPLICIT=true; shift ;;
--agent-skills|--agents-skills)
TARGETS+=(agent-skills); EXPLICIT=true; shift ;;
--skills) TARGETS+=(claude-skills opencode agent-skills); EXPLICIT=true; shift ;;
--all) ALL=true; shift ;;
--path) CUSTOM_PATH="$2"; EXPLICIT=true; shift 2 ;;
--force) FORCE=true; shift ;;
--uninstall) UNINSTALL=true; shift ;;
--dry-run) DRY_RUN=true; shift ;;
--doctor) DOCTOR=true; shift ;;
--version) echo "healthcare-agents installer v$VERSION"; exit 0 ;;
-h|--help) usage ;;
*)
if [[ "$1" != --* && -z "$AGENT_SLUG" ]]; then
AGENT_SLUG="$1"
shift
else
err "unknown option: $1"; usage
fi
;;
esac
done
find_agents() {
# Running via npx (HEALTHCARE_AGENTS_ROOT set by bin/cli.js)?
if [[ -n "${HEALTHCARE_AGENTS_ROOT:-}" ]] && [[ -d "$HEALTHCARE_AGENTS_ROOT/agents" ]]; then
AGENTS_DIR="$HEALTHCARE_AGENTS_ROOT/agents"
return 0
fi
# Running from cloned repo?
local script_dir
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ -d "$script_dir/agents" ]]; then
AGENTS_DIR="$script_dir/agents"
return 0
fi
# Running via curl pipe -- need to download
return 1
}
download_agents() {
local tmp
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
printf "%s\n" "Downloading agents from $REPO..."
if command -v git &>/dev/null; then
git clone --depth 1 --quiet "$REPO_URL.git" "$tmp/repo"
AGENTS_DIR="$tmp/repo/agents"
elif command -v curl &>/dev/null; then
curl -fsSL "$REPO_URL/archive/refs/heads/main.tar.gz" | tar -xz -C "$tmp"
AGENTS_DIR="$tmp/healthcare-agents-main/agents"
else
err "need git or curl to download agents"; exit 1
fi
if [[ ! -d "$AGENTS_DIR" ]]; then
err "download failed -- agents/ not found"; exit 1
fi
}
declare -A TOOL_DISPLAY TOOL_PATH TOOL_HOME
reg() { TOOL_DISPLAY[$1]="$2"; TOOL_PATH[$1]="$3"; TOOL_HOME[$1]="$4"; }
reg claude "Claude Code" .claude/agents 1
reg codex "Codex / Codex App" .codex/agents 1
reg gemini "Gemini CLI" .gemini/agents 1
reg cursor "Cursor" .cursor/rules 0
reg windsurf "Windsurf" .windsurf/rules 0
reg copilot "GitHub Copilot" .github/instructions 0
reg cline "Cline" .clinerules 0
reg amazonq "Amazon Q" .amazonq/rules 0
reg aider "Aider" .aider.conf.yml 0
reg continue "Continue.dev" .continue 0
reg claude-skills "Claude Skills" .claude/skills 1
reg opencode "OpenCode Skills" .config/opencode/skills 1
reg agent-skills "Open Agent Skills" .agents/skills 1
TOOL_ORDER=(claude codex claude-skills opencode agent-skills gemini cursor windsurf copilot cline amazonq aider continue)
resolve_path() {
local tool="$1"
if [[ "${TOOL_HOME[$tool]}" == "1" ]]; then
echo "$HOME/${TOOL_PATH[$tool]}"
else
echo "${PWD}/${TOOL_PATH[$tool]}"
fi
}
tool_exists() {
local tool="$1" path
path="$(resolve_path "$tool")"
if [[ "$tool" == "aider" ]]; then
[[ -f "$path" ]] || command -v aider &>/dev/null
elif [[ "$tool" == "opencode" ]]; then
[[ -d "$path" ]] || command -v opencode &>/dev/null
else
[[ -d "$path" ]] || [[ -d "$(dirname "$path")" && "$tool" == "continue" ]]
fi
}
suggest_agent_slugs() {
local wanted="$1" stem slug count=0
stem="${wanted%%-*}"
for f in "$AGENTS_DIR"/*.md; do
slug="$(basename "$f" .md)"
if [[ "$slug" == *"$wanted"* || "$slug" == "$stem"* || "$wanted" == *"$slug"* ]]; then
printf " %s\n" "$slug"
count=$((count + 1))
[[ $count -ge 5 ]] && return
fi
done
if [[ $count -eq 0 ]]; then
for f in "$AGENTS_DIR"/*.md; do
slug="$(basename "$f" .md)"
printf " %s\n" "$slug"
count=$((count + 1))
[[ $count -ge 5 ]] && return
done
fi
}
validate_agent_slug() {
if [[ -z "$AGENT_SLUG" ]]; then return; fi
if [[ ! "$AGENT_SLUG" =~ ^[a-z0-9]+(-[a-z0-9]+)*$ ]]; then
err "invalid agent slug: $AGENT_SLUG"
exit 1
fi
if [[ ! -f "$AGENTS_DIR/$AGENT_SLUG.md" ]]; then
err "unknown agent: $AGENT_SLUG"
printf "Close matches:\n" >&2
suggest_agent_slugs "$AGENT_SLUG" >&2
exit 1
fi
}
agent_files() {
if [[ -n "$AGENT_SLUG" ]]; then
printf "%s\n" "$AGENTS_DIR/$AGENT_SLUG.md"
else
printf "%s\n" "$AGENTS_DIR"/*.md
fi
}
agent_file_count() {
agent_files | wc -l | tr -d ' '
}
plan_write() {
local target="$1" source="$2"
printf " %s write %s <- %s\n" "${GREEN}->${RESET}" "$target" "$source"
}
plan_remove() {
local target="$1"
printf " %s remove %s\n" "${RED}<-${RESET}" "$target"
}
installed_count_for_tool() {
local tool="$1" path count=0 slug
path="$(resolve_path "$tool")"
while IFS= read -r f; do
slug="$(basename "$f" .md)"
if [[ "$tool" == "aider" ]]; then
[[ -f "$path" ]] && grep -Fq "$slug.md" "$path" && count=$((count + 1))
elif [[ "$tool" == "claude-skills" || "$tool" == "opencode" || "$tool" == "agent-skills" ]]; then
[[ -f "$path/$slug/SKILL.md" ]] && count=$((count + 1))
else
[[ -f "$path/$slug.md" ]] && count=$((count + 1))
fi
done < <(agent_files)
printf "%s" "$count"
}
doctor_report() {
printf "\n${BOLD}Healthcare Agents Doctor${RESET}\n"
printf "Agents source: %s\n" "$AGENTS_DIR"
if [[ -n "$AGENT_SLUG" ]]; then
printf "Selected agent: %s\n" "$AGENT_SLUG"
else
printf "Selected agents: %s\n" "$(agent_file_count)"
fi
printf "\nDetected tools and target paths:\n"
local tool path disp installed detected
for tool in "${TOOL_ORDER[@]}"; do
path="$(resolve_path "$tool")"
disp="${TOOL_DISPLAY[$tool]}"
installed="$(installed_count_for_tool "$tool")"
if tool_exists "$tool"; then detected="yes"; else detected="no"; fi
printf " %-24s detected=%-3s installed=%-3s path=%s\n" "$disp" "$detected" "$installed" "$path"
done
printf "\nRecommended next command:\n"
if [[ -n "$AGENT_SLUG" ]]; then
printf " install.sh %s --codex --dry-run\n" "$AGENT_SLUG"
else
printf " install.sh --all --dry-run\n"
fi
}
detect_targets() {
printf "\n${BOLD}Detected tools:${RESET}\n"
for tool in "${TOOL_ORDER[@]}"; do
local path disp
path="$(resolve_path "$tool")"
disp="${TOOL_DISPLAY[$tool]}"
if tool_exists "$tool"; then
ok "$disp ($path)"
TARGETS+=("$tool")
else
skip "$disp (not found)"
fi
done
echo
}
install_to_dir() {
local dest="$1" label="$2"
local count=0
if ! $DRY_RUN; then mkdir -p "$dest"; fi
while IFS= read -r f; do
local base
base="$(basename "$f")"
local target="$dest/$base"
if [[ -f "$target" ]] && ! $FORCE; then
skip "$label: exists $target (use --force to update)"
continue
fi
if $DRY_RUN; then
plan_write "$target" "$f"
count=$((count + 1))
continue
fi
cp "$f" "$target"
count=$((count + 1))
done < <(agent_files)
printf " %s %s (%d files)\n" "${GREEN}->${RESET}" "$label" "$count"
TOTAL_INSTALLED=$((TOTAL_INSTALLED + count))
}
field_value() {
local file="$1" field="$2"
awk -v key="$field:" '
$0 == "---" { seen++; next }
seen == 1 && index($0, key) == 1 {
sub("^[^:]+:[[:space:]]*", "", $0)
gsub(/^"|"$/, "", $0)
print
exit
}
' "$file"
}
write_skill_file() {
local src="$1" dest_dir="$2"
local slug display desc
slug="$(basename "$src" .md)"
display="$(field_value "$src" display_name)"
[[ -n "$display" ]] || display="$slug"
desc="$(field_value "$src" description)"
mkdir -p "$dest_dir/$slug"
{
printf '%s\n' '---'
printf 'name: %s\n' "$slug"
printf '%s\n' 'description: >-'
printf ' Healthcare administration specialist: %s Use when the user asks for the %s role, related healthcare operations expertise, or a concrete deliverable in this specialty.\n' "$desc" "$display"
printf 'license: Apache-2.0\n'
printf 'compatibility: claude-code, claude-desktop, claude-cowork, opencode, codex\n'
printf '%s\n\n' '---'
printf 'Use this skill as the %s healthcare administration specialist. Preserve the role identity, regulatory boundaries, source hierarchy, deliverable style, and safety constraints below.\n\n' "$display"
sed '1,/^---$/d' "$src"
} > "$dest_dir/$slug/SKILL.md"
}
install_skills_tree() {
local dest="$1" label="$2"
local count=0
if ! $DRY_RUN; then mkdir -p "$dest"; fi
while IFS= read -r f; do
local slug target
slug="$(basename "$f" .md)"
target="$dest/$slug/SKILL.md"
if [[ -f "$target" ]] && ! $FORCE; then
skip "$label: exists $target (use --force to update)"
continue
fi
if $DRY_RUN; then
plan_write "$target" "$f"
else
write_skill_file "$f" "$dest"
fi
count=$((count + 1))
done < <(agent_files)
printf " %s %s (%d skills)\n" "${GREEN}->${RESET}" "$label" "$count"
TOTAL_INSTALLED=$((TOTAL_INSTALLED + count))
}
uninstall_skills_tree() {
local dest="$1" label="$2"
local count=0
while IFS= read -r f; do
local slug target
slug="$(basename "$f" .md)"
target="$dest/$slug"
if [[ -d "$target" ]]; then
if $DRY_RUN; then plan_remove "$target"; else rm -rf "$target"; fi
count=$((count + 1))
fi
done < <(agent_files)
if [[ $count -gt 0 ]]; then
printf " %s %s (%d skills removed)\n" "${RED}<-${RESET}" "$label" "$count"
TOTAL_INSTALLED=$((TOTAL_INSTALLED + count))
else
skip "$label (nothing to remove)"
fi
}
upsert_block() {
local file="$1" start="$2" end="$3" body="$4"
if ! $DRY_RUN; then mkdir -p "$(dirname "$file")"; fi
local tmp
tmp="$(mktemp)"
printf '%s\n%s\n%s\n' "$start" "$body" "$end" > "$tmp"
if [[ ! -f "$file" ]]; then
if ! $DRY_RUN; then cp "$tmp" "$file"; fi
rm -f "$tmp"
return
fi
if grep -Fq "$start" "$file"; then
if ! $DRY_RUN; then
awk -v start="$start" -v end="$end" -v replacement="$tmp" '
$0 == start {
while ((getline line < replacement) > 0) print line
close(replacement)
skip = 1
next
}
$0 == end { skip = 0; next }
!skip { print }
' "$file" >"$file.tmp"
mv "$file.tmp" "$file"
fi
else
if ! $DRY_RUN; then
{
printf '\n'
cat "$tmp"
printf '\n'
} >> "$file"
fi
fi
rm -f "$tmp"
}
install_codex() {
local dest="$HOME/.codex/agents"
if $UNINSTALL; then
uninstall_from_dir "$dest" "Codex / Codex App ($dest)"
return
fi
install_to_dir "$dest" "Codex / Codex App ($dest)"
local body
body='## Healthcare Agents
When the user asks for healthcare administration expertise, choose one primary specialist prompt from `~/.codex/agents/*.md` and read it before answering. Agent file names and frontmatter `name` fields use lowercase hyphen slugs such as `revenue-cycle-specialist`; `display_name` is the human label. If the request is ambiguous, ask for the missing details from the selected agent'\''s Best Inputs section or start in quick triage mode. When the user asks for a mode, respect `quick triage`, `workplan`, `audit/checklist`, and `artifact/template`. When work crosses roles, name the supporting healthcare-agents handoffs instead of blending responsibilities. Preserve the selected agent role, compliance boundaries, source hierarchy, deliverable style, and decision-support framing. Do not treat the agents as clinical, legal, coding-of-record, billing-authority, or PHI-handling authority.'
upsert_block "$HOME/.codex/AGENTS.md" "<!-- healthcare-agents:start -->" "<!-- healthcare-agents:end -->" "$body"
if $DRY_RUN; then
plan_write "$HOME/.codex/AGENTS.md" "managed Codex instructions block"
fi
TOTAL_INSTALLED=$((TOTAL_INSTALLED + 1))
printf " %s Codex instructions (%s)\n" "${GREEN}->${RESET}" "$HOME/.codex/AGENTS.md"
}
uninstall_from_dir() {
local dest="$1" label="$2"
local count=0
while IFS= read -r f; do
local base target
base="$(basename "$f")"
target="$dest/$base"
if [[ -f "$target" ]]; then
if $DRY_RUN; then plan_remove "$target"; else rm "$target"; fi
count=$((count + 1))
fi
done < <(agent_files)
if [[ $count -gt 0 ]]; then
printf " %s %s (%d files removed)\n" "${RED}<-${RESET}" "$label" "$count"
TOTAL_INSTALLED=$((TOTAL_INSTALLED + count))
else
skip "$label (nothing to remove)"
fi
}
install_aider() {
local conf="${PWD}/.aider.conf.yml"
local agent_count
agent_count="$(agent_file_count)"
if $UNINSTALL; then
if [[ -f "$conf" ]] && grep -q "# healthcare-agents" "$conf" 2>/dev/null; then
if $DRY_RUN; then
plan_remove "$conf"
else
sed -i '/# healthcare-agents start/,/# healthcare-agents end/d' "$conf"
fi
printf " %s Aider (.aider.conf.yml block removed)\n" "${RED}<-${RESET}"
TOTAL_INSTALLED=$((TOTAL_INSTALLED + 1))
else
skip "Aider (no managed block found)"
fi
return
fi
if [[ -f "$conf" ]] && grep -q "# healthcare-agents" "$conf" 2>/dev/null && ! $FORCE; then
warn "Aider: config block exists (use --force to update)"; return
fi
local block="# healthcare-agents start"$'\n'"read:"
while IFS= read -r f; do
block+=$'\n'" - $f"
done < <(agent_files)
block+=$'\n'"# healthcare-agents end"
if $DRY_RUN; then
plan_write "$conf" "managed Aider read block"
printf " %s Aider (.aider.conf.yml, %d read entries)\n" "${GREEN}->${RESET}" "$agent_count"
TOTAL_INSTALLED=$((TOTAL_INSTALLED + 1))
return
fi
# Remove old block if --force, then append
if [[ -f "$conf" ]] && grep -q "# healthcare-agents" "$conf" 2>/dev/null; then
sed -i '/# healthcare-agents start/,/# healthcare-agents end/d' "$conf"
fi
echo "$block" >> "$conf"
printf " %s Aider (.aider.conf.yml, %d read entries)\n" "${GREEN}->${RESET}" "$agent_count"
TOTAL_INSTALLED=$((TOTAL_INSTALLED + 1))
}
printf "\n${BOLD}Healthcare Agents Installer v%s${RESET}\n" "$VERSION"
# Get agents
if ! find_agents; then
download_agents
fi
validate_agent_slug
AGENT_COUNT="$(agent_file_count)"
if $DOCTOR; then
doctor_report
exit 0
fi
if $ALL; then TARGETS=("${TOOL_ORDER[@]}")
elif ! $EXPLICIT; then detect_targets; fi
[[ -n "$CUSTOM_PATH" ]] && TARGETS+=(custom)
if [[ ${#TARGETS[@]} -eq 0 ]]; then
warn "no supported tools detected"
printf " Use --all to install everywhere, or target a specific tool (e.g. --claude)\n"
exit 1
fi
TARGETS=($(printf '%s\n' "${TARGETS[@]}" | sort -u))
ACTION="Installing"
$UNINSTALL && ACTION="Uninstalling"
$DRY_RUN && ACTION="Would install"
$DRY_RUN && $UNINSTALL && ACTION="Would uninstall"
printf "%s %d agents to %d target(s)...\n\n" "$ACTION" "$AGENT_COUNT" "${#TARGETS[@]}"
for tool in "${TARGETS[@]}"; do
if [[ "$tool" == "custom" ]]; then
if $UNINSTALL; then uninstall_from_dir "$CUSTOM_PATH" "$CUSTOM_PATH"
else install_to_dir "$CUSTOM_PATH" "$CUSTOM_PATH"; fi
continue
fi
local_path="$(resolve_path "$tool")"
if [[ "$tool" == "aider" ]]; then install_aider; continue; fi
if [[ "$tool" == "codex" ]]; then install_codex; continue; fi
if [[ "$tool" == "claude-skills" || "$tool" == "opencode" || "$tool" == "agent-skills" ]]; then
if $UNINSTALL; then uninstall_skills_tree "$local_path" "${TOOL_DISPLAY[$tool]} ($local_path)"
else install_skills_tree "$local_path" "${TOOL_DISPLAY[$tool]} ($local_path)"; fi
continue
fi
if $UNINSTALL; then uninstall_from_dir "$local_path" "${TOOL_DISPLAY[$tool]} ($local_path)"
else install_to_dir "$local_path" "${TOOL_DISPLAY[$tool]} ($local_path)"; fi
done
echo
if $DRY_RUN; then printf "${BOLD}Dry run complete.${RESET} %d files would be affected.\n" "$TOTAL_INSTALLED"
elif $UNINSTALL; then printf "${BOLD}Done!${RESET} %d files removed.\n" "$TOTAL_INSTALLED"
else printf "${BOLD}Done!${RESET} %d files installed.\n" "$TOTAL_INSTALLED"; fi