-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
313 lines (286 loc) · 8.6 KB
/
Copy pathinstall.sh
File metadata and controls
313 lines (286 loc) · 8.6 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
#!/usr/bin/env bash
set -euo pipefail
repo="qWaitCrypto/HarnessKit"
version="latest"
prefix="${HOME}/.local"
install_claude=1
install_codex=1
install_codex_plugin=0
tmp_dir=""
asset_base_url=""
usage() {
cat <<'EOF'
Install HarnessKit.
Usage:
install.sh [options]
Options:
--version <tag> Release tag to install, e.g. v0.1.0-alpha.3 (default: latest)
--prefix <path> Install prefix for the CLI (default: ~/.local)
--repo <owner/name> GitHub repository (default: qWaitCrypto/HarnessKit)
--asset-base-url <url>
Override release asset base URL, mainly for testing
--cli-only Install only the harnesskit CLI
--no-claude Do not install Claude Code skill
--no-codex Do not install Codex skill
--with-codex-plugin Also install optional Codex local plugin package
-h, --help Show this help
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--version)
if [[ $# -lt 2 || "${2:-}" == -* ]]; then
echo "--version requires a release tag, e.g. v0.1.0-alpha.3" >&2
exit 2
fi
version="$2"
shift 2
;;
--prefix)
if [[ $# -lt 2 || "${2:-}" == -* ]]; then
echo "--prefix requires a path" >&2
exit 2
fi
prefix="$2"
shift 2
;;
--repo)
if [[ $# -lt 2 || "${2:-}" == -* ]]; then
echo "--repo requires owner/name" >&2
exit 2
fi
repo="$2"
shift 2
;;
--asset-base-url)
if [[ $# -lt 2 || "${2:-}" == -* ]]; then
echo "--asset-base-url requires a URL" >&2
exit 2
fi
asset_base_url="${2%/}"
shift 2
;;
--cli-only)
install_claude=0
install_codex=0
install_codex_plugin=0
shift
;;
--no-claude)
install_claude=0
shift
;;
--no-codex)
install_codex=0
install_codex_plugin=0
shift
;;
--with-codex-plugin)
install_codex_plugin=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown argument: $1" >&2
usage >&2
exit 2
;;
esac
done
need_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "missing required command: $1" >&2
exit 1
fi
}
detect_target() {
local os arch
os="$(uname -s)"
arch="$(uname -m)"
case "${os}:${arch}" in
Linux:x86_64|Linux:amd64)
echo "x86_64-unknown-linux-gnu"
;;
Darwin:x86_64|Darwin:amd64)
echo "x86_64-apple-darwin"
;;
Darwin:arm64|Darwin:aarch64)
echo "aarch64-apple-darwin"
;;
*)
echo "unsupported platform: ${os} ${arch}" >&2
echo "This alpha installer currently supports Linux x86_64 and macOS x86_64/arm64." >&2
exit 1
;;
esac
}
verify_sha256_file() {
local sums_file="$1"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c "${sums_file}"
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 -c "${sums_file}"
else
echo "missing required command: sha256sum or shasum" >&2
exit 1
fi
}
write_archive_sha256_file() {
local sums_file="$1"
local archive="$2"
local archive_sums="${archive}.sha256"
awk -v archive="${archive}" '$2 == archive { print; found = 1 } END { exit found ? 0 : 1 }' "${sums_file}" > "${archive_sums}" || {
echo "${sums_file} did not contain checksum for ${archive}" >&2
exit 1
}
echo "${archive_sums}"
}
download() {
local url="$1"
local out="$2"
if command -v curl >/dev/null 2>&1; then
if ! curl -fsSL --retry 3 --retry-delay 2 --connect-timeout 20 --max-time 120 "$url" -o "$out"; then
echo "download failed: ${url}" >&2
echo "If you are behind a proxy, set http_proxy, https_proxy, or all_proxy and retry." >&2
exit 1
fi
elif command -v wget >/dev/null 2>&1; then
if ! wget -q --tries=3 --timeout=120 "$url" -O "$out"; then
echo "download failed: ${url}" >&2
echo "If you are behind a proxy, set http_proxy, https_proxy, or all_proxy and retry." >&2
exit 1
fi
else
echo "missing required command: curl or wget" >&2
exit 1
fi
}
upsert_codex_marketplace() {
local marketplace_path="$1"
mkdir -p "$(dirname "${marketplace_path}")"
MARKETPLACE_PATH="${marketplace_path}" python3 - <<'PY'
import json
import os
from pathlib import Path
path = Path(os.environ["MARKETPLACE_PATH"])
entry = {
"name": "harnesskit",
"source": {"source": "local", "path": "./plugins/harnesskit"},
"policy": {"installation": "AVAILABLE", "authentication": "ON_INSTALL"},
"category": "Coding",
}
if path.exists():
try:
data = json.loads(path.read_text())
except json.JSONDecodeError as exc:
raise SystemExit(f"invalid marketplace JSON at {path}: {exc}")
backup = path.with_suffix(path.suffix + ".harnesskit.bak")
backup.write_text(path.read_text())
else:
data = {
"name": "personal",
"interface": {"displayName": "Personal"},
"plugins": [],
}
plugins = data.setdefault("plugins", [])
plugins[:] = [plugin for plugin in plugins if plugin.get("name") != "harnesskit"]
plugins.append(entry)
path.write_text(json.dumps(data, indent=2) + "\n")
PY
}
need_cmd tar
if [[ "${install_codex_plugin}" -eq 1 ]]; then
need_cmd python3
fi
case "${repo}" in
*/*) ;;
*)
echo "--repo must use owner/name format" >&2
exit 2
;;
esac
target="$(detect_target)"
package="harnesskit-${target}"
archive="${package}.tar.gz"
if [[ -z "${asset_base_url}" ]]; then
if [[ "${version}" == "latest" ]]; then
asset_base_url="https://github.com/${repo}/releases/latest/download"
else
asset_base_url="https://github.com/${repo}/releases/download/${version}"
fi
fi
tmp_dir="$(mktemp -d)"
trap 'rm -rf "${tmp_dir}"' EXIT
echo "Downloading HarnessKit ${version} for ${target}..."
echo "Install prefix: ${prefix}"
if [[ "${install_claude}" -eq 1 ]]; then
echo "Claude skill: ${HOME}/.claude/skills/harnesskit/SKILL.md"
fi
if [[ "${install_codex}" -eq 1 ]]; then
codex_home="${CODEX_HOME:-${HOME}/.codex}"
echo "Codex skill: ${codex_home}/skills/harnesskit/SKILL.md"
fi
if [[ "${install_codex_plugin}" -eq 1 ]]; then
echo "Optional Codex plugin package: ${HOME}/plugins/harnesskit"
fi
download "${asset_base_url}/${archive}" "${tmp_dir}/${archive}"
download "${asset_base_url}/SHA256SUMS" "${tmp_dir}/SHA256SUMS"
(
cd "${tmp_dir}"
archive_sums="$(write_archive_sha256_file SHA256SUMS "${archive}")"
verify_sha256_file "${archive_sums}"
)
tar -xzf "${tmp_dir}/${archive}" -C "${tmp_dir}"
package_dir="${tmp_dir}/${package}"
mkdir -p "${prefix}/bin"
cp "${package_dir}/harnesskit" "${prefix}/bin/harnesskit"
chmod +x "${prefix}/bin/harnesskit" 2>/dev/null || true
echo "Installed CLI: ${prefix}/bin/harnesskit"
if [[ "${install_claude}" -eq 1 ]]; then
mkdir -p "${HOME}/.claude/skills/harnesskit"
cp "${package_dir}/agent-surfaces/skills/harnesskit/SKILL.md" "${HOME}/.claude/skills/harnesskit/SKILL.md"
echo "Installed Claude Code skill: ${HOME}/.claude/skills/harnesskit/SKILL.md"
fi
if [[ "${install_codex}" -eq 1 ]]; then
codex_home="${CODEX_HOME:-${HOME}/.codex}"
mkdir -p "${codex_home}/skills/harnesskit"
cp "${package_dir}/agent-surfaces/skills/harnesskit/SKILL.md" "${codex_home}/skills/harnesskit/SKILL.md"
echo "Installed Codex skill: ${codex_home}/skills/harnesskit/SKILL.md"
fi
if [[ "${install_codex_plugin}" -eq 1 ]]; then
mkdir -p "${HOME}/plugins/harnesskit/.codex-plugin"
mkdir -p "${HOME}/plugins/harnesskit/skills/harnesskit"
cp "${package_dir}/agent-surfaces/codex/.codex-plugin/plugin.json" "${HOME}/plugins/harnesskit/.codex-plugin/plugin.json"
cp "${package_dir}/agent-surfaces/skills/harnesskit/SKILL.md" "${HOME}/plugins/harnesskit/skills/harnesskit/SKILL.md"
upsert_codex_marketplace "${HOME}/.agents/plugins/marketplace.json"
echo "Installed Codex local plugin package: ${HOME}/plugins/harnesskit"
echo "Updated Codex personal marketplace: ${HOME}/.agents/plugins/marketplace.json"
fi
echo
if [[ ":${PATH}:" != *":${prefix}/bin:"* ]]; then
echo "Add HarnessKit to PATH for this shell:"
echo " export PATH=\"${prefix}/bin:\$PATH\""
echo
fi
echo "HarnessKit installed successfully."
echo
echo "Verify:"
echo " ${prefix}/bin/harnesskit --version"
echo " ${prefix}/bin/harnesskit doctor"
echo
echo "Next in a repository, ask your coding agent:"
echo " Initialize HarnessKit project docs for this repository."
echo
echo "Manual fallback:"
echo " harnesskit init"
echo " harnesskit index"
echo " harnesskit check"
if [[ "${install_codex_plugin}" -eq 1 ]]; then
echo
echo "For optional Codex plugin mode, install the plugin after this script:"
echo " codex plugin list | grep harnesskit"
echo " codex plugin add harnesskit@personal"
fi