xithead 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -72
- package/app/api/config/route.ts +22 -0
- package/app/api/export/route.ts +83 -0
- package/app/api/models/route.ts +12 -0
- package/app/api/stats/route.ts +46 -0
- package/app/dashboard/page.tsx +445 -0
- package/app/globals.css +35 -0
- package/app/installation/page.tsx +293 -0
- package/app/layout.tsx +35 -0
- package/app/master-design-system.css +2076 -0
- package/app/master-design-system.source.css +8 -0
- package/app/page.tsx +187 -0
- package/app/rechtliches/agb/page.tsx +165 -0
- package/app/rechtliches/datenschutz/page.tsx +128 -0
- package/app/rechtliches/impressum/page.tsx +122 -0
- package/app/rechtliches/widerruf/page.tsx +185 -0
- package/bin/xithead.js +264 -0
- package/components/layout/AppShell.tsx +25 -0
- package/components/layout/Footer.tsx +120 -0
- package/components/layout/Header.tsx +145 -0
- package/components/marketing/LegalHighlights.tsx +45 -0
- package/components/marketing/LegalPageShell.tsx +49 -0
- package/components/marketing/LegalPanel.tsx +41 -0
- package/components/marketing/index.ts +3 -0
- package/design-system/README.md +80 -0
- package/design-system/base.css +127 -0
- package/design-system/components.css +1943 -0
- package/design-system/fonts.css +17 -0
- package/design-system/tailwind-preset.js +95 -0
- package/design-system/tokens.css +48 -0
- package/design-system/utilities.css +53 -0
- package/lib/config/index.ts +12 -0
- package/lib/hooks/index.ts +4 -0
- package/lib/hooks/use-mounted.ts +13 -0
- package/lib/hooks/use-session.ts +34 -0
- package/lib/hooks/use-settings.ts +49 -0
- package/lib/utils/index.ts +1 -0
- package/lib/utils/settings.ts +162 -0
- package/lib/utils/utils.ts +6 -0
- package/middleware.ts +26 -0
- package/next-env.d.ts +7 -0
- package/next.config.ts +12 -0
- package/package.json +77 -36
- package/postcss.config.mjs +7 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/logo-transparent.png +0 -0
- package/public/xithead.ps1 +937 -0
- package/scripts/README.md +77 -0
- package/scripts/audit_wheel_glibc_symbols.py +217 -0
- package/scripts/build-master-design-system.cjs +33 -0
- package/scripts/build_rust_extension.sh +58 -0
- package/scripts/changelog-gen.py +203 -0
- package/scripts/eval_output_shaper.py +235 -0
- package/scripts/export_kompress_v2_onnx.py +267 -0
- package/scripts/fixtures/anthropic_replay_body.json +133 -0
- package/scripts/fixtures/codex_response_create_frame.json +52 -0
- package/scripts/install-git-hooks.sh +104 -0
- package/scripts/install.ps1 +1809 -0
- package/scripts/install.sh +1673 -0
- package/scripts/pr-governance.py +297 -0
- package/scripts/record_fixtures.py +59 -0
- package/scripts/refresh_model_limits.sh +48 -0
- package/scripts/replay_codex_ws_load.py +445 -0
- package/scripts/repro_codex_replay.py +699 -0
- package/scripts/smoke_issue_327.py +233 -0
- package/scripts/sync-plugin-versions.py +116 -0
- package/scripts/tests/test_changelog_gen.py +302 -0
- package/scripts/tests/test_pr_governance.py +163 -0
- package/scripts/tests/test_pr_health_labels.py +94 -0
- package/scripts/tests/test_pr_health_workflow.py +14 -0
- package/scripts/tests/test_sync_plugin_versions.py +131 -0
- package/scripts/tests/test_version_sync.py +291 -0
- package/scripts/validate-workflows.sh +39 -0
- package/scripts/verify-versions.py +106 -0
- package/scripts/version-sync.py +207 -0
- package/tailwind.config.js +31 -0
- package/tailwind.master.config.cjs +47 -0
- package/tsconfig.json +84 -0
- package/types/api.ts +12 -0
- package/types/config.ts +9 -0
- package/types/index.ts +2 -0
- package/npm/bin/xithead.js +0 -366
- package/npm/index.d.ts +0 -57
- package/npm/index.js +0 -139
- package/npm/package.json +0 -54
- package/npm/postinstall.js +0 -43
|
@@ -0,0 +1,1673 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
IMAGE_DEFAULT="ghcr.io/chopratejas/headroom:latest"
|
|
6
|
+
INSTALL_IMAGE="${HEADROOM_DOCKER_IMAGE:-${IMAGE_DEFAULT}}"
|
|
7
|
+
INSTALL_DIR="${HOME}/.local/bin"
|
|
8
|
+
if [[ ! -d "${HOME}/.local" ]]; then
|
|
9
|
+
INSTALL_DIR="${HOME}/bin"
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
BASH_PATH="${BASH:-$(command -v bash)}"
|
|
13
|
+
if ((BASH_VERSINFO[0] < 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] < 3))); then
|
|
14
|
+
printf 'ERROR: Headroom Docker-native install requires bash >= 4.3\n' >&2
|
|
15
|
+
exit 1
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
info() {
|
|
19
|
+
printf '==> %s\n' "$*"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
warn() {
|
|
23
|
+
printf 'WARN: %s\n' "$*" >&2
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
die() {
|
|
27
|
+
printf 'ERROR: %s\n' "$*" >&2
|
|
28
|
+
exit 1
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
require_cmd() {
|
|
32
|
+
command -v "$1" >/dev/null 2>&1 || die "Missing required command: $1"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
append_path_block() {
|
|
36
|
+
local target_file="$1"
|
|
37
|
+
local marker_start="# >>> headroom docker-native >>>"
|
|
38
|
+
local marker_end="# <<< headroom docker-native <<<"
|
|
39
|
+
local block="${marker_start}
|
|
40
|
+
export PATH=\"${INSTALL_DIR}:\$PATH\"
|
|
41
|
+
${marker_end}"
|
|
42
|
+
|
|
43
|
+
touch "${target_file}"
|
|
44
|
+
if grep -Fq "${marker_start}" "${target_file}"; then
|
|
45
|
+
return
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
{
|
|
49
|
+
printf '\n%s\n' "${block}"
|
|
50
|
+
} >>"${target_file}"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
write_wrapper() {
|
|
54
|
+
local wrapper_path="${INSTALL_DIR}/headroom"
|
|
55
|
+
|
|
56
|
+
{
|
|
57
|
+
printf '#!%s\n\n' "${BASH_PATH}"
|
|
58
|
+
printf 'HEADROOM_IMAGE_DEFAULT=%q\n' "${INSTALL_IMAGE}"
|
|
59
|
+
cat <<'WRAPPER'
|
|
60
|
+
|
|
61
|
+
set -euo pipefail
|
|
62
|
+
|
|
63
|
+
HEADROOM_IMAGE="${HEADROOM_DOCKER_IMAGE:-${HEADROOM_IMAGE_DEFAULT}}"
|
|
64
|
+
HEADROOM_CONTAINER_HOME="${HEADROOM_CONTAINER_HOME:-/tmp/headroom-home}"
|
|
65
|
+
HEADROOM_HOST_HOME="${HOME:?}"
|
|
66
|
+
|
|
67
|
+
if ((BASH_VERSINFO[0] < 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] < 3))); then
|
|
68
|
+
printf 'ERROR: Headroom Docker-native wrapper requires bash >= 4.3\n' >&2
|
|
69
|
+
exit 1
|
|
70
|
+
fi
|
|
71
|
+
|
|
72
|
+
warn() {
|
|
73
|
+
printf 'WARN: %s\n' "$*" >&2
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
die() {
|
|
77
|
+
printf 'ERROR: %s\n' "$*" >&2
|
|
78
|
+
exit 1
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
require_cmd() {
|
|
82
|
+
command -v "$1" >/dev/null 2>&1 || die "Missing required command: $1"
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
detect_rtk_target() {
|
|
86
|
+
local system
|
|
87
|
+
local machine
|
|
88
|
+
system="$(uname -s)"
|
|
89
|
+
machine="$(uname -m)"
|
|
90
|
+
|
|
91
|
+
case "${system}" in
|
|
92
|
+
Darwin)
|
|
93
|
+
if [[ "${machine}" == "arm64" ]]; then
|
|
94
|
+
printf 'aarch64-apple-darwin'
|
|
95
|
+
else
|
|
96
|
+
printf 'x86_64-apple-darwin'
|
|
97
|
+
fi
|
|
98
|
+
;;
|
|
99
|
+
Linux)
|
|
100
|
+
if [[ "${machine}" == "aarch64" ]]; then
|
|
101
|
+
printf 'aarch64-unknown-linux-gnu'
|
|
102
|
+
else
|
|
103
|
+
printf 'x86_64-unknown-linux-musl'
|
|
104
|
+
fi
|
|
105
|
+
;;
|
|
106
|
+
*)
|
|
107
|
+
die "Unsupported host platform for Docker-native wrapper: ${system}/${machine}"
|
|
108
|
+
;;
|
|
109
|
+
esac
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
ensure_host_dirs() {
|
|
113
|
+
mkdir -p \
|
|
114
|
+
"${HEADROOM_HOST_HOME}/.headroom" \
|
|
115
|
+
"${HEADROOM_HOST_HOME}/.claude" \
|
|
116
|
+
"${HEADROOM_HOST_HOME}/.codex" \
|
|
117
|
+
"${HEADROOM_HOST_HOME}/.gemini"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
append_passthrough_envs() {
|
|
121
|
+
local -n ref=$1
|
|
122
|
+
local name
|
|
123
|
+
|
|
124
|
+
for name in $(compgen -e); do
|
|
125
|
+
case "${name}" in
|
|
126
|
+
HEADROOM_*|ANTHROPIC_*|OPENAI_*|GEMINI_*|AWS_*|AZURE_*|VERTEX_*|GOOGLE_*|GOOGLE_CLOUD_*|MISTRAL_*|GROQ_*|OPENROUTER_*|XAI_*|TOGETHER_*|COHERE_*|OLLAMA_*|LITELLM_*|OTEL_*|SUPABASE_*|QDRANT_*|NEO4J_*|LANGSMITH_*)
|
|
127
|
+
ref+=(--env "${name}")
|
|
128
|
+
;;
|
|
129
|
+
esac
|
|
130
|
+
done
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
append_common_container_args() {
|
|
134
|
+
local -n ref=$1
|
|
135
|
+
|
|
136
|
+
ensure_host_dirs
|
|
137
|
+
ref+=(-w /workspace)
|
|
138
|
+
ref+=(--env "HOME=${HEADROOM_CONTAINER_HOME}")
|
|
139
|
+
ref+=(--env "PYTHONUNBUFFERED=1")
|
|
140
|
+
# Canonical Headroom filesystem contract (issue #175) — forward into the
|
|
141
|
+
# container so the proxy resolves state/config to the bind-mounted path.
|
|
142
|
+
ref+=(--env "HEADROOM_WORKSPACE_DIR=${HEADROOM_CONTAINER_HOME}/.headroom")
|
|
143
|
+
ref+=(--env "HEADROOM_CONFIG_DIR=${HEADROOM_CONTAINER_HOME}/.headroom/config")
|
|
144
|
+
ref+=(-v "${PWD}:/workspace")
|
|
145
|
+
ref+=(-v "${HEADROOM_HOST_HOME}/.headroom:${HEADROOM_CONTAINER_HOME}/.headroom")
|
|
146
|
+
ref+=(-v "${HEADROOM_HOST_HOME}/.claude:${HEADROOM_CONTAINER_HOME}/.claude")
|
|
147
|
+
ref+=(-v "${HEADROOM_HOST_HOME}/.codex:${HEADROOM_CONTAINER_HOME}/.codex")
|
|
148
|
+
ref+=(-v "${HEADROOM_HOST_HOME}/.gemini:${HEADROOM_CONTAINER_HOME}/.gemini")
|
|
149
|
+
|
|
150
|
+
if command -v id >/dev/null 2>&1; then
|
|
151
|
+
ref+=(--user "$(id -u):$(id -g)")
|
|
152
|
+
fi
|
|
153
|
+
|
|
154
|
+
append_passthrough_envs "$1"
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
append_tty_args() {
|
|
158
|
+
local -n ref=$1
|
|
159
|
+
|
|
160
|
+
if [[ -t 0 && -t 1 ]]; then
|
|
161
|
+
ref+=(-it)
|
|
162
|
+
elif [[ -t 0 ]]; then
|
|
163
|
+
ref+=(-i)
|
|
164
|
+
elif [[ -t 1 ]]; then
|
|
165
|
+
ref+=(-t)
|
|
166
|
+
fi
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
run_headroom() {
|
|
170
|
+
local args=()
|
|
171
|
+
args=(docker run --rm)
|
|
172
|
+
append_tty_args args
|
|
173
|
+
append_common_container_args args
|
|
174
|
+
args+=(--entrypoint headroom "${HEADROOM_IMAGE}" "$@")
|
|
175
|
+
"${args[@]}"
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
docker_container_exists() {
|
|
179
|
+
local name="$1"
|
|
180
|
+
docker ps --format '{{.Names}}' | grep -Fxq "${name}"
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
wait_for_proxy() {
|
|
184
|
+
local container_name="$1"
|
|
185
|
+
local port="$2"
|
|
186
|
+
local attempt
|
|
187
|
+
|
|
188
|
+
for attempt in $(seq 1 45); do
|
|
189
|
+
if command -v curl >/dev/null 2>&1; then
|
|
190
|
+
if curl --fail --silent "http://127.0.0.1:${port}/readyz" >/dev/null; then
|
|
191
|
+
return 0
|
|
192
|
+
fi
|
|
193
|
+
elif (echo >/dev/tcp/127.0.0.1/"${port}") >/dev/null 2>&1; then
|
|
194
|
+
return 0
|
|
195
|
+
fi
|
|
196
|
+
|
|
197
|
+
if ! docker_container_exists "${container_name}"; then
|
|
198
|
+
break
|
|
199
|
+
fi
|
|
200
|
+
|
|
201
|
+
sleep 1
|
|
202
|
+
done
|
|
203
|
+
|
|
204
|
+
docker logs "${container_name}" >&2 || true
|
|
205
|
+
return 1
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
start_proxy_container() {
|
|
209
|
+
local port="$1"
|
|
210
|
+
shift
|
|
211
|
+
|
|
212
|
+
local container_name="headroom-proxy-${port}-$$"
|
|
213
|
+
local args=()
|
|
214
|
+
args=(docker run -d --rm --name "${container_name}" -p "${port}:${port}")
|
|
215
|
+
append_common_container_args args
|
|
216
|
+
args+=("${HEADROOM_IMAGE}" --host 0.0.0.0 --port "${port}" "$@")
|
|
217
|
+
"${args[@]}" >/dev/null
|
|
218
|
+
|
|
219
|
+
if ! wait_for_proxy "${container_name}" "${port}"; then
|
|
220
|
+
docker stop "${container_name}" >/dev/null 2>&1 || true
|
|
221
|
+
die "Xtream Head proxy failed to start on port ${port}"
|
|
222
|
+
fi
|
|
223
|
+
|
|
224
|
+
printf '%s\n' "${container_name}"
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
stop_proxy_container() {
|
|
228
|
+
local container_name="${1:-}"
|
|
229
|
+
if [[ -n "${container_name}" ]]; then
|
|
230
|
+
docker stop "${container_name}" >/dev/null 2>&1 || true
|
|
231
|
+
fi
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
persistent_profile_root() {
|
|
235
|
+
local profile="$1"
|
|
236
|
+
validate_profile_name "${profile}"
|
|
237
|
+
printf '%s/.headroom/deploy/%s\n' "${HEADROOM_HOST_HOME}" "${profile}"
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
persistent_state_path() {
|
|
241
|
+
local profile="$1"
|
|
242
|
+
printf '%s/docker-native.env\n' "$(persistent_profile_root "${profile}")"
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
persistent_manifest_path() {
|
|
246
|
+
local profile="$1"
|
|
247
|
+
printf '%s/manifest.json\n' "$(persistent_profile_root "${profile}")"
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
persistent_container_name() {
|
|
251
|
+
local profile="$1"
|
|
252
|
+
validate_profile_name "${profile}"
|
|
253
|
+
printf 'headroom-%s\n' "${profile}"
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
validate_profile_name() {
|
|
257
|
+
local profile="$1"
|
|
258
|
+
[[ "${profile}" =~ ^[A-Za-z0-9._-]+$ ]] || die "Invalid profile name '${profile}'"
|
|
259
|
+
[[ "${profile}" != "." && "${profile}" != ".." ]] || die "Invalid profile name '${profile}'"
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
validate_port() {
|
|
263
|
+
local port="$1"
|
|
264
|
+
[[ "${port}" =~ ^[0-9]+$ ]] || die "Invalid port '${port}'"
|
|
265
|
+
((10#${port} >= 1 && 10#${port} <= 65535)) || die "Invalid port '${port}'"
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
validate_positive_integer() {
|
|
269
|
+
local value="$1"
|
|
270
|
+
[[ "${value}" =~ ^[0-9]+$ ]] || die "Invalid value '${value}'"
|
|
271
|
+
((10#${value} >= 1)) || die "Invalid value '${value}'"
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
require_option_value() {
|
|
275
|
+
(($# >= 2)) || die "Option $1 requires a value"
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
json_escape() {
|
|
279
|
+
local value="$1"
|
|
280
|
+
value="${value//\\/\\\\}"
|
|
281
|
+
value="${value//\"/\\\"}"
|
|
282
|
+
value="${value//$'\n'/\\n}"
|
|
283
|
+
printf '%s' "${value}"
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
json_array_from_args() {
|
|
287
|
+
local first=1
|
|
288
|
+
local arg
|
|
289
|
+
printf '['
|
|
290
|
+
for arg in "$@"; do
|
|
291
|
+
if [[ "${first}" -eq 0 ]]; then
|
|
292
|
+
printf ','
|
|
293
|
+
fi
|
|
294
|
+
first=0
|
|
295
|
+
printf '"%s"' "$(json_escape "${arg}")"
|
|
296
|
+
done
|
|
297
|
+
printf ']'
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
append_persistent_container_args() {
|
|
301
|
+
local -n ref=$1
|
|
302
|
+
|
|
303
|
+
ensure_host_dirs
|
|
304
|
+
ref+=(--workdir "${HEADROOM_CONTAINER_HOME}")
|
|
305
|
+
ref+=(--env "HOME=${HEADROOM_CONTAINER_HOME}")
|
|
306
|
+
ref+=(--env "PYTHONUNBUFFERED=1")
|
|
307
|
+
# Canonical Headroom filesystem contract (issue #175).
|
|
308
|
+
ref+=(--env "HEADROOM_WORKSPACE_DIR=${HEADROOM_CONTAINER_HOME}/.headroom")
|
|
309
|
+
ref+=(--env "HEADROOM_CONFIG_DIR=${HEADROOM_CONTAINER_HOME}/.headroom/config")
|
|
310
|
+
ref+=(-v "${HEADROOM_HOST_HOME}/.headroom:${HEADROOM_CONTAINER_HOME}/.headroom")
|
|
311
|
+
ref+=(-v "${HEADROOM_HOST_HOME}/.claude:${HEADROOM_CONTAINER_HOME}/.claude")
|
|
312
|
+
ref+=(-v "${HEADROOM_HOST_HOME}/.codex:${HEADROOM_CONTAINER_HOME}/.codex")
|
|
313
|
+
ref+=(-v "${HEADROOM_HOST_HOME}/.gemini:${HEADROOM_CONTAINER_HOME}/.gemini")
|
|
314
|
+
|
|
315
|
+
if command -v id >/dev/null 2>&1; then
|
|
316
|
+
ref+=(--user "$(id -u):$(id -g)")
|
|
317
|
+
fi
|
|
318
|
+
|
|
319
|
+
append_passthrough_envs "$1"
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
build_manifest_proxy_args() {
|
|
323
|
+
local -n out_args=$1
|
|
324
|
+
local port="$2"
|
|
325
|
+
local proxy_mode="$3"
|
|
326
|
+
local backend="$4"
|
|
327
|
+
local anyllm="$5"
|
|
328
|
+
local region="$6"
|
|
329
|
+
local memory_enabled="$7"
|
|
330
|
+
local telemetry_enabled="$8"
|
|
331
|
+
|
|
332
|
+
out_args=(--host 127.0.0.1 --port "${port}" --mode "${proxy_mode}" --backend "${backend}")
|
|
333
|
+
if [[ "${telemetry_enabled}" -eq 0 ]]; then
|
|
334
|
+
out_args+=(--no-telemetry)
|
|
335
|
+
fi
|
|
336
|
+
if [[ "${memory_enabled}" -eq 1 ]]; then
|
|
337
|
+
out_args+=(--memory --memory-db-path "${HEADROOM_CONTAINER_HOME}/.headroom/memory.db")
|
|
338
|
+
fi
|
|
339
|
+
if [[ -n "${anyllm}" ]]; then
|
|
340
|
+
out_args+=(--anyllm-provider "${anyllm}")
|
|
341
|
+
fi
|
|
342
|
+
if [[ -n "${region}" ]]; then
|
|
343
|
+
out_args+=(--region "${region}")
|
|
344
|
+
fi
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
write_persistent_state() {
|
|
348
|
+
local profile="$1"
|
|
349
|
+
local image="$2"
|
|
350
|
+
local port="$3"
|
|
351
|
+
local backend="$4"
|
|
352
|
+
local anyllm="$5"
|
|
353
|
+
local region="$6"
|
|
354
|
+
local proxy_mode="$7"
|
|
355
|
+
local memory_enabled="$8"
|
|
356
|
+
local telemetry_enabled="$9"
|
|
357
|
+
|
|
358
|
+
local root
|
|
359
|
+
root="$(persistent_profile_root "${profile}")"
|
|
360
|
+
mkdir -p "${root}"
|
|
361
|
+
|
|
362
|
+
{
|
|
363
|
+
printf 'PROFILE=%s\n' "${profile}"
|
|
364
|
+
printf 'IMAGE=%s\n' "${image}"
|
|
365
|
+
printf 'PORT=%s\n' "${port}"
|
|
366
|
+
printf 'BACKEND=%s\n' "${backend}"
|
|
367
|
+
printf 'ANYLLM_PROVIDER=%s\n' "${anyllm}"
|
|
368
|
+
printf 'REGION=%s\n' "${region}"
|
|
369
|
+
printf 'PROXY_MODE=%s\n' "${proxy_mode}"
|
|
370
|
+
printf 'MEMORY_ENABLED=%s\n' "${memory_enabled}"
|
|
371
|
+
printf 'TELEMETRY_ENABLED=%s\n' "${telemetry_enabled}"
|
|
372
|
+
printf 'CONTAINER_NAME=%s\n' "$(persistent_container_name "${profile}")"
|
|
373
|
+
printf 'HEALTH_URL=%s\n' "http://127.0.0.1:${port}/readyz"
|
|
374
|
+
} >"$(persistent_state_path "${profile}")"
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
write_persistent_manifest() {
|
|
378
|
+
local profile="$1"
|
|
379
|
+
local image="$2"
|
|
380
|
+
local port="$3"
|
|
381
|
+
local backend="$4"
|
|
382
|
+
local anyllm="$5"
|
|
383
|
+
local region="$6"
|
|
384
|
+
local proxy_mode="$7"
|
|
385
|
+
local memory_enabled="$8"
|
|
386
|
+
local telemetry_enabled="$9"
|
|
387
|
+
local -n proxy_args_ref=${10}
|
|
388
|
+
|
|
389
|
+
local root
|
|
390
|
+
local manifest_path
|
|
391
|
+
local anyllm_json="null"
|
|
392
|
+
local region_json="null"
|
|
393
|
+
local memory_json="false"
|
|
394
|
+
local telemetry_json="true"
|
|
395
|
+
|
|
396
|
+
root="$(persistent_profile_root "${profile}")"
|
|
397
|
+
manifest_path="$(persistent_manifest_path "${profile}")"
|
|
398
|
+
mkdir -p "${root}"
|
|
399
|
+
|
|
400
|
+
if [[ -n "${anyllm}" ]]; then
|
|
401
|
+
anyllm_json="\"$(json_escape "${anyllm}")\""
|
|
402
|
+
fi
|
|
403
|
+
if [[ -n "${region}" ]]; then
|
|
404
|
+
region_json="\"$(json_escape "${region}")\""
|
|
405
|
+
fi
|
|
406
|
+
if [[ "${memory_enabled}" -eq 1 ]]; then
|
|
407
|
+
memory_json="true"
|
|
408
|
+
fi
|
|
409
|
+
if [[ "${telemetry_enabled}" -eq 0 ]]; then
|
|
410
|
+
telemetry_json="false"
|
|
411
|
+
fi
|
|
412
|
+
|
|
413
|
+
cat >"${manifest_path}" <<EOF
|
|
414
|
+
{
|
|
415
|
+
"profile": "$(json_escape "${profile}")",
|
|
416
|
+
"preset": "persistent-docker",
|
|
417
|
+
"runtime_kind": "docker",
|
|
418
|
+
"supervisor_kind": "none",
|
|
419
|
+
"scope": "user",
|
|
420
|
+
"provider_mode": "manual",
|
|
421
|
+
"targets": [],
|
|
422
|
+
"port": ${port},
|
|
423
|
+
"host": "127.0.0.1",
|
|
424
|
+
"backend": "$(json_escape "${backend}")",
|
|
425
|
+
"anyllm_provider": ${anyllm_json},
|
|
426
|
+
"region": ${region_json},
|
|
427
|
+
"proxy_mode": "$(json_escape "${proxy_mode}")",
|
|
428
|
+
"memory_enabled": ${memory_json},
|
|
429
|
+
"memory_db_path": "$(json_escape "${HEADROOM_CONTAINER_HOME}/.headroom/memory.db")",
|
|
430
|
+
"telemetry_enabled": ${telemetry_json},
|
|
431
|
+
"image": "$(json_escape "${image}")",
|
|
432
|
+
"service_name": "headroom-$(json_escape "${profile}")",
|
|
433
|
+
"container_name": "$(json_escape "$(persistent_container_name "${profile}")")",
|
|
434
|
+
"health_url": "http://127.0.0.1:${port}/readyz",
|
|
435
|
+
"base_env": {
|
|
436
|
+
"HEADROOM_PORT": "${port}",
|
|
437
|
+
"HEADROOM_HOST": "127.0.0.1",
|
|
438
|
+
"HEADROOM_MODE": "$(json_escape "${proxy_mode}")",
|
|
439
|
+
"HEADROOM_BACKEND": "$(json_escape "${backend}")"
|
|
440
|
+
},
|
|
441
|
+
"tool_envs": {},
|
|
442
|
+
"proxy_args": $(json_array_from_args "${proxy_args_ref[@]}"),
|
|
443
|
+
"mutations": [],
|
|
444
|
+
"artifacts": []
|
|
445
|
+
}
|
|
446
|
+
EOF
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
load_persistent_state() {
|
|
450
|
+
local profile="$1"
|
|
451
|
+
local state_path
|
|
452
|
+
validate_profile_name "${profile}"
|
|
453
|
+
state_path="$(persistent_state_path "${profile}")"
|
|
454
|
+
[[ -f "${state_path}" ]] || die "No docker-native persistent deployment profile named '${profile}'"
|
|
455
|
+
PROFILE=""
|
|
456
|
+
IMAGE=""
|
|
457
|
+
PORT=""
|
|
458
|
+
BACKEND=""
|
|
459
|
+
ANYLLM_PROVIDER=""
|
|
460
|
+
REGION=""
|
|
461
|
+
PROXY_MODE=""
|
|
462
|
+
MEMORY_ENABLED=""
|
|
463
|
+
TELEMETRY_ENABLED=""
|
|
464
|
+
CONTAINER_NAME=""
|
|
465
|
+
HEALTH_URL=""
|
|
466
|
+
while IFS='=' read -r key value; do
|
|
467
|
+
case "${key}" in
|
|
468
|
+
PROFILE|IMAGE|PORT|BACKEND|ANYLLM_PROVIDER|REGION|PROXY_MODE|MEMORY_ENABLED|TELEMETRY_ENABLED|CONTAINER_NAME|HEALTH_URL)
|
|
469
|
+
printf -v "${key}" '%s' "${value}"
|
|
470
|
+
;;
|
|
471
|
+
esac
|
|
472
|
+
done <"${state_path}"
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
start_persistent_docker_install() {
|
|
476
|
+
local profile="$1"
|
|
477
|
+
local image="$2"
|
|
478
|
+
local port="$3"
|
|
479
|
+
local backend="$4"
|
|
480
|
+
local anyllm="$5"
|
|
481
|
+
local region="$6"
|
|
482
|
+
local proxy_mode="$7"
|
|
483
|
+
local memory_enabled="$8"
|
|
484
|
+
local telemetry_enabled="$9"
|
|
485
|
+
|
|
486
|
+
local container_name
|
|
487
|
+
local proxy_args=()
|
|
488
|
+
local args=()
|
|
489
|
+
|
|
490
|
+
validate_profile_name "${profile}"
|
|
491
|
+
container_name="$(persistent_container_name "${profile}")"
|
|
492
|
+
build_manifest_proxy_args proxy_args "${port}" "${proxy_mode}" "${backend}" "${anyllm}" "${region}" "${memory_enabled}" "${telemetry_enabled}"
|
|
493
|
+
|
|
494
|
+
docker rm -f "${container_name}" >/dev/null 2>&1 || true
|
|
495
|
+
|
|
496
|
+
args=(docker run -d --restart unless-stopped --name "${container_name}" -p "${port}:${port}")
|
|
497
|
+
append_persistent_container_args args
|
|
498
|
+
args+=(
|
|
499
|
+
--env "HEADROOM_DEPLOYMENT_PROFILE=${profile}"
|
|
500
|
+
--env "HEADROOM_DEPLOYMENT_PRESET=persistent-docker"
|
|
501
|
+
--env "HEADROOM_DEPLOYMENT_RUNTIME=docker"
|
|
502
|
+
--env "HEADROOM_DEPLOYMENT_SUPERVISOR=none"
|
|
503
|
+
--env "HEADROOM_DEPLOYMENT_SCOPE=user"
|
|
504
|
+
)
|
|
505
|
+
args+=("${image}" --host 0.0.0.0 "${proxy_args[@]:2}")
|
|
506
|
+
"${args[@]}" >/dev/null
|
|
507
|
+
|
|
508
|
+
if ! wait_for_proxy "${container_name}" "${port}"; then
|
|
509
|
+
docker rm -f "${container_name}" >/dev/null 2>&1 || true
|
|
510
|
+
die "Headroom persistent Docker deployment failed to start on port ${port}"
|
|
511
|
+
fi
|
|
512
|
+
|
|
513
|
+
write_persistent_state "${profile}" "${image}" "${port}" "${backend}" "${anyllm}" "${region}" "${proxy_mode}" "${memory_enabled}" "${telemetry_enabled}"
|
|
514
|
+
write_persistent_manifest "${profile}" "${image}" "${port}" "${backend}" "${anyllm}" "${region}" "${proxy_mode}" "${memory_enabled}" "${telemetry_enabled}" proxy_args
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
stop_persistent_docker_install() {
|
|
518
|
+
local profile="$1"
|
|
519
|
+
local container_name
|
|
520
|
+
|
|
521
|
+
load_persistent_state "${profile}"
|
|
522
|
+
container_name="${CONTAINER_NAME}"
|
|
523
|
+
docker stop "${container_name}" >/dev/null 2>&1 || true
|
|
524
|
+
docker rm -f "${container_name}" >/dev/null 2>&1 || true
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
status_persistent_docker_install() {
|
|
528
|
+
local profile="$1"
|
|
529
|
+
local status="stopped"
|
|
530
|
+
local ready="no"
|
|
531
|
+
|
|
532
|
+
load_persistent_state "${profile}"
|
|
533
|
+
if docker_container_exists "${CONTAINER_NAME}"; then
|
|
534
|
+
status="running"
|
|
535
|
+
if command -v curl >/dev/null 2>&1; then
|
|
536
|
+
if curl --fail --silent "${HEALTH_URL}" >/dev/null; then
|
|
537
|
+
ready="yes"
|
|
538
|
+
fi
|
|
539
|
+
elif (echo >/dev/tcp/127.0.0.1/"${PORT}") >/dev/null 2>&1; then
|
|
540
|
+
ready="yes"
|
|
541
|
+
fi
|
|
542
|
+
fi
|
|
543
|
+
|
|
544
|
+
printf 'Profile: %s\n' "${PROFILE}"
|
|
545
|
+
printf 'Preset: persistent-docker\n'
|
|
546
|
+
printf 'Runtime: docker\n'
|
|
547
|
+
printf 'Supervisor: none\n'
|
|
548
|
+
printf 'Port: %s\n' "${PORT}"
|
|
549
|
+
printf 'Status: %s\n' "${status}"
|
|
550
|
+
printf 'Ready: %s\n' "${ready}"
|
|
551
|
+
printf 'Health URL: %s\n' "${HEALTH_URL}"
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
remove_persistent_docker_install() {
|
|
555
|
+
local profile="$1"
|
|
556
|
+
local root
|
|
557
|
+
|
|
558
|
+
load_persistent_state "${profile}"
|
|
559
|
+
docker stop "${CONTAINER_NAME}" >/dev/null 2>&1 || true
|
|
560
|
+
docker rm -f "${CONTAINER_NAME}" >/dev/null 2>&1 || true
|
|
561
|
+
root="$(persistent_profile_root "${profile}")"
|
|
562
|
+
rm -rf "${root}"
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
print_install_help() {
|
|
566
|
+
cat <<'EOF'
|
|
567
|
+
Usage: xtream-head install [OPTIONS] COMMAND [ARGS]...
|
|
568
|
+
|
|
569
|
+
Manage persistent Docker-native Headroom deployments.
|
|
570
|
+
|
|
571
|
+
The Docker-native wrapper currently supports the persistent-docker preset only.
|
|
572
|
+
Use the Python-native `xtream-head install` command for persistent-service and
|
|
573
|
+
persistent-task installs, or when you need provider/user/system config mutation.
|
|
574
|
+
|
|
575
|
+
Options:
|
|
576
|
+
-?, --help Show this message and exit.
|
|
577
|
+
|
|
578
|
+
Commands:
|
|
579
|
+
apply Install a persistent Docker deployment.
|
|
580
|
+
remove Remove a persistent Docker deployment.
|
|
581
|
+
restart Restart a persistent Docker deployment.
|
|
582
|
+
start Start a persistent Docker deployment.
|
|
583
|
+
status Show persistent Docker deployment status.
|
|
584
|
+
stop Stop a persistent Docker deployment.
|
|
585
|
+
EOF
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
print_install_apply_help() {
|
|
589
|
+
cat <<'EOF'
|
|
590
|
+
Usage: xtream-head install apply [OPTIONS]
|
|
591
|
+
|
|
592
|
+
Install a persistent Docker deployment.
|
|
593
|
+
|
|
594
|
+
Options:
|
|
595
|
+
--preset [persistent-docker] Docker-native wrapper supports persistent-docker only.
|
|
596
|
+
--runtime [docker] Docker-native wrapper supports runtime=docker only.
|
|
597
|
+
--profile TEXT Deployment profile name. [default: default]
|
|
598
|
+
-p, --port INTEGER Persistent proxy port. [default: 8787]
|
|
599
|
+
--backend TEXT Proxy backend. [default: anthropic]
|
|
600
|
+
--anyllm-provider TEXT Provider for any-llm backends.
|
|
601
|
+
--region TEXT Cloud region for Bedrock / Vertex style backends.
|
|
602
|
+
--mode TEXT Proxy optimization mode. [default: token]
|
|
603
|
+
--memory Enable persistent memory in the runtime.
|
|
604
|
+
--no-telemetry Disable anonymous telemetry in the runtime.
|
|
605
|
+
--image TEXT Docker image to use. [default: HEADROOM_DOCKER_IMAGE or ghcr.io/chopratejas/headroom:latest]
|
|
606
|
+
-?, --help Show this message and exit.
|
|
607
|
+
EOF
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
print_wrap_help() {
|
|
611
|
+
cat <<'EOF'
|
|
612
|
+
Usage: xtream-head wrap <COMMAND> [OPTIONS] [-- ARGS...]
|
|
613
|
+
|
|
614
|
+
Launch supported host tools through a Docker-native Xtream Head proxy.
|
|
615
|
+
|
|
616
|
+
Supported commands:
|
|
617
|
+
claude
|
|
618
|
+
codex
|
|
619
|
+
aider
|
|
620
|
+
cursor
|
|
621
|
+
openclaw
|
|
622
|
+
|
|
623
|
+
Notes:
|
|
624
|
+
- GitHub Copilot CLI wrapping is not supported by the Docker-native wrapper.
|
|
625
|
+
- Use the Python-native CLI for unsupported wrap targets.
|
|
626
|
+
EOF
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
parse_install_apply_args() {
|
|
630
|
+
local -n out_profile=$1
|
|
631
|
+
local -n out_port=$2
|
|
632
|
+
local -n out_backend=$3
|
|
633
|
+
local -n out_anyllm=$4
|
|
634
|
+
local -n out_region=$5
|
|
635
|
+
local -n out_mode=$6
|
|
636
|
+
local -n out_memory=$7
|
|
637
|
+
local -n out_telemetry=$8
|
|
638
|
+
local -n out_image=$9
|
|
639
|
+
shift 9
|
|
640
|
+
|
|
641
|
+
out_profile="default"
|
|
642
|
+
out_port=8787
|
|
643
|
+
out_backend="anthropic"
|
|
644
|
+
out_anyllm=""
|
|
645
|
+
out_region=""
|
|
646
|
+
out_mode="token"
|
|
647
|
+
out_memory=0
|
|
648
|
+
out_telemetry=1
|
|
649
|
+
out_image="${HEADROOM_IMAGE}"
|
|
650
|
+
|
|
651
|
+
while (($#)); do
|
|
652
|
+
case "$1" in
|
|
653
|
+
--preset)
|
|
654
|
+
require_option_value "$@"
|
|
655
|
+
[[ "$2" == "persistent-docker" ]] || die "Docker-native wrapper supports only --preset persistent-docker"
|
|
656
|
+
shift 2
|
|
657
|
+
;;
|
|
658
|
+
--preset=*)
|
|
659
|
+
[[ "${1#*=}" == "persistent-docker" ]] || die "Docker-native wrapper supports only --preset persistent-docker"
|
|
660
|
+
shift
|
|
661
|
+
;;
|
|
662
|
+
--runtime)
|
|
663
|
+
require_option_value "$@"
|
|
664
|
+
[[ "$2" == "docker" ]] || die "Docker-native wrapper supports only --runtime docker"
|
|
665
|
+
shift 2
|
|
666
|
+
;;
|
|
667
|
+
--runtime=*)
|
|
668
|
+
[[ "${1#*=}" == "docker" ]] || die "Docker-native wrapper supports only --runtime docker"
|
|
669
|
+
shift
|
|
670
|
+
;;
|
|
671
|
+
--scope|--providers|--target)
|
|
672
|
+
die "Docker-native wrapper install does not support provider/user/system mutation flags; use the Python-native CLI for those flows"
|
|
673
|
+
;;
|
|
674
|
+
--scope=*|--providers=*|--target=*)
|
|
675
|
+
die "Docker-native wrapper install does not support provider/user/system mutation flags; use the Python-native CLI for those flows"
|
|
676
|
+
;;
|
|
677
|
+
--profile)
|
|
678
|
+
require_option_value "$@"
|
|
679
|
+
out_profile="$2"
|
|
680
|
+
shift 2
|
|
681
|
+
;;
|
|
682
|
+
--profile=*)
|
|
683
|
+
out_profile="${1#*=}"
|
|
684
|
+
shift
|
|
685
|
+
;;
|
|
686
|
+
--port|-p)
|
|
687
|
+
require_option_value "$@"
|
|
688
|
+
out_port="$2"
|
|
689
|
+
shift 2
|
|
690
|
+
;;
|
|
691
|
+
--port=*|-p=*)
|
|
692
|
+
out_port="${1#*=}"
|
|
693
|
+
shift
|
|
694
|
+
;;
|
|
695
|
+
--backend)
|
|
696
|
+
require_option_value "$@"
|
|
697
|
+
out_backend="$2"
|
|
698
|
+
shift 2
|
|
699
|
+
;;
|
|
700
|
+
--backend=*)
|
|
701
|
+
out_backend="${1#*=}"
|
|
702
|
+
shift
|
|
703
|
+
;;
|
|
704
|
+
--anyllm-provider)
|
|
705
|
+
require_option_value "$@"
|
|
706
|
+
out_anyllm="$2"
|
|
707
|
+
shift 2
|
|
708
|
+
;;
|
|
709
|
+
--anyllm-provider=*)
|
|
710
|
+
out_anyllm="${1#*=}"
|
|
711
|
+
shift
|
|
712
|
+
;;
|
|
713
|
+
--region)
|
|
714
|
+
require_option_value "$@"
|
|
715
|
+
out_region="$2"
|
|
716
|
+
shift 2
|
|
717
|
+
;;
|
|
718
|
+
--region=*)
|
|
719
|
+
out_region="${1#*=}"
|
|
720
|
+
shift
|
|
721
|
+
;;
|
|
722
|
+
--mode)
|
|
723
|
+
require_option_value "$@"
|
|
724
|
+
out_mode="$2"
|
|
725
|
+
shift 2
|
|
726
|
+
;;
|
|
727
|
+
--mode=*)
|
|
728
|
+
out_mode="${1#*=}"
|
|
729
|
+
shift
|
|
730
|
+
;;
|
|
731
|
+
--memory)
|
|
732
|
+
out_memory=1
|
|
733
|
+
shift
|
|
734
|
+
;;
|
|
735
|
+
--no-telemetry)
|
|
736
|
+
out_telemetry=0
|
|
737
|
+
shift
|
|
738
|
+
;;
|
|
739
|
+
--image)
|
|
740
|
+
require_option_value "$@"
|
|
741
|
+
out_image="$2"
|
|
742
|
+
shift 2
|
|
743
|
+
;;
|
|
744
|
+
--image=*)
|
|
745
|
+
out_image="${1#*=}"
|
|
746
|
+
shift
|
|
747
|
+
;;
|
|
748
|
+
--help|-?)
|
|
749
|
+
print_install_apply_help
|
|
750
|
+
exit 0
|
|
751
|
+
;;
|
|
752
|
+
*)
|
|
753
|
+
die "Unsupported option for 'xtream-head install apply': $1"
|
|
754
|
+
;;
|
|
755
|
+
esac
|
|
756
|
+
done
|
|
757
|
+
|
|
758
|
+
validate_port "${out_port}"
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
parse_install_profile_arg() {
|
|
762
|
+
local -n out_profile=$1
|
|
763
|
+
shift
|
|
764
|
+
|
|
765
|
+
out_profile="default"
|
|
766
|
+
while (($#)); do
|
|
767
|
+
case "$1" in
|
|
768
|
+
--profile)
|
|
769
|
+
require_option_value "$@"
|
|
770
|
+
out_profile="$2"
|
|
771
|
+
shift 2
|
|
772
|
+
;;
|
|
773
|
+
--profile=*)
|
|
774
|
+
out_profile="${1#*=}"
|
|
775
|
+
shift
|
|
776
|
+
;;
|
|
777
|
+
--help|-?)
|
|
778
|
+
print_install_help
|
|
779
|
+
exit 0
|
|
780
|
+
;;
|
|
781
|
+
*)
|
|
782
|
+
die "Unsupported option for 'xtream-head install': $1"
|
|
783
|
+
;;
|
|
784
|
+
esac
|
|
785
|
+
done
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
run_claude_rtk_init() {
|
|
789
|
+
local rtk_bin="${HEADROOM_HOST_HOME}/.headroom/bin/rtk"
|
|
790
|
+
if [[ ! -x "${rtk_bin}" ]]; then
|
|
791
|
+
warn "rtk was not installed at ${rtk_bin}; Claude hooks were not registered"
|
|
792
|
+
return
|
|
793
|
+
fi
|
|
794
|
+
|
|
795
|
+
if ! "${rtk_bin}" init --global --auto-patch >/dev/null 2>&1; then
|
|
796
|
+
warn "Failed to register Claude hooks with rtk; continuing without hook registration"
|
|
797
|
+
fi
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
selected_context_tool() {
|
|
801
|
+
local value="${HEADROOM_CONTEXT_TOOL:-rtk}"
|
|
802
|
+
value="${value,,}"
|
|
803
|
+
value="${value//_/-}"
|
|
804
|
+
if [[ -z "${value}" ]]; then
|
|
805
|
+
value="rtk"
|
|
806
|
+
elif [[ "${value}" == "leanctx" ]]; then
|
|
807
|
+
value="lean-ctx"
|
|
808
|
+
fi
|
|
809
|
+
|
|
810
|
+
case "${value}" in
|
|
811
|
+
rtk|lean-ctx)
|
|
812
|
+
printf '%s\n' "${value}"
|
|
813
|
+
;;
|
|
814
|
+
*)
|
|
815
|
+
die "HEADROOM_CONTEXT_TOOL must be one of: lean-ctx, rtk"
|
|
816
|
+
;;
|
|
817
|
+
esac
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
run_lean_ctx_init() {
|
|
821
|
+
local agent="$1"
|
|
822
|
+
if ! command -v lean-ctx >/dev/null 2>&1; then
|
|
823
|
+
warn "lean-ctx is not installed on PATH; ${agent} lean-ctx setup was skipped"
|
|
824
|
+
return
|
|
825
|
+
fi
|
|
826
|
+
|
|
827
|
+
if ! lean-ctx init --agent "${agent}" >/dev/null 2>&1; then
|
|
828
|
+
warn "Failed to initialize lean-ctx for ${agent}; continuing without lean-ctx setup"
|
|
829
|
+
fi
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
parse_wrap_args() {
|
|
833
|
+
local -n out_known=$1
|
|
834
|
+
local -n out_host=$2
|
|
835
|
+
local -n out_port=$3
|
|
836
|
+
local -n out_no_rtk=$4
|
|
837
|
+
local -n out_no_proxy=$5
|
|
838
|
+
local -n out_learn=$6
|
|
839
|
+
local -n out_backend=$7
|
|
840
|
+
local -n out_anyllm=$8
|
|
841
|
+
local -n out_region=$9
|
|
842
|
+
shift 9
|
|
843
|
+
|
|
844
|
+
out_known=()
|
|
845
|
+
out_host=()
|
|
846
|
+
out_port=8787
|
|
847
|
+
out_no_rtk=0
|
|
848
|
+
out_no_proxy=0
|
|
849
|
+
out_learn=0
|
|
850
|
+
out_backend=""
|
|
851
|
+
out_anyllm=""
|
|
852
|
+
out_region=""
|
|
853
|
+
|
|
854
|
+
while (($#)); do
|
|
855
|
+
case "$1" in
|
|
856
|
+
--)
|
|
857
|
+
shift
|
|
858
|
+
out_host+=("$@")
|
|
859
|
+
break
|
|
860
|
+
;;
|
|
861
|
+
--port|-p)
|
|
862
|
+
require_option_value "$@"
|
|
863
|
+
out_port="$2"
|
|
864
|
+
validate_port "${out_port}"
|
|
865
|
+
out_known+=("$1" "$2")
|
|
866
|
+
shift 2
|
|
867
|
+
;;
|
|
868
|
+
--port=*)
|
|
869
|
+
out_port="${1#*=}"
|
|
870
|
+
validate_port "${out_port}"
|
|
871
|
+
out_known+=("$1")
|
|
872
|
+
shift
|
|
873
|
+
;;
|
|
874
|
+
--no-rtk)
|
|
875
|
+
out_no_rtk=1
|
|
876
|
+
out_known+=("$1")
|
|
877
|
+
shift
|
|
878
|
+
;;
|
|
879
|
+
--no-proxy)
|
|
880
|
+
out_no_proxy=1
|
|
881
|
+
out_known+=("$1")
|
|
882
|
+
shift
|
|
883
|
+
;;
|
|
884
|
+
--learn)
|
|
885
|
+
out_learn=1
|
|
886
|
+
out_known+=("$1")
|
|
887
|
+
shift
|
|
888
|
+
;;
|
|
889
|
+
--verbose|-v)
|
|
890
|
+
out_known+=("$1")
|
|
891
|
+
shift
|
|
892
|
+
;;
|
|
893
|
+
--backend)
|
|
894
|
+
require_option_value "$@"
|
|
895
|
+
out_backend="$2"
|
|
896
|
+
out_known+=("$1" "$2")
|
|
897
|
+
shift 2
|
|
898
|
+
;;
|
|
899
|
+
--backend=*)
|
|
900
|
+
out_backend="${1#*=}"
|
|
901
|
+
out_known+=("$1")
|
|
902
|
+
shift
|
|
903
|
+
;;
|
|
904
|
+
--anyllm-provider)
|
|
905
|
+
require_option_value "$@"
|
|
906
|
+
out_anyllm="$2"
|
|
907
|
+
out_known+=("$1" "$2")
|
|
908
|
+
shift 2
|
|
909
|
+
;;
|
|
910
|
+
--anyllm-provider=*)
|
|
911
|
+
out_anyllm="${1#*=}"
|
|
912
|
+
out_known+=("$1")
|
|
913
|
+
shift
|
|
914
|
+
;;
|
|
915
|
+
--region)
|
|
916
|
+
require_option_value "$@"
|
|
917
|
+
out_region="$2"
|
|
918
|
+
out_known+=("$1" "$2")
|
|
919
|
+
shift 2
|
|
920
|
+
;;
|
|
921
|
+
--region=*)
|
|
922
|
+
out_region="${1#*=}"
|
|
923
|
+
out_known+=("$1")
|
|
924
|
+
shift
|
|
925
|
+
;;
|
|
926
|
+
*)
|
|
927
|
+
out_host+=("$@")
|
|
928
|
+
break
|
|
929
|
+
;;
|
|
930
|
+
esac
|
|
931
|
+
done
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
run_prepare_only() {
|
|
935
|
+
local tool="$1"
|
|
936
|
+
shift
|
|
937
|
+
|
|
938
|
+
local args=()
|
|
939
|
+
args=(docker run --rm)
|
|
940
|
+
append_tty_args args
|
|
941
|
+
append_common_container_args args
|
|
942
|
+
args+=(--env "HEADROOM_RTK_TARGET=$(detect_rtk_target)")
|
|
943
|
+
args+=(--entrypoint headroom "${HEADROOM_IMAGE}" wrap "${tool}" --prepare-only "$@")
|
|
944
|
+
"${args[@]}"
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
run_host_tool() {
|
|
948
|
+
local binary="$1"
|
|
949
|
+
shift
|
|
950
|
+
|
|
951
|
+
command -v "${binary}" >/dev/null 2>&1 || die "'${binary}' not found in PATH"
|
|
952
|
+
"${binary}" "$@"
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
contains_help_flag() {
|
|
956
|
+
local arg
|
|
957
|
+
for arg in "$@"; do
|
|
958
|
+
if [[ "${arg}" == "--" ]]; then
|
|
959
|
+
break
|
|
960
|
+
fi
|
|
961
|
+
if [[ "${arg}" == "--help" || "${arg}" == "-?" ]]; then
|
|
962
|
+
return 0
|
|
963
|
+
fi
|
|
964
|
+
done
|
|
965
|
+
|
|
966
|
+
return 1
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
parse_openclaw_wrap_args() {
|
|
970
|
+
local -n out_plugin_path=$1
|
|
971
|
+
local -n out_plugin_spec=$2
|
|
972
|
+
local -n out_skip_build=$3
|
|
973
|
+
local -n out_copy=$4
|
|
974
|
+
local -n out_proxy_port=$5
|
|
975
|
+
local -n out_startup_timeout_ms=$6
|
|
976
|
+
local -n out_gateway_provider_ids=$7
|
|
977
|
+
local -n out_python_path=$8
|
|
978
|
+
local -n out_no_auto_start=$9
|
|
979
|
+
local -n out_no_restart=${10}
|
|
980
|
+
local -n out_verbose=${11}
|
|
981
|
+
shift 11
|
|
982
|
+
|
|
983
|
+
out_plugin_path=""
|
|
984
|
+
out_plugin_spec="xtream-head/openclaw"
|
|
985
|
+
out_skip_build=0
|
|
986
|
+
out_copy=0
|
|
987
|
+
out_proxy_port=8787
|
|
988
|
+
out_startup_timeout_ms=20000
|
|
989
|
+
out_gateway_provider_ids=()
|
|
990
|
+
out_python_path=""
|
|
991
|
+
out_no_auto_start=0
|
|
992
|
+
out_no_restart=0
|
|
993
|
+
out_verbose=0
|
|
994
|
+
|
|
995
|
+
while (($#)); do
|
|
996
|
+
case "$1" in
|
|
997
|
+
--plugin-path)
|
|
998
|
+
require_option_value "$@"
|
|
999
|
+
out_plugin_path="$2"
|
|
1000
|
+
shift 2
|
|
1001
|
+
;;
|
|
1002
|
+
--plugin-path=*)
|
|
1003
|
+
out_plugin_path="${1#*=}"
|
|
1004
|
+
shift
|
|
1005
|
+
;;
|
|
1006
|
+
--plugin-spec)
|
|
1007
|
+
require_option_value "$@"
|
|
1008
|
+
out_plugin_spec="$2"
|
|
1009
|
+
shift 2
|
|
1010
|
+
;;
|
|
1011
|
+
--plugin-spec=*)
|
|
1012
|
+
out_plugin_spec="${1#*=}"
|
|
1013
|
+
shift
|
|
1014
|
+
;;
|
|
1015
|
+
--skip-build)
|
|
1016
|
+
out_skip_build=1
|
|
1017
|
+
shift
|
|
1018
|
+
;;
|
|
1019
|
+
--copy)
|
|
1020
|
+
out_copy=1
|
|
1021
|
+
shift
|
|
1022
|
+
;;
|
|
1023
|
+
--proxy-port)
|
|
1024
|
+
require_option_value "$@"
|
|
1025
|
+
out_proxy_port="$2"
|
|
1026
|
+
validate_port "${out_proxy_port}"
|
|
1027
|
+
shift 2
|
|
1028
|
+
;;
|
|
1029
|
+
--proxy-port=*)
|
|
1030
|
+
out_proxy_port="${1#*=}"
|
|
1031
|
+
validate_port "${out_proxy_port}"
|
|
1032
|
+
shift
|
|
1033
|
+
;;
|
|
1034
|
+
--startup-timeout-ms)
|
|
1035
|
+
require_option_value "$@"
|
|
1036
|
+
out_startup_timeout_ms="$2"
|
|
1037
|
+
validate_positive_integer "${out_startup_timeout_ms}"
|
|
1038
|
+
shift 2
|
|
1039
|
+
;;
|
|
1040
|
+
--startup-timeout-ms=*)
|
|
1041
|
+
out_startup_timeout_ms="${1#*=}"
|
|
1042
|
+
validate_positive_integer "${out_startup_timeout_ms}"
|
|
1043
|
+
shift
|
|
1044
|
+
;;
|
|
1045
|
+
--gateway-provider-id)
|
|
1046
|
+
require_option_value "$@"
|
|
1047
|
+
out_gateway_provider_ids+=("$2")
|
|
1048
|
+
shift 2
|
|
1049
|
+
;;
|
|
1050
|
+
--gateway-provider-id=*)
|
|
1051
|
+
out_gateway_provider_ids+=("${1#*=}")
|
|
1052
|
+
shift
|
|
1053
|
+
;;
|
|
1054
|
+
--python-path)
|
|
1055
|
+
require_option_value "$@"
|
|
1056
|
+
out_python_path="$2"
|
|
1057
|
+
shift 2
|
|
1058
|
+
;;
|
|
1059
|
+
--python-path=*)
|
|
1060
|
+
out_python_path="${1#*=}"
|
|
1061
|
+
shift
|
|
1062
|
+
;;
|
|
1063
|
+
--no-auto-start)
|
|
1064
|
+
out_no_auto_start=1
|
|
1065
|
+
shift
|
|
1066
|
+
;;
|
|
1067
|
+
--no-restart)
|
|
1068
|
+
out_no_restart=1
|
|
1069
|
+
shift
|
|
1070
|
+
;;
|
|
1071
|
+
--verbose|-v)
|
|
1072
|
+
out_verbose=1
|
|
1073
|
+
shift
|
|
1074
|
+
;;
|
|
1075
|
+
*)
|
|
1076
|
+
die "Unsupported option for 'xtream-head wrap openclaw': $1"
|
|
1077
|
+
;;
|
|
1078
|
+
esac
|
|
1079
|
+
done
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
parse_openclaw_unwrap_args() {
|
|
1083
|
+
local -n out_no_restart=$1
|
|
1084
|
+
local -n out_verbose=$2
|
|
1085
|
+
shift 2
|
|
1086
|
+
|
|
1087
|
+
out_no_restart=0
|
|
1088
|
+
out_verbose=0
|
|
1089
|
+
|
|
1090
|
+
while (($#)); do
|
|
1091
|
+
case "$1" in
|
|
1092
|
+
--no-restart)
|
|
1093
|
+
out_no_restart=1
|
|
1094
|
+
shift
|
|
1095
|
+
;;
|
|
1096
|
+
--verbose|-v)
|
|
1097
|
+
out_verbose=1
|
|
1098
|
+
shift
|
|
1099
|
+
;;
|
|
1100
|
+
*)
|
|
1101
|
+
die "Unsupported option for 'xtream-head unwrap openclaw': $1"
|
|
1102
|
+
;;
|
|
1103
|
+
esac
|
|
1104
|
+
done
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
get_openclaw_existing_entry_json() {
|
|
1108
|
+
local output=""
|
|
1109
|
+
if output="$(openclaw config get plugins.entries.headroom 2>/dev/null)"; then
|
|
1110
|
+
printf '%s' "${output}"
|
|
1111
|
+
fi
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
prepare_openclaw_entry_json() {
|
|
1115
|
+
local existing_entry_json="$1"
|
|
1116
|
+
local proxy_port="$2"
|
|
1117
|
+
local startup_timeout_ms="$3"
|
|
1118
|
+
local python_path="$4"
|
|
1119
|
+
local no_auto_start="$5"
|
|
1120
|
+
shift 5
|
|
1121
|
+
local gateway_provider_ids=("$@")
|
|
1122
|
+
local args=()
|
|
1123
|
+
args=(docker run --rm)
|
|
1124
|
+
append_common_container_args args
|
|
1125
|
+
args+=(--entrypoint headroom "${HEADROOM_IMAGE}" wrap openclaw --prepare-only)
|
|
1126
|
+
args+=(--proxy-port "${proxy_port}" --startup-timeout-ms "${startup_timeout_ms}")
|
|
1127
|
+
|
|
1128
|
+
if [[ -n "${existing_entry_json}" ]]; then
|
|
1129
|
+
args+=(--existing-entry-json "${existing_entry_json}")
|
|
1130
|
+
fi
|
|
1131
|
+
if [[ -n "${python_path}" ]]; then
|
|
1132
|
+
args+=(--python-path "${python_path}")
|
|
1133
|
+
fi
|
|
1134
|
+
if [[ "${no_auto_start}" -eq 1 ]]; then
|
|
1135
|
+
args+=(--no-auto-start)
|
|
1136
|
+
fi
|
|
1137
|
+
|
|
1138
|
+
local provider_id
|
|
1139
|
+
for provider_id in "${gateway_provider_ids[@]}"; do
|
|
1140
|
+
args+=(--gateway-provider-id "${provider_id}")
|
|
1141
|
+
done
|
|
1142
|
+
|
|
1143
|
+
"${args[@]}"
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
prepare_openclaw_unwrap_entry_json() {
|
|
1147
|
+
local existing_entry_json="$1"
|
|
1148
|
+
local args=()
|
|
1149
|
+
args=(docker run --rm)
|
|
1150
|
+
append_common_container_args args
|
|
1151
|
+
args+=(--entrypoint headroom "${HEADROOM_IMAGE}" unwrap openclaw --prepare-only)
|
|
1152
|
+
if [[ -n "${existing_entry_json}" ]]; then
|
|
1153
|
+
args+=(--existing-entry-json "${existing_entry_json}")
|
|
1154
|
+
fi
|
|
1155
|
+
"${args[@]}"
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
run_openclaw_checked() {
|
|
1159
|
+
local action="$1"
|
|
1160
|
+
shift
|
|
1161
|
+
local output=""
|
|
1162
|
+
|
|
1163
|
+
if ! output="$("$@" 2>&1)"; then
|
|
1164
|
+
output="${output//$'\r'/}"
|
|
1165
|
+
die "${action} failed: ${output:-unknown error}"
|
|
1166
|
+
fi
|
|
1167
|
+
|
|
1168
|
+
printf '%s' "${output//$'\r'/}"
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
run_openclaw_checked_in_dir() {
|
|
1172
|
+
local action="$1"
|
|
1173
|
+
local cwd="$2"
|
|
1174
|
+
shift 2
|
|
1175
|
+
local output=""
|
|
1176
|
+
|
|
1177
|
+
if ! output="$(cd "${cwd}" && "$@" 2>&1)"; then
|
|
1178
|
+
output="${output//$'\r'/}"
|
|
1179
|
+
die "${action} failed: ${output:-unknown error}"
|
|
1180
|
+
fi
|
|
1181
|
+
|
|
1182
|
+
printf '%s' "${output//$'\r'/}"
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
resolve_openclaw_extensions_dir() {
|
|
1186
|
+
local config_output
|
|
1187
|
+
config_output="$(run_openclaw_checked "openclaw config file" openclaw config file)"
|
|
1188
|
+
local config_path
|
|
1189
|
+
config_path="$(printf '%s\n' "${config_output}" | tail -n 1)"
|
|
1190
|
+
[[ -n "${config_path}" ]] || die "Unable to resolve OpenClaw config path."
|
|
1191
|
+
printf '%s\n' "$(dirname "${config_path}")/extensions"
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
copy_openclaw_plugin_into_extensions() {
|
|
1195
|
+
local plugin_dir="$1"
|
|
1196
|
+
local dist_dir="${plugin_dir}/dist"
|
|
1197
|
+
local hook_shim_dir="${plugin_dir}/hook-shim"
|
|
1198
|
+
[[ -d "${dist_dir}" ]] || die "Plugin dist folder missing at ${dist_dir}. Build the plugin first."
|
|
1199
|
+
[[ -d "${hook_shim_dir}" ]] || die "Plugin hook-shim folder missing at ${hook_shim_dir}. Build the plugin first."
|
|
1200
|
+
|
|
1201
|
+
local extensions_dir
|
|
1202
|
+
extensions_dir="$(resolve_openclaw_extensions_dir)"
|
|
1203
|
+
local target_dir="${extensions_dir}/headroom"
|
|
1204
|
+
mkdir -p "${target_dir}"
|
|
1205
|
+
rm -rf "${target_dir}/dist" "${target_dir}/hook-shim"
|
|
1206
|
+
cp -R "${dist_dir}" "${target_dir}/dist"
|
|
1207
|
+
cp -R "${hook_shim_dir}" "${target_dir}/hook-shim"
|
|
1208
|
+
|
|
1209
|
+
local filename
|
|
1210
|
+
for filename in openclaw.plugin.json package.json README.md; do
|
|
1211
|
+
if [[ -f "${plugin_dir}/${filename}" ]]; then
|
|
1212
|
+
cp "${plugin_dir}/${filename}" "${target_dir}/${filename}"
|
|
1213
|
+
fi
|
|
1214
|
+
done
|
|
1215
|
+
|
|
1216
|
+
printf '%s\n' "${target_dir}"
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
install_openclaw_plugin() {
|
|
1220
|
+
local plugin_path="$1"
|
|
1221
|
+
local plugin_spec="$2"
|
|
1222
|
+
local skip_build="$3"
|
|
1223
|
+
local copy_mode="$4"
|
|
1224
|
+
local verbose="$5"
|
|
1225
|
+
|
|
1226
|
+
local local_source_mode=0
|
|
1227
|
+
if [[ -n "${plugin_path}" ]]; then
|
|
1228
|
+
local_source_mode=1
|
|
1229
|
+
[[ -d "${plugin_path}" ]] || die "Plugin path not found: ${plugin_path}."
|
|
1230
|
+
[[ -f "${plugin_path}/package.json" ]] || die "Invalid plugin path (missing package.json): ${plugin_path}"
|
|
1231
|
+
[[ -f "${plugin_path}/openclaw.plugin.json" ]] || die "Invalid plugin path (missing openclaw.plugin.json): ${plugin_path}"
|
|
1232
|
+
fi
|
|
1233
|
+
|
|
1234
|
+
if [[ "${local_source_mode}" -eq 1 && "${skip_build}" -eq 0 ]]; then
|
|
1235
|
+
require_cmd npm
|
|
1236
|
+
info "Building OpenClaw plugin (npm install + npm run build)..."
|
|
1237
|
+
run_openclaw_checked_in_dir "npm install" "${plugin_path}" npm install >/dev/null
|
|
1238
|
+
run_openclaw_checked_in_dir "npm run build" "${plugin_path}" npm run build >/dev/null
|
|
1239
|
+
fi
|
|
1240
|
+
|
|
1241
|
+
local install_output=""
|
|
1242
|
+
local install_status=0
|
|
1243
|
+
set +e
|
|
1244
|
+
if [[ "${local_source_mode}" -eq 1 ]]; then
|
|
1245
|
+
if [[ "${copy_mode}" -eq 1 ]]; then
|
|
1246
|
+
install_output="$(openclaw plugins install --dangerously-force-unsafe-install "${plugin_path}" 2>&1)"
|
|
1247
|
+
install_status=$?
|
|
1248
|
+
else
|
|
1249
|
+
install_output="$(cd "${plugin_path}" && openclaw plugins install --dangerously-force-unsafe-install --link . 2>&1)"
|
|
1250
|
+
install_status=$?
|
|
1251
|
+
fi
|
|
1252
|
+
else
|
|
1253
|
+
install_output="$(openclaw plugins install --dangerously-force-unsafe-install "${plugin_spec}" 2>&1)"
|
|
1254
|
+
install_status=$?
|
|
1255
|
+
fi
|
|
1256
|
+
set -e
|
|
1257
|
+
install_output="${install_output//$'\r'/}"
|
|
1258
|
+
|
|
1259
|
+
if [[ "${install_status}" -eq 0 ]]; then
|
|
1260
|
+
if [[ "${verbose}" -eq 1 && -n "${install_output}" ]]; then
|
|
1261
|
+
printf '%s\n' "${install_output}"
|
|
1262
|
+
fi
|
|
1263
|
+
return
|
|
1264
|
+
fi
|
|
1265
|
+
|
|
1266
|
+
local lower_output="${install_output,,}"
|
|
1267
|
+
if [[ "${lower_output}" == *"plugin already exists"* ]]; then
|
|
1268
|
+
info "Plugin already installed; continuing with configuration/update steps."
|
|
1269
|
+
return
|
|
1270
|
+
fi
|
|
1271
|
+
|
|
1272
|
+
if [[ "${lower_output}" == *"also not a valid hook pack"* && "${local_source_mode}" -eq 1 && "${copy_mode}" -eq 0 ]]; then
|
|
1273
|
+
info "OpenClaw linked-path install bug detected; applying extension-path fallback..."
|
|
1274
|
+
local target_dir
|
|
1275
|
+
target_dir="$(copy_openclaw_plugin_into_extensions "${plugin_path}")"
|
|
1276
|
+
info "Fallback plugin copy completed: ${target_dir}"
|
|
1277
|
+
return
|
|
1278
|
+
fi
|
|
1279
|
+
|
|
1280
|
+
die "openclaw plugins install failed: ${install_output:-exit code ${install_status}}"
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
restart_or_start_openclaw_gateway() {
|
|
1284
|
+
local output=""
|
|
1285
|
+
if output="$(openclaw gateway restart 2>&1)"; then
|
|
1286
|
+
OPENCLAW_GATEWAY_ACTION="restarted"
|
|
1287
|
+
OPENCLAW_GATEWAY_OUTPUT="${output//$'\r'/}"
|
|
1288
|
+
return
|
|
1289
|
+
fi
|
|
1290
|
+
|
|
1291
|
+
OPENCLAW_GATEWAY_OUTPUT="$(run_openclaw_checked "openclaw gateway start" openclaw gateway start)"
|
|
1292
|
+
OPENCLAW_GATEWAY_ACTION="started"
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
wrap_openclaw_host() {
|
|
1296
|
+
local plugin_path plugin_spec skip_build copy_mode proxy_port startup_timeout_ms python_path
|
|
1297
|
+
local no_auto_start no_restart verbose
|
|
1298
|
+
local gateway_provider_ids=()
|
|
1299
|
+
|
|
1300
|
+
parse_openclaw_wrap_args \
|
|
1301
|
+
plugin_path \
|
|
1302
|
+
plugin_spec \
|
|
1303
|
+
skip_build \
|
|
1304
|
+
copy_mode \
|
|
1305
|
+
proxy_port \
|
|
1306
|
+
startup_timeout_ms \
|
|
1307
|
+
gateway_provider_ids \
|
|
1308
|
+
python_path \
|
|
1309
|
+
no_auto_start \
|
|
1310
|
+
no_restart \
|
|
1311
|
+
verbose \
|
|
1312
|
+
"$@"
|
|
1313
|
+
|
|
1314
|
+
require_cmd openclaw
|
|
1315
|
+
local existing_entry_json=""
|
|
1316
|
+
existing_entry_json="$(get_openclaw_existing_entry_json)"
|
|
1317
|
+
local entry_json
|
|
1318
|
+
entry_json="$(prepare_openclaw_entry_json "${existing_entry_json}" "${proxy_port}" "${startup_timeout_ms}" "${python_path}" "${no_auto_start}" "${gateway_provider_ids[@]}")"
|
|
1319
|
+
|
|
1320
|
+
printf '\n ╔═══════════════════════════════════════════════╗\n'
|
|
1321
|
+
printf ' ║ HEADROOM WRAP: OPENCLAW ║\n'
|
|
1322
|
+
printf ' ╚═══════════════════════════════════════════════╝\n\n'
|
|
1323
|
+
if [[ -n "${plugin_path}" ]]; then
|
|
1324
|
+
printf ' Plugin source: local (%s)\n' "${plugin_path}"
|
|
1325
|
+
else
|
|
1326
|
+
printf ' Plugin source: npm (%s)\n' "${plugin_spec}"
|
|
1327
|
+
fi
|
|
1328
|
+
|
|
1329
|
+
printf ' Writing plugin configuration...\n'
|
|
1330
|
+
run_openclaw_checked \
|
|
1331
|
+
"openclaw config set plugins.entries.headroom" \
|
|
1332
|
+
openclaw config set plugins.entries.headroom "${entry_json}" --strict-json >/dev/null
|
|
1333
|
+
|
|
1334
|
+
printf ' Installing OpenClaw plugin with required unsafe-install flag...\n'
|
|
1335
|
+
install_openclaw_plugin "${plugin_path}" "${plugin_spec}" "${skip_build}" "${copy_mode}" "${verbose}"
|
|
1336
|
+
|
|
1337
|
+
run_openclaw_checked \
|
|
1338
|
+
"openclaw config set plugins.slots.contextEngine" \
|
|
1339
|
+
openclaw config set plugins.slots.contextEngine '"headroom"' --strict-json >/dev/null
|
|
1340
|
+
run_openclaw_checked "openclaw config validate" openclaw config validate >/dev/null
|
|
1341
|
+
|
|
1342
|
+
if [[ "${no_restart}" -eq 1 ]]; then
|
|
1343
|
+
printf ' Skipping gateway restart (--no-restart).\n'
|
|
1344
|
+
printf ' Run `openclaw gateway restart` (or `openclaw gateway start`) to apply plugin changes.\n'
|
|
1345
|
+
else
|
|
1346
|
+
printf ' Applying plugin changes to OpenClaw gateway...\n'
|
|
1347
|
+
restart_or_start_openclaw_gateway
|
|
1348
|
+
printf ' Gateway %s.\n' "${OPENCLAW_GATEWAY_ACTION}"
|
|
1349
|
+
if [[ "${verbose}" -eq 1 && -n "${OPENCLAW_GATEWAY_OUTPUT}" ]]; then
|
|
1350
|
+
printf '%s\n' "${OPENCLAW_GATEWAY_OUTPUT}"
|
|
1351
|
+
fi
|
|
1352
|
+
fi
|
|
1353
|
+
|
|
1354
|
+
local inspect_output=""
|
|
1355
|
+
inspect_output="$(run_openclaw_checked "openclaw plugins inspect headroom" openclaw plugins inspect headroom)"
|
|
1356
|
+
if [[ "${verbose}" -eq 1 && -n "${inspect_output}" ]]; then
|
|
1357
|
+
printf '%s\n' "${inspect_output}"
|
|
1358
|
+
fi
|
|
1359
|
+
|
|
1360
|
+
printf '\n✓ OpenClaw is configured to use Xtream Head context compression.\n'
|
|
1361
|
+
printf ' Plugin: headroom\n'
|
|
1362
|
+
printf ' Slot: plugins.slots.contextEngine = headroom\n\n'
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
unwrap_openclaw_host() {
|
|
1366
|
+
local no_restart verbose
|
|
1367
|
+
parse_openclaw_unwrap_args no_restart verbose "$@"
|
|
1368
|
+
|
|
1369
|
+
require_cmd openclaw
|
|
1370
|
+
local existing_entry_json=""
|
|
1371
|
+
existing_entry_json="$(get_openclaw_existing_entry_json)"
|
|
1372
|
+
local entry_json
|
|
1373
|
+
entry_json="$(prepare_openclaw_unwrap_entry_json "${existing_entry_json}")"
|
|
1374
|
+
|
|
1375
|
+
printf '\n ╔═══════════════════════════════════════════════╗\n'
|
|
1376
|
+
printf ' ║ HEADROOM UNWRAP: OPENCLAW ║\n'
|
|
1377
|
+
printf ' ╚═══════════════════════════════════════════════╝\n\n'
|
|
1378
|
+
printf ' Disabling Headroom plugin and removing engine mapping...\n'
|
|
1379
|
+
|
|
1380
|
+
run_openclaw_checked \
|
|
1381
|
+
"openclaw config set plugins.entries.headroom" \
|
|
1382
|
+
openclaw config set plugins.entries.headroom "${entry_json}" --strict-json >/dev/null
|
|
1383
|
+
run_openclaw_checked \
|
|
1384
|
+
"openclaw config set plugins.slots.contextEngine" \
|
|
1385
|
+
openclaw config set plugins.slots.contextEngine '"legacy"' --strict-json >/dev/null
|
|
1386
|
+
run_openclaw_checked "openclaw config validate" openclaw config validate >/dev/null
|
|
1387
|
+
|
|
1388
|
+
if [[ "${no_restart}" -eq 1 ]]; then
|
|
1389
|
+
printf ' Skipping gateway restart (--no-restart).\n'
|
|
1390
|
+
printf ' Run `openclaw gateway restart` (or `openclaw gateway start`) to apply unwrap changes.\n'
|
|
1391
|
+
else
|
|
1392
|
+
printf ' Applying unwrap changes to OpenClaw gateway...\n'
|
|
1393
|
+
restart_or_start_openclaw_gateway
|
|
1394
|
+
printf ' Gateway %s.\n' "${OPENCLAW_GATEWAY_ACTION}"
|
|
1395
|
+
if [[ "${verbose}" -eq 1 && -n "${OPENCLAW_GATEWAY_OUTPUT}" ]]; then
|
|
1396
|
+
printf '%s\n' "${OPENCLAW_GATEWAY_OUTPUT}"
|
|
1397
|
+
fi
|
|
1398
|
+
fi
|
|
1399
|
+
|
|
1400
|
+
if [[ "${verbose}" -eq 1 ]]; then
|
|
1401
|
+
local inspect_output=""
|
|
1402
|
+
inspect_output="$(run_openclaw_checked "openclaw plugins inspect headroom" openclaw plugins inspect headroom)"
|
|
1403
|
+
if [[ -n "${inspect_output}" ]]; then
|
|
1404
|
+
printf '%s\n' "${inspect_output}"
|
|
1405
|
+
fi
|
|
1406
|
+
fi
|
|
1407
|
+
|
|
1408
|
+
printf '\n✓ OpenClaw Headroom wrap removed.\n'
|
|
1409
|
+
printf ' Plugin: headroom (installed, disabled)\n'
|
|
1410
|
+
printf ' Slot: plugins.slots.contextEngine = legacy\n\n'
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
main() {
|
|
1414
|
+
require_cmd docker
|
|
1415
|
+
|
|
1416
|
+
if (($# == 0)); then
|
|
1417
|
+
run_headroom --help
|
|
1418
|
+
return
|
|
1419
|
+
fi
|
|
1420
|
+
|
|
1421
|
+
case "$1" in
|
|
1422
|
+
install)
|
|
1423
|
+
if (($# == 1)) || [[ "$2" == "--help" || "$2" == "-?" ]]; then
|
|
1424
|
+
print_install_help
|
|
1425
|
+
return
|
|
1426
|
+
fi
|
|
1427
|
+
|
|
1428
|
+
local install_command="$2"
|
|
1429
|
+
shift 2
|
|
1430
|
+
case "${install_command}" in
|
|
1431
|
+
apply)
|
|
1432
|
+
local profile port backend anyllm region proxy_mode memory_enabled telemetry_enabled image
|
|
1433
|
+
parse_install_apply_args profile port backend anyllm region proxy_mode memory_enabled telemetry_enabled image "$@"
|
|
1434
|
+
start_persistent_docker_install "${profile}" "${image}" "${port}" "${backend}" "${anyllm}" "${region}" "${proxy_mode}" "${memory_enabled}" "${telemetry_enabled}"
|
|
1435
|
+
printf "Installed docker-native persistent deployment '%s' on port %s.\n" "${profile}" "${port}"
|
|
1436
|
+
;;
|
|
1437
|
+
status)
|
|
1438
|
+
local profile
|
|
1439
|
+
parse_install_profile_arg profile "$@"
|
|
1440
|
+
status_persistent_docker_install "${profile}"
|
|
1441
|
+
;;
|
|
1442
|
+
start)
|
|
1443
|
+
local profile
|
|
1444
|
+
parse_install_profile_arg profile "$@"
|
|
1445
|
+
load_persistent_state "${profile}"
|
|
1446
|
+
start_persistent_docker_install "${PROFILE}" "${IMAGE}" "${PORT}" "${BACKEND}" "${ANYLLM_PROVIDER}" "${REGION}" "${PROXY_MODE}" "${MEMORY_ENABLED}" "${TELEMETRY_ENABLED}"
|
|
1447
|
+
printf "Started docker-native persistent deployment '%s'.\n" "${profile}"
|
|
1448
|
+
;;
|
|
1449
|
+
stop)
|
|
1450
|
+
local profile
|
|
1451
|
+
parse_install_profile_arg profile "$@"
|
|
1452
|
+
stop_persistent_docker_install "${profile}"
|
|
1453
|
+
printf "Stopped docker-native persistent deployment '%s'.\n" "${profile}"
|
|
1454
|
+
;;
|
|
1455
|
+
restart)
|
|
1456
|
+
local profile
|
|
1457
|
+
parse_install_profile_arg profile "$@"
|
|
1458
|
+
load_persistent_state "${profile}"
|
|
1459
|
+
start_persistent_docker_install "${PROFILE}" "${IMAGE}" "${PORT}" "${BACKEND}" "${ANYLLM_PROVIDER}" "${REGION}" "${PROXY_MODE}" "${MEMORY_ENABLED}" "${TELEMETRY_ENABLED}"
|
|
1460
|
+
printf "Restarted docker-native persistent deployment '%s'.\n" "${profile}"
|
|
1461
|
+
;;
|
|
1462
|
+
remove)
|
|
1463
|
+
local profile
|
|
1464
|
+
parse_install_profile_arg profile "$@"
|
|
1465
|
+
remove_persistent_docker_install "${profile}"
|
|
1466
|
+
printf "Removed docker-native persistent deployment '%s'.\n" "${profile}"
|
|
1467
|
+
;;
|
|
1468
|
+
*)
|
|
1469
|
+
die "Unsupported install target: ${install_command}"
|
|
1470
|
+
;;
|
|
1471
|
+
esac
|
|
1472
|
+
;;
|
|
1473
|
+
wrap)
|
|
1474
|
+
if (($# == 1)) || [[ "$2" == "--help" || "$2" == "-?" ]]; then
|
|
1475
|
+
print_wrap_help
|
|
1476
|
+
return
|
|
1477
|
+
fi
|
|
1478
|
+
|
|
1479
|
+
(($# >= 2)) || die "Usage: xtream-head wrap <claude|codex|aider|cursor|openclaw> [...]"
|
|
1480
|
+
local tool="$2"
|
|
1481
|
+
shift 2
|
|
1482
|
+
|
|
1483
|
+
case "${tool}" in
|
|
1484
|
+
claude|codex|aider|cursor|openclaw)
|
|
1485
|
+
;;
|
|
1486
|
+
*)
|
|
1487
|
+
die "Docker-native wrapper does not support 'wrap ${tool}'. Supported targets: claude, codex, aider, cursor, openclaw"
|
|
1488
|
+
;;
|
|
1489
|
+
esac
|
|
1490
|
+
|
|
1491
|
+
if [[ "${tool}" == "openclaw" ]]; then
|
|
1492
|
+
if contains_help_flag "$@"; then
|
|
1493
|
+
run_xtream-head wrap openclaw "$@"
|
|
1494
|
+
return
|
|
1495
|
+
fi
|
|
1496
|
+
wrap_openclaw_host "$@"
|
|
1497
|
+
return
|
|
1498
|
+
fi
|
|
1499
|
+
|
|
1500
|
+
if contains_help_flag "$@"; then
|
|
1501
|
+
run_xtream-head wrap "${tool}" "$@"
|
|
1502
|
+
return
|
|
1503
|
+
fi
|
|
1504
|
+
|
|
1505
|
+
local known_args host_args port no_rtk no_proxy learn backend anyllm region context_tool
|
|
1506
|
+
parse_wrap_args known_args host_args port no_rtk no_proxy learn backend anyllm region "$@"
|
|
1507
|
+
context_tool="$(selected_context_tool)"
|
|
1508
|
+
|
|
1509
|
+
local proxy_args=()
|
|
1510
|
+
if [[ "${learn}" -eq 1 ]]; then
|
|
1511
|
+
proxy_args+=(--learn)
|
|
1512
|
+
fi
|
|
1513
|
+
if [[ -n "${backend}" ]]; then
|
|
1514
|
+
proxy_args+=(--backend "${backend}")
|
|
1515
|
+
fi
|
|
1516
|
+
if [[ -n "${anyllm}" ]]; then
|
|
1517
|
+
proxy_args+=(--anyllm-provider "${anyllm}")
|
|
1518
|
+
fi
|
|
1519
|
+
if [[ -n "${region}" ]]; then
|
|
1520
|
+
proxy_args+=(--region "${region}")
|
|
1521
|
+
fi
|
|
1522
|
+
|
|
1523
|
+
local container_name=""
|
|
1524
|
+
if [[ "${no_proxy}" -eq 0 ]]; then
|
|
1525
|
+
container_name="$(start_proxy_container "${port}" "${proxy_args[@]}")"
|
|
1526
|
+
fi
|
|
1527
|
+
trap 'stop_proxy_container "${container_name}"' EXIT INT TERM
|
|
1528
|
+
|
|
1529
|
+
local prep_args=("${known_args[@]}")
|
|
1530
|
+
if [[ "${no_proxy}" -eq 0 ]]; then
|
|
1531
|
+
prep_args+=(--no-proxy)
|
|
1532
|
+
fi
|
|
1533
|
+
if [[ "${no_rtk}" -eq 0 && "${context_tool}" == "lean-ctx" ]]; then
|
|
1534
|
+
prep_args+=(--no-rtk)
|
|
1535
|
+
fi
|
|
1536
|
+
run_prepare_only "${tool}" "${prep_args[@]}"
|
|
1537
|
+
|
|
1538
|
+
if [[ "${no_rtk}" -eq 0 && "${context_tool}" == "lean-ctx" ]]; then
|
|
1539
|
+
run_lean_ctx_init "${tool}"
|
|
1540
|
+
fi
|
|
1541
|
+
|
|
1542
|
+
case "${tool}" in
|
|
1543
|
+
claude)
|
|
1544
|
+
if [[ "${no_rtk}" -eq 0 && "${context_tool}" == "rtk" ]]; then
|
|
1545
|
+
run_claude_rtk_init
|
|
1546
|
+
fi
|
|
1547
|
+
ANTHROPIC_BASE_URL="http://127.0.0.1:${port}" run_host_tool claude "${host_args[@]}"
|
|
1548
|
+
;;
|
|
1549
|
+
codex)
|
|
1550
|
+
OPENAI_BASE_URL="http://127.0.0.1:${port}/v1" run_host_tool codex "${host_args[@]}"
|
|
1551
|
+
;;
|
|
1552
|
+
aider)
|
|
1553
|
+
OPENAI_API_BASE="http://127.0.0.1:${port}/v1" \
|
|
1554
|
+
ANTHROPIC_BASE_URL="http://127.0.0.1:${port}" \
|
|
1555
|
+
run_host_tool aider "${host_args[@]}"
|
|
1556
|
+
;;
|
|
1557
|
+
cursor)
|
|
1558
|
+
cat <<EOF
|
|
1559
|
+
Xtream Head proxy is running for Cursor.
|
|
1560
|
+
|
|
1561
|
+
OpenAI base URL: http://127.0.0.1:${port}/v1
|
|
1562
|
+
Anthropic base URL: http://127.0.0.1:${port}
|
|
1563
|
+
|
|
1564
|
+
Press Ctrl+C to stop the proxy.
|
|
1565
|
+
EOF
|
|
1566
|
+
while true; do
|
|
1567
|
+
sleep 1
|
|
1568
|
+
done
|
|
1569
|
+
;;
|
|
1570
|
+
esac
|
|
1571
|
+
;;
|
|
1572
|
+
unwrap)
|
|
1573
|
+
if (($# == 1)) || [[ "$2" == "--help" || "$2" == "-?" ]]; then
|
|
1574
|
+
run_xtream-head unwrap --help
|
|
1575
|
+
return
|
|
1576
|
+
fi
|
|
1577
|
+
|
|
1578
|
+
if (($# >= 2)) && [[ "$2" == "openclaw" ]]; then
|
|
1579
|
+
shift 2
|
|
1580
|
+
if contains_help_flag "$@"; then
|
|
1581
|
+
run_xtream-head unwrap openclaw "$@"
|
|
1582
|
+
return
|
|
1583
|
+
fi
|
|
1584
|
+
unwrap_openclaw_host "$@"
|
|
1585
|
+
return
|
|
1586
|
+
fi
|
|
1587
|
+
run_headroom "$@"
|
|
1588
|
+
;;
|
|
1589
|
+
proxy)
|
|
1590
|
+
shift
|
|
1591
|
+
local port=8787
|
|
1592
|
+
local args=()
|
|
1593
|
+
args=(proxy)
|
|
1594
|
+
while (($#)); do
|
|
1595
|
+
case "$1" in
|
|
1596
|
+
--port|-p)
|
|
1597
|
+
require_option_value "$@"
|
|
1598
|
+
port="$2"
|
|
1599
|
+
validate_port "${port}"
|
|
1600
|
+
args+=("$1" "$2")
|
|
1601
|
+
shift 2
|
|
1602
|
+
;;
|
|
1603
|
+
--port=*)
|
|
1604
|
+
port="${1#*=}"
|
|
1605
|
+
validate_port "${port}"
|
|
1606
|
+
args+=("$1")
|
|
1607
|
+
shift
|
|
1608
|
+
;;
|
|
1609
|
+
*)
|
|
1610
|
+
args+=("$1")
|
|
1611
|
+
shift
|
|
1612
|
+
;;
|
|
1613
|
+
esac
|
|
1614
|
+
done
|
|
1615
|
+
local run_args=()
|
|
1616
|
+
run_args=(docker run --rm)
|
|
1617
|
+
append_tty_args run_args
|
|
1618
|
+
append_common_container_args run_args
|
|
1619
|
+
run_args+=(-p "${port}:${port}")
|
|
1620
|
+
run_args+=(--entrypoint headroom "${HEADROOM_IMAGE}" "${args[@]}")
|
|
1621
|
+
"${run_args[@]}"
|
|
1622
|
+
;;
|
|
1623
|
+
*)
|
|
1624
|
+
run_headroom "$@"
|
|
1625
|
+
;;
|
|
1626
|
+
esac
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
main "$@"
|
|
1630
|
+
WRAPPER
|
|
1631
|
+
} >"${wrapper_path}"
|
|
1632
|
+
|
|
1633
|
+
chmod +x "${wrapper_path}"
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
main() {
|
|
1637
|
+
require_cmd docker
|
|
1638
|
+
docker version >/dev/null 2>&1 || die "Docker is installed but not available to the current user"
|
|
1639
|
+
|
|
1640
|
+
mkdir -p "${INSTALL_DIR}"
|
|
1641
|
+
write_wrapper
|
|
1642
|
+
|
|
1643
|
+
append_path_block "${HOME}/.bashrc"
|
|
1644
|
+
append_path_block "${HOME}/.zshrc"
|
|
1645
|
+
append_path_block "${HOME}/.profile"
|
|
1646
|
+
|
|
1647
|
+
if [[ -n "${HEADROOM_DOCKER_IMAGE:-}" ]]; then
|
|
1648
|
+
if docker image inspect "${INSTALL_IMAGE}" >/dev/null 2>&1; then
|
|
1649
|
+
info "Using existing HEADROOM_DOCKER_IMAGE=${INSTALL_IMAGE}"
|
|
1650
|
+
else
|
|
1651
|
+
info "Pulling ${INSTALL_IMAGE}"
|
|
1652
|
+
docker pull "${INSTALL_IMAGE}" >/dev/null
|
|
1653
|
+
fi
|
|
1654
|
+
else
|
|
1655
|
+
info "Pulling ${IMAGE_DEFAULT}"
|
|
1656
|
+
docker pull "${IMAGE_DEFAULT}" >/dev/null
|
|
1657
|
+
fi
|
|
1658
|
+
|
|
1659
|
+
cat <<EOF
|
|
1660
|
+
|
|
1661
|
+
Headroom Docker-native install complete.
|
|
1662
|
+
|
|
1663
|
+
Installed wrapper:
|
|
1664
|
+
${INSTALL_DIR}/headroom
|
|
1665
|
+
|
|
1666
|
+
Next steps:
|
|
1667
|
+
1. Restart your shell or run: export PATH="${INSTALL_DIR}:\$PATH"
|
|
1668
|
+
2. Try: xtream-head proxy
|
|
1669
|
+
3. Docs: https://github.com/Xtream-ITSolutions/xithead/blob/main/docs/docker-install.md
|
|
1670
|
+
EOF
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
main "$@"
|