-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall-skill.sh
More file actions
216 lines (185 loc) · 5.16 KB
/
Copy pathinstall-skill.sh
File metadata and controls
216 lines (185 loc) · 5.16 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
#!/bin/sh
set -eu
REPO="${AGENT_MEMORY_REPO:-taichuy/agentMemory}"
REF="${AGENT_MEMORY_REF:-main}"
TOOLS="${AGENT_MEMORY_TOOL:-}"
FORCE=0
TMPDIR=""
usage() {
cat <<'EOF'
Install agentMemory for one selected coding tool.
Usage:
install-skill.sh --tool <codex|claude|opencode|gemini> [--update]
Options:
--tool, --tools <list> Comma-separated tools to install. Required.
--repo <owner/repo> GitHub repository to download. Default: taichuy/agentMemory
--ref <branch> Branch to download. Default: main
--update Update by replacing existing installed skill/command files
--force Alias of --update
-h, --help Show this help
Examples:
curl -fsSL https://raw.githubusercontent.com/taichuy/agentMemory/main/install-skill.sh | sh -s -- --tool codex
curl -fsSL https://raw.githubusercontent.com/taichuy/agentMemory/main/install-skill.sh | sh -s -- --tool claude --update
EOF
}
while [ "$#" -gt 0 ]; do
case "$1" in
--tool|--tools)
TOOLS="$2"
shift 2
;;
--repo)
REPO="$2"
shift 2
;;
--ref)
REF="$2"
shift 2
;;
--update|--force)
FORCE=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 1
;;
esac
done
TOOLS="$(printf '%s' "$TOOLS" | tr '[:upper:]' '[:lower:]' | tr -d ' ')"
if [ -z "$TOOLS" ]; then
echo "No tool selected. Choose one with --tool codex, --tool claude, --tool opencode, or --tool gemini." >&2
usage >&2
exit 2
fi
case ",$TOOLS," in
*,all,*)
echo "Refusing implicit all-tools install. Install only the tool you need, for example --tool codex." >&2
exit 2
;;
esac
enabled() {
case ",$TOOLS," in
*,"$1",*) return 0 ;;
*) return 1 ;;
esac
}
validate_tools() {
old_ifs="$IFS"
IFS=","
for tool in $TOOLS; do
case "$tool" in
codex|claude|opencode|gemini) ;;
*)
IFS="$old_ifs"
echo "Unsupported tool: $tool" >&2
usage >&2
exit 2
;;
esac
done
IFS="$old_ifs"
}
cleanup() {
if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
rm -rf "$TMPDIR"
fi
}
trap cleanup EXIT INT TERM
validate_tools
script_dir=""
if [ -n "${0:-}" ] && [ -f "$0" ]; then
script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
fi
if [ -n "$script_dir" ] && [ -d "$script_dir/skills/agent-memory" ]; then
source_root="$script_dir"
else
TMPDIR="$(mktemp -d 2>/dev/null || mktemp -d -t agentMemorySkill)"
archive_path="$TMPDIR/agentMemory.tar.gz"
extract_path="$TMPDIR/extract"
mkdir -p "$extract_path"
download_url="https://codeload.github.com/$REPO/tar.gz/refs/heads/$REF"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$download_url" -o "$archive_path"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$archive_path" "$download_url"
else
echo "Either curl or wget is required to download the archive." >&2
exit 1
fi
tar -xzf "$archive_path" -C "$extract_path"
source_root="$(find "$extract_path" -mindepth 1 -maxdepth 1 -type d | head -n 1)"
fi
skill_source="$source_root/skills/agent-memory"
command_source="$source_root/commands/skills.md"
gemini_command_source="$source_root/commands/gemini-skills.toml"
if [ ! -d "$skill_source" ]; then
echo "The repository archive does not contain skills/agent-memory." >&2
exit 1
fi
copy_dir() {
source="$1"
target="$2"
label="$3"
base_dir="$(dirname "$target")"
existed=0
mkdir -p "$base_dir"
if [ -e "$target" ] && [ "$FORCE" -ne 1 ]; then
echo "Kept existing $label at $target"
return
fi
if [ -e "$target" ]; then
existed=1
rm -rf "$target"
fi
cp -R "$source" "$target"
if [ "$existed" -eq 1 ]; then
echo "Updated $label at $target"
else
echo "Installed $label at $target"
fi
}
copy_file() {
source="$1"
target="$2"
label="$3"
base_dir="$(dirname "$target")"
existed=0
mkdir -p "$base_dir"
if [ -e "$target" ] && [ "$FORCE" -ne 1 ]; then
echo "Kept existing $label at $target"
return
fi
if [ -e "$target" ]; then
existed=1
fi
cp "$source" "$target"
if [ "$existed" -eq 1 ]; then
echo "Updated $label at $target"
else
echo "Installed $label at $target"
fi
}
if enabled codex; then
copy_dir "$skill_source" "$HOME/.codex/skills/agent-memory" "Codex skill"
copy_file "$command_source" "$HOME/.codex/prompts/skills.md" "Codex /prompts:skills prompt"
fi
if enabled claude; then
copy_dir "$skill_source" "$HOME/.claude/skills/agent-memory" "Claude Code skill"
copy_file "$command_source" "$HOME/.claude/commands/skills.md" "Claude Code /skills command"
fi
if enabled opencode; then
opencode_home="${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
copy_dir "$skill_source" "$opencode_home/skills/agent-memory" "OpenCode skill"
copy_file "$command_source" "$opencode_home/commands/skills.md" "OpenCode /skills command"
fi
if enabled gemini; then
copy_dir "$skill_source" "$HOME/.gemini/skills/agent-memory" "Gemini CLI skill"
copy_file "$gemini_command_source" "$HOME/.gemini/commands/skills.toml" "Gemini CLI /skills command"
fi
echo "Done. Restart the selected tool if it does not immediately see /skills."