-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·186 lines (151 loc) · 4.44 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·186 lines (151 loc) · 4.44 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SKILLS_SOURCE_DIR="$SCRIPT_DIR/skills"
PLAN_SKILL_NAME="delegate-plan"
REVIEW_SKILL_NAME="delegate-review"
COMMIT_SKILL_NAME="delegate-commit"
SKILL_NAMES=(
"$PLAN_SKILL_NAME"
"$REVIEW_SKILL_NAME"
"$COMMIT_SKILL_NAME"
)
BACKUP_EXISTING=0
QUIET=0
usage() {
cat <<'USAGE'
Usage:
bash install.sh [options]
Install three user-level Codex skills:
- delegate-plan
- delegate-review
- delegate-commit
Install root:
$HOME/.agents/skills
Backup root:
$HOME/.agents/skills-backups
Behavior:
Overwrites existing same-name skills on every run.
Safe to run multiple times; each run mirrors skills/ exactly.
Options:
--backup Back up existing same-name skills before overwriting
--quiet Reduce output
-h, --help Show help
After installation, restart Codex if needed and run /skills.
USAGE
}
info() {
if [[ "$QUIET" -eq 0 ]]; then
printf '==> %s\n' "$*"
fi
}
warn() {
printf 'Warning: %s\n' "$*" >&2
}
die() {
printf 'Error: %s\n' "$*" >&2
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
--backup)
BACKUP_EXISTING=1
shift
;;
--no-backup)
BACKUP_EXISTING=0
shift
;;
--quiet)
QUIET=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
die "Unknown argument: $1"
;;
esac
done
if [[ -z "${HOME:-}" ]]; then
die "HOME is not set. Cannot determine user-level skill directory."
fi
OS_NAME="$(uname -s 2>/dev/null || true)"
case "$OS_NAME" in
Darwin|Linux) ;;
*) warn "Unsupported OS name: ${OS_NAME:-unknown}. Continuing anyway." ;;
esac
INSTALL_ROOT="$HOME/.agents/skills"
BACKUP_BASE="$HOME/.agents/skills-backups"
TIMESTAMP="$(date '+%Y%m%d-%H%M%S')"
BACKUP_ROOT=""
backup_existing_skill() {
local skill_name="$1"
local skill_dir="$INSTALL_ROOT/$skill_name"
if [[ ! -e "$skill_dir" ]]; then
return 0
fi
if [[ "$BACKUP_EXISTING" -eq 1 ]]; then
if [[ -z "$BACKUP_ROOT" ]]; then
BACKUP_ROOT="$BACKUP_BASE/codex-delegate-skills-$TIMESTAMP-$$"
mkdir -p "$BACKUP_ROOT"
fi
info "Backing up existing skill: $skill_dir -> $BACKUP_ROOT/$skill_name"
mv "$skill_dir" "$BACKUP_ROOT/$skill_name"
return 0
fi
info "Removing existing skill: $skill_dir"
rm -rf "$skill_dir"
}
validate_skill() {
local skill_name="$1"
local skill_dir="$INSTALL_ROOT/$skill_name"
local skill_md="$skill_dir/SKILL.md"
local openai_yaml="$skill_dir/agents/openai.yaml"
[[ -d "$skill_dir" ]] || die "Missing skill directory: $skill_dir"
[[ -f "$skill_md" ]] || die "Missing file: $skill_md"
[[ -f "$openai_yaml" ]] || die "Missing file: $openai_yaml"
grep -q "^name: $skill_name$" "$skill_md" || die "Invalid name metadata in $skill_md"
grep -q "^description:" "$skill_md" || die "Missing description metadata in $skill_md"
grep -q "allow_implicit_invocation: false" "$openai_yaml" || die "Missing allow_implicit_invocation: false in $openai_yaml"
}
install_skill() {
local skill_name="$1"
local source_dir="$SKILLS_SOURCE_DIR/$skill_name"
local target_dir="$INSTALL_ROOT/$skill_name"
[[ -d "$source_dir" ]] || die "Missing source skill directory: $source_dir"
[[ -f "$source_dir/SKILL.md" ]] || die "Missing source file: $source_dir/SKILL.md"
[[ -f "$source_dir/agents/openai.yaml" ]] || die "Missing source file: $source_dir/agents/openai.yaml"
backup_existing_skill "$skill_name"
rm -rf "$target_dir"
mkdir -p "$target_dir"
info "Installing $skill_name"
cp -R "$source_dir/." "$target_dir/"
}
[[ -d "$SKILLS_SOURCE_DIR" ]] || die "Missing skills source directory: $SKILLS_SOURCE_DIR"
info "Preparing user-level Codex skills directory: $INSTALL_ROOT"
mkdir -p "$INSTALL_ROOT"
for skill_name in "${SKILL_NAMES[@]}"; do
install_skill "$skill_name"
done
info "Validating installation"
for skill_name in "${SKILL_NAMES[@]}"; do
validate_skill "$skill_name"
done
printf '\nInstallation complete.\n\n'
printf 'Installed skills:\n'
for skill_name in "${SKILL_NAMES[@]}"; do
printf ' %s/%s\n' "$INSTALL_ROOT" "$skill_name"
done
if [[ -n "$BACKUP_ROOT" ]]; then
printf '\nBackups saved to:\n %s\n' "$BACKUP_ROOT"
fi
printf '\nNext steps:\n'
printf ' 1. Restart Codex if the skills do not appear immediately.\n'
printf ' 2. Run /skills in Codex.\n'
printf ' 3. Invoke explicitly with:\n'
printf ' $%s\n' "$PLAN_SKILL_NAME"
printf ' $%s\n' "$REVIEW_SKILL_NAME"
printf ' $%s\n' "$COMMIT_SKILL_NAME"