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,1809 @@
|
|
|
1
|
+
$ErrorActionPreference = 'Stop'
|
|
2
|
+
|
|
3
|
+
$ImageDefault = 'ghcr.io/chopratejas/headroom:latest'
|
|
4
|
+
$InstallImage = if ($env:HEADROOM_DOCKER_IMAGE) { $env:HEADROOM_DOCKER_IMAGE } else { $ImageDefault }
|
|
5
|
+
$InstallDir = Join-Path $HOME '.local\bin'
|
|
6
|
+
if (-not (Test-Path (Join-Path $HOME '.local'))) {
|
|
7
|
+
$InstallDir = Join-Path $HOME 'bin'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function Write-Info {
|
|
11
|
+
param([string]$Message)
|
|
12
|
+
Write-Host "==> $Message"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function Require-Command {
|
|
16
|
+
param([string]$Name)
|
|
17
|
+
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
|
|
18
|
+
throw "Missing required command: $Name"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function Ensure-PathEntry {
|
|
23
|
+
param([string]$PathEntry)
|
|
24
|
+
|
|
25
|
+
$currentPath = [Environment]::GetEnvironmentVariable('Path', 'User')
|
|
26
|
+
$parts = @()
|
|
27
|
+
if ($currentPath) {
|
|
28
|
+
$parts = $currentPath -split ';' | Where-Object { $_ }
|
|
29
|
+
}
|
|
30
|
+
if ($parts -notcontains $PathEntry) {
|
|
31
|
+
$newPath = @($PathEntry) + $parts
|
|
32
|
+
[Environment]::SetEnvironmentVariable('Path', ($newPath -join ';'), 'User')
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function Ensure-ProfileBlock {
|
|
37
|
+
param([string]$PathEntry)
|
|
38
|
+
|
|
39
|
+
$markerStart = '# >>> headroom docker-native >>>'
|
|
40
|
+
$markerEnd = '# <<< headroom docker-native <<<'
|
|
41
|
+
$escapedPathEntry = $PathEntry.Replace("'", "''")
|
|
42
|
+
$block = @"
|
|
43
|
+
$markerStart
|
|
44
|
+
if (-not ((`$env:Path -split ';') -contains '$escapedPathEntry')) {
|
|
45
|
+
`$env:Path = '$escapedPathEntry;' + `$env:Path
|
|
46
|
+
}
|
|
47
|
+
$markerEnd
|
|
48
|
+
"@
|
|
49
|
+
|
|
50
|
+
$profileDir = Split-Path -Parent $PROFILE
|
|
51
|
+
if (-not (Test-Path $profileDir)) {
|
|
52
|
+
New-Item -ItemType Directory -Force -Path $profileDir | Out-Null
|
|
53
|
+
}
|
|
54
|
+
if (-not (Test-Path $PROFILE)) {
|
|
55
|
+
New-Item -ItemType File -Force -Path $PROFILE | Out-Null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
$existing = Get-Content -Raw -Path $PROFILE
|
|
59
|
+
if ($existing -notmatch [regex]::Escape($markerStart)) {
|
|
60
|
+
Add-Content -Path $PROFILE -Value "`n$block"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function Write-Wrapper {
|
|
65
|
+
param([string]$TargetDir)
|
|
66
|
+
|
|
67
|
+
$wrapperPath = Join-Path $TargetDir 'headroom.ps1'
|
|
68
|
+
$cmdPath = Join-Path $TargetDir 'headroom.cmd'
|
|
69
|
+
$resolvedInstallImage = $InstallImage.Replace("'", "''")
|
|
70
|
+
|
|
71
|
+
$wrapper = @'
|
|
72
|
+
$ErrorActionPreference = 'Stop'
|
|
73
|
+
|
|
74
|
+
$HeadroomImage = if ($env:HEADROOM_DOCKER_IMAGE) { $env:HEADROOM_DOCKER_IMAGE } else { '__HEADROOM_INSTALL_IMAGE__' }
|
|
75
|
+
$ContainerHome = if ($env:HEADROOM_CONTAINER_HOME) { $env:HEADROOM_CONTAINER_HOME } else { '/tmp/headroom-home' }
|
|
76
|
+
$HostHome = $HOME
|
|
77
|
+
|
|
78
|
+
function Fail {
|
|
79
|
+
param([string]$Message)
|
|
80
|
+
throw $Message
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function Require-Command {
|
|
84
|
+
param([string]$Name)
|
|
85
|
+
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
|
|
86
|
+
Fail "Missing required command: $Name"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function Get-RtkTarget {
|
|
91
|
+
$arch = if ($env:PROCESSOR_ARCHITECTURE -match 'ARM64') { 'aarch64' } else { 'x86_64' }
|
|
92
|
+
return "${arch}-pc-windows-msvc"
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function Ensure-HostDirs {
|
|
96
|
+
foreach ($dir in @(
|
|
97
|
+
(Join-Path $HostHome '.headroom'),
|
|
98
|
+
(Join-Path $HostHome '.claude'),
|
|
99
|
+
(Join-Path $HostHome '.codex'),
|
|
100
|
+
(Join-Path $HostHome '.gemini')
|
|
101
|
+
)) {
|
|
102
|
+
if (-not (Test-Path $dir)) {
|
|
103
|
+
New-Item -ItemType Directory -Force -Path $dir | Out-Null
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function Get-PassthroughEnvArgs {
|
|
109
|
+
$args = New-Object System.Collections.Generic.List[string]
|
|
110
|
+
$prefixes = @(
|
|
111
|
+
'HEADROOM_','ANTHROPIC_','OPENAI_','GEMINI_','AWS_','AZURE_','VERTEX_',
|
|
112
|
+
'GOOGLE_','GOOGLE_CLOUD_','MISTRAL_','GROQ_','OPENROUTER_','XAI_',
|
|
113
|
+
'TOGETHER_','COHERE_','OLLAMA_','LITELLM_','OTEL_','SUPABASE_',
|
|
114
|
+
'QDRANT_','NEO4J_','LANGSMITH_'
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
foreach ($item in Get-ChildItem Env:) {
|
|
118
|
+
foreach ($prefix in $prefixes) {
|
|
119
|
+
if ($item.Name.StartsWith($prefix, [System.StringComparison]::OrdinalIgnoreCase)) {
|
|
120
|
+
$args.Add('--env')
|
|
121
|
+
$args.Add($item.Name)
|
|
122
|
+
break
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return ,$args.ToArray()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function Get-SharedDockerArgs {
|
|
131
|
+
Ensure-HostDirs
|
|
132
|
+
$args = New-Object System.Collections.Generic.List[string]
|
|
133
|
+
$args.Add('--workdir')
|
|
134
|
+
$args.Add('/workspace')
|
|
135
|
+
$args.Add('--env')
|
|
136
|
+
$args.Add("HOME=$ContainerHome")
|
|
137
|
+
$args.Add('--env')
|
|
138
|
+
$args.Add('PYTHONUNBUFFERED=1')
|
|
139
|
+
# Canonical Headroom filesystem contract (issue #175).
|
|
140
|
+
$args.Add('--env')
|
|
141
|
+
$args.Add("HEADROOM_WORKSPACE_DIR=$ContainerHome/.headroom")
|
|
142
|
+
$args.Add('--env')
|
|
143
|
+
$args.Add("HEADROOM_CONFIG_DIR=$ContainerHome/.headroom/config")
|
|
144
|
+
$args.Add('--volume')
|
|
145
|
+
$args.Add("${PWD}:/workspace")
|
|
146
|
+
$args.Add('--volume')
|
|
147
|
+
$args.Add((Join-Path $HostHome '.headroom') + ":$ContainerHome/.headroom")
|
|
148
|
+
$args.Add('--volume')
|
|
149
|
+
$args.Add((Join-Path $HostHome '.claude') + ":$ContainerHome/.claude")
|
|
150
|
+
$args.Add('--volume')
|
|
151
|
+
$args.Add((Join-Path $HostHome '.codex') + ":$ContainerHome/.codex")
|
|
152
|
+
$args.Add('--volume')
|
|
153
|
+
$args.Add((Join-Path $HostHome '.gemini') + ":$ContainerHome/.gemini")
|
|
154
|
+
|
|
155
|
+
foreach ($entry in (Get-PassthroughEnvArgs)) {
|
|
156
|
+
$args.Add($entry)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return ,$args.ToArray()
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function Add-TtyArgs {
|
|
163
|
+
param($ArgsList)
|
|
164
|
+
|
|
165
|
+
if (-not [Console]::IsInputRedirected -and -not [Console]::IsOutputRedirected) {
|
|
166
|
+
$ArgsList.Add('-it')
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
if (-not [Console]::IsInputRedirected) {
|
|
170
|
+
$ArgsList.Add('-i')
|
|
171
|
+
}
|
|
172
|
+
if (-not [Console]::IsOutputRedirected) {
|
|
173
|
+
$ArgsList.Add('-t')
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function Invoke-HeadroomDocker {
|
|
178
|
+
param([string[]]$Arguments)
|
|
179
|
+
|
|
180
|
+
$dockerArgs = New-Object System.Collections.Generic.List[string]
|
|
181
|
+
$dockerArgs.AddRange([string[]]@('run','--rm'))
|
|
182
|
+
Add-TtyArgs -ArgsList $dockerArgs
|
|
183
|
+
$dockerArgs.AddRange((Get-SharedDockerArgs))
|
|
184
|
+
$dockerArgs.Add('--entrypoint')
|
|
185
|
+
$dockerArgs.Add('headroom')
|
|
186
|
+
$dockerArgs.Add($HeadroomImage)
|
|
187
|
+
foreach ($arg in $Arguments) {
|
|
188
|
+
$dockerArgs.Add($arg)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
& docker @dockerArgs
|
|
192
|
+
if ($LASTEXITCODE -ne 0) {
|
|
193
|
+
exit $LASTEXITCODE
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function Wait-Proxy {
|
|
198
|
+
param(
|
|
199
|
+
[string]$ContainerName,
|
|
200
|
+
[int]$Port
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
for ($attempt = 0; $attempt -lt 45; $attempt++) {
|
|
204
|
+
try {
|
|
205
|
+
Invoke-WebRequest -UseBasicParsing -Uri "http://127.0.0.1:$Port/readyz" | Out-Null
|
|
206
|
+
return
|
|
207
|
+
} catch {
|
|
208
|
+
$running = docker ps --format '{{.Names}}'
|
|
209
|
+
if ($running -notcontains $ContainerName) {
|
|
210
|
+
break
|
|
211
|
+
}
|
|
212
|
+
Start-Sleep -Seconds 1
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
docker logs $ContainerName | Write-Error
|
|
217
|
+
throw "Xtream Head proxy failed to start on port $Port"
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function Start-ProxyContainer {
|
|
221
|
+
param(
|
|
222
|
+
[int]$Port,
|
|
223
|
+
[string[]]$ProxyArgs
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
$containerName = "headroom-proxy-$Port-$PID"
|
|
227
|
+
$dockerArgs = New-Object System.Collections.Generic.List[string]
|
|
228
|
+
$dockerArgs.AddRange([string[]]@('run','-d','--rm','--name',$containerName,'-p',"$Port`:$Port"))
|
|
229
|
+
$dockerArgs.AddRange((Get-SharedDockerArgs))
|
|
230
|
+
$dockerArgs.Add($HeadroomImage)
|
|
231
|
+
$dockerArgs.Add('--host')
|
|
232
|
+
$dockerArgs.Add('0.0.0.0')
|
|
233
|
+
$dockerArgs.Add('--port')
|
|
234
|
+
$dockerArgs.Add("$Port")
|
|
235
|
+
foreach ($arg in $ProxyArgs) {
|
|
236
|
+
$dockerArgs.Add($arg)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
& docker @dockerArgs | Out-Null
|
|
240
|
+
if ($LASTEXITCODE -ne 0) {
|
|
241
|
+
throw "Failed to start Xtream Head proxy container"
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
Wait-Proxy -ContainerName $containerName -Port $Port
|
|
245
|
+
return $containerName
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function Stop-ProxyContainer {
|
|
249
|
+
param([string]$ContainerName)
|
|
250
|
+
if ($ContainerName) {
|
|
251
|
+
docker stop $ContainerName | Out-Null
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function Get-PersistentProfileRoot {
|
|
256
|
+
param([string]$Profile)
|
|
257
|
+
Assert-ValidProfileName -Profile $Profile
|
|
258
|
+
return Join-Path (Join-Path $HostHome '.headroom\deploy') $Profile
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function Get-PersistentStatePath {
|
|
262
|
+
param([string]$Profile)
|
|
263
|
+
return Join-Path (Get-PersistentProfileRoot -Profile $Profile) 'docker-native.json'
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function Get-PersistentManifestPath {
|
|
267
|
+
param([string]$Profile)
|
|
268
|
+
return Join-Path (Get-PersistentProfileRoot -Profile $Profile) 'manifest.json'
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function Get-PersistentContainerName {
|
|
272
|
+
param([string]$Profile)
|
|
273
|
+
return "headroom-$Profile"
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function Assert-ValidProfileName {
|
|
277
|
+
param([string]$Profile)
|
|
278
|
+
if ($Profile -notmatch '^[A-Za-z0-9._-]+$' -or $Profile -in @('.', '..')) {
|
|
279
|
+
Fail "Invalid profile name '$Profile'"
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function Parse-PortValue {
|
|
284
|
+
param([string]$Value)
|
|
285
|
+
|
|
286
|
+
$parsed = 0
|
|
287
|
+
if (-not [int]::TryParse($Value, [ref]$parsed) -or $parsed -lt 1 -or $parsed -gt 65535) {
|
|
288
|
+
Fail "Invalid port '$Value'"
|
|
289
|
+
}
|
|
290
|
+
return $parsed
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function Parse-PositiveIntegerValue {
|
|
294
|
+
param([string]$Value)
|
|
295
|
+
|
|
296
|
+
$parsed = 0
|
|
297
|
+
if (-not [int]::TryParse($Value, [ref]$parsed) -or $parsed -lt 1) {
|
|
298
|
+
Fail "Invalid value '$Value'"
|
|
299
|
+
}
|
|
300
|
+
return $parsed
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function Require-OptionValue {
|
|
304
|
+
param(
|
|
305
|
+
[string[]]$Arguments,
|
|
306
|
+
[int]$Index,
|
|
307
|
+
[string]$Option
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
if ($Index + 1 -ge $Arguments.Count) {
|
|
311
|
+
Fail "Option $Option requires a value"
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function Write-Utf8NoBomFile {
|
|
316
|
+
param(
|
|
317
|
+
[string]$Path,
|
|
318
|
+
[string]$Content
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
[System.IO.File]::WriteAllText($Path, $Content, [System.Text.UTF8Encoding]::new($false))
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function Get-PersistentDockerArgs {
|
|
325
|
+
Ensure-HostDirs
|
|
326
|
+
$args = New-Object System.Collections.Generic.List[string]
|
|
327
|
+
$args.Add('--workdir')
|
|
328
|
+
$args.Add($ContainerHome)
|
|
329
|
+
$args.Add('--env')
|
|
330
|
+
$args.Add("HOME=$ContainerHome")
|
|
331
|
+
$args.Add('--env')
|
|
332
|
+
$args.Add('PYTHONUNBUFFERED=1')
|
|
333
|
+
# Canonical Headroom filesystem contract (issue #175).
|
|
334
|
+
$args.Add('--env')
|
|
335
|
+
$args.Add("HEADROOM_WORKSPACE_DIR=$ContainerHome/.headroom")
|
|
336
|
+
$args.Add('--env')
|
|
337
|
+
$args.Add("HEADROOM_CONFIG_DIR=$ContainerHome/.headroom/config")
|
|
338
|
+
$args.Add('--volume')
|
|
339
|
+
$args.Add((Join-Path $HostHome '.headroom') + ":$ContainerHome/.headroom")
|
|
340
|
+
$args.Add('--volume')
|
|
341
|
+
$args.Add((Join-Path $HostHome '.claude') + ":$ContainerHome/.claude")
|
|
342
|
+
$args.Add('--volume')
|
|
343
|
+
$args.Add((Join-Path $HostHome '.codex') + ":$ContainerHome/.codex")
|
|
344
|
+
$args.Add('--volume')
|
|
345
|
+
$args.Add((Join-Path $HostHome '.gemini') + ":$ContainerHome/.gemini")
|
|
346
|
+
|
|
347
|
+
foreach ($entry in (Get-PassthroughEnvArgs)) {
|
|
348
|
+
$args.Add($entry)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return ,$args.ToArray()
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function Get-ManifestProxyArgs {
|
|
355
|
+
param(
|
|
356
|
+
[int]$Port,
|
|
357
|
+
[string]$Backend,
|
|
358
|
+
[string]$AnyllmProvider,
|
|
359
|
+
[string]$Region,
|
|
360
|
+
[string]$Mode,
|
|
361
|
+
[bool]$Memory,
|
|
362
|
+
[bool]$TelemetryEnabled
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
$args = New-Object System.Collections.Generic.List[string]
|
|
366
|
+
$args.AddRange([string[]]@('--host','127.0.0.1','--port',"$Port",'--mode',$Mode,'--backend',$Backend))
|
|
367
|
+
if (-not $TelemetryEnabled) {
|
|
368
|
+
$args.Add('--no-telemetry')
|
|
369
|
+
}
|
|
370
|
+
if ($Memory) {
|
|
371
|
+
$args.AddRange([string[]]@('--memory','--memory-db-path',"$ContainerHome/.headroom/memory.db"))
|
|
372
|
+
}
|
|
373
|
+
if ($AnyllmProvider) {
|
|
374
|
+
$args.AddRange([string[]]@('--anyllm-provider', $AnyllmProvider))
|
|
375
|
+
}
|
|
376
|
+
if ($Region) {
|
|
377
|
+
$args.AddRange([string[]]@('--region', $Region))
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return ,$args.ToArray()
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function Write-PersistentState {
|
|
384
|
+
param(
|
|
385
|
+
[string]$Profile,
|
|
386
|
+
[string]$Image,
|
|
387
|
+
[int]$Port,
|
|
388
|
+
[string]$Backend,
|
|
389
|
+
[string]$AnyllmProvider,
|
|
390
|
+
[string]$Region,
|
|
391
|
+
[string]$Mode,
|
|
392
|
+
[bool]$Memory,
|
|
393
|
+
[bool]$TelemetryEnabled
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
$root = Get-PersistentProfileRoot -Profile $Profile
|
|
397
|
+
New-Item -ItemType Directory -Force -Path $root | Out-Null
|
|
398
|
+
$state = [ordered]@{
|
|
399
|
+
profile = $Profile
|
|
400
|
+
image = $Image
|
|
401
|
+
port = $Port
|
|
402
|
+
backend = $Backend
|
|
403
|
+
anyllm_provider = $AnyllmProvider
|
|
404
|
+
region = $Region
|
|
405
|
+
proxy_mode = $Mode
|
|
406
|
+
memory_enabled = $Memory
|
|
407
|
+
telemetry_enabled = $TelemetryEnabled
|
|
408
|
+
container_name = Get-PersistentContainerName -Profile $Profile
|
|
409
|
+
health_url = "http://127.0.0.1:$Port/readyz"
|
|
410
|
+
}
|
|
411
|
+
Write-Utf8NoBomFile -Path (Get-PersistentStatePath -Profile $Profile) -Content ($state | ConvertTo-Json -Depth 4)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function Write-PersistentManifest {
|
|
415
|
+
param(
|
|
416
|
+
[string]$Profile,
|
|
417
|
+
[string]$Image,
|
|
418
|
+
[int]$Port,
|
|
419
|
+
[string]$Backend,
|
|
420
|
+
[string]$AnyllmProvider,
|
|
421
|
+
[string]$Region,
|
|
422
|
+
[string]$Mode,
|
|
423
|
+
[bool]$Memory,
|
|
424
|
+
[bool]$TelemetryEnabled,
|
|
425
|
+
[string[]]$ProxyArgs
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
$root = Get-PersistentProfileRoot -Profile $Profile
|
|
429
|
+
New-Item -ItemType Directory -Force -Path $root | Out-Null
|
|
430
|
+
|
|
431
|
+
$baseEnv = [ordered]@{
|
|
432
|
+
HEADROOM_PORT = "$Port"
|
|
433
|
+
HEADROOM_HOST = '127.0.0.1'
|
|
434
|
+
HEADROOM_MODE = $Mode
|
|
435
|
+
HEADROOM_BACKEND = $Backend
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
$manifest = [ordered]@{
|
|
439
|
+
profile = $Profile
|
|
440
|
+
preset = 'persistent-docker'
|
|
441
|
+
runtime_kind = 'docker'
|
|
442
|
+
supervisor_kind = 'none'
|
|
443
|
+
scope = 'user'
|
|
444
|
+
provider_mode = 'manual'
|
|
445
|
+
targets = @()
|
|
446
|
+
port = $Port
|
|
447
|
+
host = '127.0.0.1'
|
|
448
|
+
backend = $Backend
|
|
449
|
+
anyllm_provider = if ($AnyllmProvider) { $AnyllmProvider } else { $null }
|
|
450
|
+
region = if ($Region) { $Region } else { $null }
|
|
451
|
+
proxy_mode = $Mode
|
|
452
|
+
memory_enabled = $Memory
|
|
453
|
+
memory_db_path = "$ContainerHome/.headroom/memory.db"
|
|
454
|
+
telemetry_enabled = $TelemetryEnabled
|
|
455
|
+
image = $Image
|
|
456
|
+
service_name = "headroom-$Profile"
|
|
457
|
+
container_name = Get-PersistentContainerName -Profile $Profile
|
|
458
|
+
health_url = "http://127.0.0.1:$Port/readyz"
|
|
459
|
+
base_env = $baseEnv
|
|
460
|
+
tool_envs = @{}
|
|
461
|
+
proxy_args = $ProxyArgs
|
|
462
|
+
mutations = @()
|
|
463
|
+
artifacts = @()
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
Write-Utf8NoBomFile -Path (Get-PersistentManifestPath -Profile $Profile) -Content ($manifest | ConvertTo-Json -Depth 8)
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function Read-PersistentState {
|
|
470
|
+
param([string]$Profile)
|
|
471
|
+
|
|
472
|
+
Assert-ValidProfileName -Profile $Profile
|
|
473
|
+
$statePath = Get-PersistentStatePath -Profile $Profile
|
|
474
|
+
if (-not (Test-Path $statePath)) {
|
|
475
|
+
Fail "No docker-native persistent deployment profile named '$Profile'"
|
|
476
|
+
}
|
|
477
|
+
return Get-Content -Raw -Path $statePath | ConvertFrom-Json
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function Start-PersistentDockerInstall {
|
|
481
|
+
param(
|
|
482
|
+
[string]$Profile,
|
|
483
|
+
[string]$Image,
|
|
484
|
+
[int]$Port,
|
|
485
|
+
[string]$Backend,
|
|
486
|
+
[string]$AnyllmProvider,
|
|
487
|
+
[string]$Region,
|
|
488
|
+
[string]$Mode,
|
|
489
|
+
[bool]$Memory,
|
|
490
|
+
[bool]$TelemetryEnabled
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
Assert-ValidProfileName -Profile $Profile
|
|
494
|
+
$containerName = Get-PersistentContainerName -Profile $Profile
|
|
495
|
+
$proxyArgs = Get-ManifestProxyArgs -Port $Port -Backend $Backend -AnyllmProvider $AnyllmProvider -Region $Region -Mode $Mode -Memory $Memory -TelemetryEnabled $TelemetryEnabled
|
|
496
|
+
|
|
497
|
+
docker rm -f $containerName | Out-Null 2>$null
|
|
498
|
+
|
|
499
|
+
$dockerArgs = New-Object System.Collections.Generic.List[string]
|
|
500
|
+
$dockerArgs.AddRange([string[]]@('run','-d','--restart','unless-stopped','--name',$containerName,'-p',"$Port`:$Port"))
|
|
501
|
+
$dockerArgs.AddRange((Get-PersistentDockerArgs))
|
|
502
|
+
$dockerArgs.AddRange([string[]]@(
|
|
503
|
+
'--env',"HEADROOM_DEPLOYMENT_PROFILE=$Profile",
|
|
504
|
+
'--env','HEADROOM_DEPLOYMENT_PRESET=persistent-docker',
|
|
505
|
+
'--env','HEADROOM_DEPLOYMENT_RUNTIME=docker',
|
|
506
|
+
'--env','HEADROOM_DEPLOYMENT_SUPERVISOR=none',
|
|
507
|
+
'--env','HEADROOM_DEPLOYMENT_SCOPE=user'
|
|
508
|
+
))
|
|
509
|
+
$dockerArgs.Add($Image)
|
|
510
|
+
$dockerArgs.Add('--host')
|
|
511
|
+
$dockerArgs.Add('0.0.0.0')
|
|
512
|
+
for ($i = 2; $i -lt $proxyArgs.Count; $i++) {
|
|
513
|
+
$dockerArgs.Add($proxyArgs[$i])
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
& docker @dockerArgs | Out-Null
|
|
517
|
+
if ($LASTEXITCODE -ne 0) {
|
|
518
|
+
throw "Failed to start docker-native persistent deployment"
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
try {
|
|
522
|
+
Wait-Proxy -ContainerName $containerName -Port $Port
|
|
523
|
+
} catch {
|
|
524
|
+
docker rm -f $containerName | Out-Null 2>$null
|
|
525
|
+
throw
|
|
526
|
+
}
|
|
527
|
+
Write-PersistentState -Profile $Profile -Image $Image -Port $Port -Backend $Backend -AnyllmProvider $AnyllmProvider -Region $Region -Mode $Mode -Memory $Memory -TelemetryEnabled $TelemetryEnabled
|
|
528
|
+
Write-PersistentManifest -Profile $Profile -Image $Image -Port $Port -Backend $Backend -AnyllmProvider $AnyllmProvider -Region $Region -Mode $Mode -Memory $Memory -TelemetryEnabled $TelemetryEnabled -ProxyArgs $proxyArgs
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function Stop-PersistentDockerInstall {
|
|
532
|
+
param([string]$Profile)
|
|
533
|
+
|
|
534
|
+
$state = Read-PersistentState -Profile $Profile
|
|
535
|
+
docker stop $state.container_name | Out-Null 2>$null
|
|
536
|
+
docker rm -f $state.container_name | Out-Null 2>$null
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function Remove-PersistentDockerInstall {
|
|
540
|
+
param([string]$Profile)
|
|
541
|
+
|
|
542
|
+
$state = Read-PersistentState -Profile $Profile
|
|
543
|
+
docker stop $state.container_name | Out-Null 2>$null
|
|
544
|
+
docker rm -f $state.container_name | Out-Null 2>$null
|
|
545
|
+
$root = Get-PersistentProfileRoot -Profile $Profile
|
|
546
|
+
if (Test-Path $root) {
|
|
547
|
+
Remove-Item -Recurse -Force -Path $root
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function Show-PersistentDockerInstallStatus {
|
|
552
|
+
param([string]$Profile)
|
|
553
|
+
|
|
554
|
+
$state = Read-PersistentState -Profile $Profile
|
|
555
|
+
$status = 'stopped'
|
|
556
|
+
$ready = 'no'
|
|
557
|
+
$running = docker ps --format '{{.Names}}'
|
|
558
|
+
if ($running -contains $state.container_name) {
|
|
559
|
+
$status = 'running'
|
|
560
|
+
try {
|
|
561
|
+
Invoke-WebRequest -UseBasicParsing -Uri $state.health_url | Out-Null
|
|
562
|
+
$ready = 'yes'
|
|
563
|
+
} catch {
|
|
564
|
+
$ready = 'no'
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
Write-Host "Profile: $($state.profile)"
|
|
569
|
+
Write-Host 'Preset: persistent-docker'
|
|
570
|
+
Write-Host 'Runtime: docker'
|
|
571
|
+
Write-Host 'Supervisor: none'
|
|
572
|
+
Write-Host "Port: $($state.port)"
|
|
573
|
+
Write-Host "Status: $status"
|
|
574
|
+
Write-Host "Ready: $ready"
|
|
575
|
+
Write-Host "Health URL: $($state.health_url)"
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function Show-InstallHelp {
|
|
579
|
+
$lines = @(
|
|
580
|
+
'Usage: xtream-head install [OPTIONS] COMMAND [ARGS]...',
|
|
581
|
+
'',
|
|
582
|
+
' Manage persistent Docker-native Headroom deployments.',
|
|
583
|
+
'',
|
|
584
|
+
' The Docker-native wrapper currently supports the persistent-docker preset only.',
|
|
585
|
+
' Use the Python-native `xtream-head install` command for persistent-service and',
|
|
586
|
+
' persistent-task installs, or when you need provider/user/system config mutation.',
|
|
587
|
+
'',
|
|
588
|
+
'Options:',
|
|
589
|
+
' -?, --help Show this message and exit.',
|
|
590
|
+
'',
|
|
591
|
+
'Commands:',
|
|
592
|
+
' apply Install a persistent Docker deployment.',
|
|
593
|
+
' remove Remove a persistent Docker deployment.',
|
|
594
|
+
' restart Restart a persistent Docker deployment.',
|
|
595
|
+
' start Start a persistent Docker deployment.',
|
|
596
|
+
' status Show persistent Docker deployment status.',
|
|
597
|
+
' stop Stop a persistent Docker deployment.'
|
|
598
|
+
)
|
|
599
|
+
Write-Host ($lines -join [Environment]::NewLine)
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function Show-InstallApplyHelp {
|
|
603
|
+
$lines = @(
|
|
604
|
+
'Usage: xtream-head install apply [OPTIONS]',
|
|
605
|
+
'',
|
|
606
|
+
' Install a persistent Docker deployment.',
|
|
607
|
+
'',
|
|
608
|
+
'Options:',
|
|
609
|
+
' --preset [persistent-docker] Docker-native wrapper supports persistent-docker only.',
|
|
610
|
+
' --runtime [docker] Docker-native wrapper supports runtime=docker only.',
|
|
611
|
+
' --profile TEXT Deployment profile name. [default: default]',
|
|
612
|
+
' -p, --port INTEGER Persistent proxy port. [default: 8787]',
|
|
613
|
+
' --backend TEXT Proxy backend. [default: anthropic]',
|
|
614
|
+
' --anyllm-provider TEXT Provider for any-llm backends.',
|
|
615
|
+
' --region TEXT Cloud region for Bedrock / Vertex style backends.',
|
|
616
|
+
' --mode TEXT Proxy optimization mode. [default: token]',
|
|
617
|
+
' --memory Enable persistent memory in the runtime.',
|
|
618
|
+
' --no-telemetry Disable anonymous telemetry in the runtime.',
|
|
619
|
+
' --image TEXT Docker image to use. [default: HEADROOM_DOCKER_IMAGE or ghcr.io/chopratejas/headroom:latest]',
|
|
620
|
+
' -?, --help Show this message and exit.'
|
|
621
|
+
)
|
|
622
|
+
Write-Host ($lines -join [Environment]::NewLine)
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function Show-WrapHelp {
|
|
626
|
+
$lines = @(
|
|
627
|
+
'Usage: xtream-head wrap <COMMAND> [OPTIONS] [-- ARGS...]',
|
|
628
|
+
'',
|
|
629
|
+
' Launch supported host tools through a Docker-native Xtream Head proxy.',
|
|
630
|
+
'',
|
|
631
|
+
'Supported commands:',
|
|
632
|
+
' claude',
|
|
633
|
+
' codex',
|
|
634
|
+
' aider',
|
|
635
|
+
' cursor',
|
|
636
|
+
' openclaw',
|
|
637
|
+
'',
|
|
638
|
+
'Notes:',
|
|
639
|
+
' - GitHub Copilot CLI wrapping is not supported by the Docker-native wrapper.',
|
|
640
|
+
' - Use the Python-native CLI for unsupported wrap targets.'
|
|
641
|
+
)
|
|
642
|
+
Write-Host ($lines -join [Environment]::NewLine)
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function Parse-InstallApplyArgs {
|
|
646
|
+
param([string[]]$Arguments)
|
|
647
|
+
|
|
648
|
+
$profile = 'default'
|
|
649
|
+
$port = 8787
|
|
650
|
+
$backend = 'anthropic'
|
|
651
|
+
$anyllmProvider = $null
|
|
652
|
+
$region = $null
|
|
653
|
+
$mode = 'token'
|
|
654
|
+
$memory = $false
|
|
655
|
+
$telemetryEnabled = $true
|
|
656
|
+
$image = $HeadroomImage
|
|
657
|
+
|
|
658
|
+
$i = 0
|
|
659
|
+
while ($i -lt $Arguments.Count) {
|
|
660
|
+
$arg = $Arguments[$i]
|
|
661
|
+
switch -Regex ($arg) {
|
|
662
|
+
'^--preset$' {
|
|
663
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option '--preset'
|
|
664
|
+
if ($Arguments[$i + 1] -ne 'persistent-docker') { Fail 'Docker-native wrapper supports only --preset persistent-docker' }
|
|
665
|
+
$i += 2
|
|
666
|
+
continue
|
|
667
|
+
}
|
|
668
|
+
'^--preset=' {
|
|
669
|
+
if (($arg -replace '^--preset=', '') -ne 'persistent-docker') { Fail 'Docker-native wrapper supports only --preset persistent-docker' }
|
|
670
|
+
$i += 1
|
|
671
|
+
continue
|
|
672
|
+
}
|
|
673
|
+
'^--runtime$' {
|
|
674
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option '--runtime'
|
|
675
|
+
if ($Arguments[$i + 1] -ne 'docker') { Fail 'Docker-native wrapper supports only --runtime docker' }
|
|
676
|
+
$i += 2
|
|
677
|
+
continue
|
|
678
|
+
}
|
|
679
|
+
'^--runtime=' {
|
|
680
|
+
if (($arg -replace '^--runtime=', '') -ne 'docker') { Fail 'Docker-native wrapper supports only --runtime docker' }
|
|
681
|
+
$i += 1
|
|
682
|
+
continue
|
|
683
|
+
}
|
|
684
|
+
'^(--scope|--providers|--target)$' { Fail 'Docker-native wrapper install does not support provider/user/system mutation flags; use the Python-native CLI for those flows' }
|
|
685
|
+
'^(--scope=|--providers=|--target=)' { Fail 'Docker-native wrapper install does not support provider/user/system mutation flags; use the Python-native CLI for those flows' }
|
|
686
|
+
'^--profile$' {
|
|
687
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option '--profile'
|
|
688
|
+
$profile = $Arguments[$i + 1]
|
|
689
|
+
$i += 2
|
|
690
|
+
continue
|
|
691
|
+
}
|
|
692
|
+
'^--profile=' {
|
|
693
|
+
$profile = $arg -replace '^--profile=', ''
|
|
694
|
+
$i += 1
|
|
695
|
+
continue
|
|
696
|
+
}
|
|
697
|
+
'^(--port|-p)$' {
|
|
698
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
699
|
+
$port = Parse-PortValue -Value $Arguments[$i + 1]
|
|
700
|
+
$i += 2
|
|
701
|
+
continue
|
|
702
|
+
}
|
|
703
|
+
'^(--port=|-p=)' {
|
|
704
|
+
$port = Parse-PortValue -Value ($arg -replace '^(--port=|-p=)', '')
|
|
705
|
+
$i += 1
|
|
706
|
+
continue
|
|
707
|
+
}
|
|
708
|
+
'^--backend$' {
|
|
709
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option '--backend'
|
|
710
|
+
$backend = $Arguments[$i + 1]
|
|
711
|
+
$i += 2
|
|
712
|
+
continue
|
|
713
|
+
}
|
|
714
|
+
'^--backend=' {
|
|
715
|
+
$backend = $arg -replace '^--backend=', ''
|
|
716
|
+
$i += 1
|
|
717
|
+
continue
|
|
718
|
+
}
|
|
719
|
+
'^--anyllm-provider$' {
|
|
720
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option '--anyllm-provider'
|
|
721
|
+
$anyllmProvider = $Arguments[$i + 1]
|
|
722
|
+
$i += 2
|
|
723
|
+
continue
|
|
724
|
+
}
|
|
725
|
+
'^--anyllm-provider=' {
|
|
726
|
+
$anyllmProvider = $arg -replace '^--anyllm-provider=', ''
|
|
727
|
+
$i += 1
|
|
728
|
+
continue
|
|
729
|
+
}
|
|
730
|
+
'^--region$' {
|
|
731
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option '--region'
|
|
732
|
+
$region = $Arguments[$i + 1]
|
|
733
|
+
$i += 2
|
|
734
|
+
continue
|
|
735
|
+
}
|
|
736
|
+
'^--region=' {
|
|
737
|
+
$region = $arg -replace '^--region=', ''
|
|
738
|
+
$i += 1
|
|
739
|
+
continue
|
|
740
|
+
}
|
|
741
|
+
'^--mode$' {
|
|
742
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option '--mode'
|
|
743
|
+
$mode = $Arguments[$i + 1]
|
|
744
|
+
$i += 2
|
|
745
|
+
continue
|
|
746
|
+
}
|
|
747
|
+
'^--mode=' {
|
|
748
|
+
$mode = $arg -replace '^--mode=', ''
|
|
749
|
+
$i += 1
|
|
750
|
+
continue
|
|
751
|
+
}
|
|
752
|
+
'^--memory$' {
|
|
753
|
+
$memory = $true
|
|
754
|
+
$i += 1
|
|
755
|
+
continue
|
|
756
|
+
}
|
|
757
|
+
'^--no-telemetry$' {
|
|
758
|
+
$telemetryEnabled = $false
|
|
759
|
+
$i += 1
|
|
760
|
+
continue
|
|
761
|
+
}
|
|
762
|
+
'^--image$' {
|
|
763
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option '--image'
|
|
764
|
+
$image = $Arguments[$i + 1]
|
|
765
|
+
$i += 2
|
|
766
|
+
continue
|
|
767
|
+
}
|
|
768
|
+
'^--image=' {
|
|
769
|
+
$image = $arg -replace '^--image=', ''
|
|
770
|
+
$i += 1
|
|
771
|
+
continue
|
|
772
|
+
}
|
|
773
|
+
'^(--help|-\?)$' {
|
|
774
|
+
Show-InstallApplyHelp
|
|
775
|
+
exit 0
|
|
776
|
+
}
|
|
777
|
+
default {
|
|
778
|
+
Fail "Unsupported option for 'xtream-head install apply': $arg"
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
return [pscustomobject]@{
|
|
784
|
+
Profile = $profile
|
|
785
|
+
Port = $port
|
|
786
|
+
Backend = $backend
|
|
787
|
+
AnyllmProvider = $anyllmProvider
|
|
788
|
+
Region = $region
|
|
789
|
+
Mode = $mode
|
|
790
|
+
Memory = $memory
|
|
791
|
+
TelemetryEnabled = $telemetryEnabled
|
|
792
|
+
Image = $image
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function Parse-InstallProfileArgs {
|
|
797
|
+
param([string[]]$Arguments)
|
|
798
|
+
|
|
799
|
+
$profile = 'default'
|
|
800
|
+
$i = 0
|
|
801
|
+
while ($i -lt $Arguments.Count) {
|
|
802
|
+
$arg = $Arguments[$i]
|
|
803
|
+
switch -Regex ($arg) {
|
|
804
|
+
'^--profile$' {
|
|
805
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option '--profile'
|
|
806
|
+
$profile = $Arguments[$i + 1]
|
|
807
|
+
$i += 2
|
|
808
|
+
continue
|
|
809
|
+
}
|
|
810
|
+
'^--profile=' {
|
|
811
|
+
$profile = $arg -replace '^--profile=', ''
|
|
812
|
+
$i += 1
|
|
813
|
+
continue
|
|
814
|
+
}
|
|
815
|
+
'^(--help|-\?)$' {
|
|
816
|
+
Show-InstallHelp
|
|
817
|
+
exit 0
|
|
818
|
+
}
|
|
819
|
+
default {
|
|
820
|
+
Fail "Unsupported option for 'xtream-head install': $arg"
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return $profile
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
function Invoke-ClaudeRtkInit {
|
|
829
|
+
$rtkPath = Join-Path $HostHome '.headroom\bin\rtk.exe'
|
|
830
|
+
if (-not (Test-Path $rtkPath)) {
|
|
831
|
+
Write-Warning "rtk was not installed at $rtkPath; Claude hooks were not registered"
|
|
832
|
+
return
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
try {
|
|
836
|
+
& $rtkPath init --global --auto-patch | Out-Null
|
|
837
|
+
} catch {
|
|
838
|
+
Write-Warning "Failed to register Claude hooks with rtk; continuing without hook registration"
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function Get-ContextTool {
|
|
843
|
+
$value = $env:HEADROOM_CONTEXT_TOOL
|
|
844
|
+
if ([string]::IsNullOrWhiteSpace($value)) {
|
|
845
|
+
return 'rtk'
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
$value = $value.Trim().ToLowerInvariant().Replace('_', '-')
|
|
849
|
+
if ($value -eq 'leanctx') {
|
|
850
|
+
return 'lean-ctx'
|
|
851
|
+
}
|
|
852
|
+
if ($value -ne 'rtk' -and $value -ne 'lean-ctx') {
|
|
853
|
+
Fail 'HEADROOM_CONTEXT_TOOL must be one of: lean-ctx, rtk'
|
|
854
|
+
}
|
|
855
|
+
return $value
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
function Invoke-LeanCtxInit {
|
|
859
|
+
param([string]$Agent)
|
|
860
|
+
|
|
861
|
+
$cmd = Get-Command lean-ctx -ErrorAction SilentlyContinue
|
|
862
|
+
if (-not $cmd) {
|
|
863
|
+
Write-Warning "lean-ctx is not installed on PATH; $Agent lean-ctx setup was skipped"
|
|
864
|
+
return
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
try {
|
|
868
|
+
& $cmd.Source init --agent $Agent | Out-Null
|
|
869
|
+
} catch {
|
|
870
|
+
Write-Warning "Failed to initialize lean-ctx for $Agent; continuing without lean-ctx setup"
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
function Invoke-WithTemporaryEnv {
|
|
875
|
+
param(
|
|
876
|
+
[hashtable]$Environment,
|
|
877
|
+
[string]$Command,
|
|
878
|
+
[string[]]$Arguments
|
|
879
|
+
)
|
|
880
|
+
|
|
881
|
+
$previous = @{}
|
|
882
|
+
foreach ($pair in $Environment.GetEnumerator()) {
|
|
883
|
+
$previous[$pair.Key] = [Environment]::GetEnvironmentVariable($pair.Key, 'Process')
|
|
884
|
+
[Environment]::SetEnvironmentVariable($pair.Key, $pair.Value, 'Process')
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
try {
|
|
888
|
+
& $Command @Arguments
|
|
889
|
+
return $LASTEXITCODE
|
|
890
|
+
} finally {
|
|
891
|
+
foreach ($pair in $Environment.GetEnumerator()) {
|
|
892
|
+
[Environment]::SetEnvironmentVariable($pair.Key, $previous[$pair.Key], 'Process')
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
function Test-HelpFlag {
|
|
898
|
+
param([string[]]$Arguments)
|
|
899
|
+
|
|
900
|
+
foreach ($arg in $Arguments) {
|
|
901
|
+
if ($arg -eq '--') {
|
|
902
|
+
break
|
|
903
|
+
}
|
|
904
|
+
if ($arg -eq '--help' -or $arg -eq '-?') {
|
|
905
|
+
return $true
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
return $false
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function Parse-OpenClawWrapArgs {
|
|
913
|
+
param([string[]]$Arguments)
|
|
914
|
+
|
|
915
|
+
$gatewayProviderIds = New-Object System.Collections.Generic.List[string]
|
|
916
|
+
$pluginPath = $null
|
|
917
|
+
$pluginSpec = 'xtream-head/openclaw'
|
|
918
|
+
$skipBuild = $false
|
|
919
|
+
$copy = $false
|
|
920
|
+
$proxyPort = 8787
|
|
921
|
+
$startupTimeoutMs = 20000
|
|
922
|
+
$pythonPath = $null
|
|
923
|
+
$noAutoStart = $false
|
|
924
|
+
$noRestart = $false
|
|
925
|
+
$verbose = $false
|
|
926
|
+
|
|
927
|
+
$i = 0
|
|
928
|
+
while ($i -lt $Arguments.Count) {
|
|
929
|
+
$arg = $Arguments[$i]
|
|
930
|
+
switch -Regex ($arg) {
|
|
931
|
+
'^--plugin-path$' {
|
|
932
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
933
|
+
$pluginPath = $Arguments[$i + 1]
|
|
934
|
+
$i += 2
|
|
935
|
+
continue
|
|
936
|
+
}
|
|
937
|
+
'^--plugin-path=' {
|
|
938
|
+
$pluginPath = $arg -replace '^--plugin-path=', ''
|
|
939
|
+
$i += 1
|
|
940
|
+
continue
|
|
941
|
+
}
|
|
942
|
+
'^--plugin-spec$' {
|
|
943
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
944
|
+
$pluginSpec = $Arguments[$i + 1]
|
|
945
|
+
$i += 2
|
|
946
|
+
continue
|
|
947
|
+
}
|
|
948
|
+
'^--plugin-spec=' {
|
|
949
|
+
$pluginSpec = $arg -replace '^--plugin-spec=', ''
|
|
950
|
+
$i += 1
|
|
951
|
+
continue
|
|
952
|
+
}
|
|
953
|
+
'^--skip-build$' {
|
|
954
|
+
$skipBuild = $true
|
|
955
|
+
$i += 1
|
|
956
|
+
continue
|
|
957
|
+
}
|
|
958
|
+
'^--copy$' {
|
|
959
|
+
$copy = $true
|
|
960
|
+
$i += 1
|
|
961
|
+
continue
|
|
962
|
+
}
|
|
963
|
+
'^--proxy-port$' {
|
|
964
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
965
|
+
$proxyPort = Parse-PortValue -Value $Arguments[$i + 1]
|
|
966
|
+
$i += 2
|
|
967
|
+
continue
|
|
968
|
+
}
|
|
969
|
+
'^--proxy-port=' {
|
|
970
|
+
$proxyPort = Parse-PortValue -Value ($arg -replace '^--proxy-port=', '')
|
|
971
|
+
$i += 1
|
|
972
|
+
continue
|
|
973
|
+
}
|
|
974
|
+
'^--startup-timeout-ms$' {
|
|
975
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
976
|
+
$startupTimeoutMs = Parse-PositiveIntegerValue -Value $Arguments[$i + 1]
|
|
977
|
+
$i += 2
|
|
978
|
+
continue
|
|
979
|
+
}
|
|
980
|
+
'^--startup-timeout-ms=' {
|
|
981
|
+
$startupTimeoutMs = Parse-PositiveIntegerValue -Value ($arg -replace '^--startup-timeout-ms=', '')
|
|
982
|
+
$i += 1
|
|
983
|
+
continue
|
|
984
|
+
}
|
|
985
|
+
'^--gateway-provider-id$' {
|
|
986
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
987
|
+
$gatewayProviderIds.Add($Arguments[$i + 1])
|
|
988
|
+
$i += 2
|
|
989
|
+
continue
|
|
990
|
+
}
|
|
991
|
+
'^--gateway-provider-id=' {
|
|
992
|
+
$gatewayProviderIds.Add($arg -replace '^--gateway-provider-id=', '')
|
|
993
|
+
$i += 1
|
|
994
|
+
continue
|
|
995
|
+
}
|
|
996
|
+
'^--python-path$' {
|
|
997
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
998
|
+
$pythonPath = $Arguments[$i + 1]
|
|
999
|
+
$i += 2
|
|
1000
|
+
continue
|
|
1001
|
+
}
|
|
1002
|
+
'^--python-path=' {
|
|
1003
|
+
$pythonPath = $arg -replace '^--python-path=', ''
|
|
1004
|
+
$i += 1
|
|
1005
|
+
continue
|
|
1006
|
+
}
|
|
1007
|
+
'^--no-auto-start$' {
|
|
1008
|
+
$noAutoStart = $true
|
|
1009
|
+
$i += 1
|
|
1010
|
+
continue
|
|
1011
|
+
}
|
|
1012
|
+
'^--no-restart$' {
|
|
1013
|
+
$noRestart = $true
|
|
1014
|
+
$i += 1
|
|
1015
|
+
continue
|
|
1016
|
+
}
|
|
1017
|
+
'^--verbose$|^-v$' {
|
|
1018
|
+
$verbose = $true
|
|
1019
|
+
$i += 1
|
|
1020
|
+
continue
|
|
1021
|
+
}
|
|
1022
|
+
default {
|
|
1023
|
+
Fail "Unsupported option for 'xtream-head wrap openclaw': $arg"
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
[pscustomobject]@{
|
|
1029
|
+
PluginPath = $pluginPath
|
|
1030
|
+
PluginSpec = $pluginSpec
|
|
1031
|
+
SkipBuild = $skipBuild
|
|
1032
|
+
Copy = $copy
|
|
1033
|
+
ProxyPort = $proxyPort
|
|
1034
|
+
StartupTimeoutMs = $startupTimeoutMs
|
|
1035
|
+
GatewayProviderIds = $gatewayProviderIds.ToArray()
|
|
1036
|
+
PythonPath = $pythonPath
|
|
1037
|
+
NoAutoStart = $noAutoStart
|
|
1038
|
+
NoRestart = $noRestart
|
|
1039
|
+
Verbose = $verbose
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
function Parse-OpenClawUnwrapArgs {
|
|
1044
|
+
param([string[]]$Arguments)
|
|
1045
|
+
|
|
1046
|
+
$noRestart = $false
|
|
1047
|
+
$verbose = $false
|
|
1048
|
+
$i = 0
|
|
1049
|
+
while ($i -lt $Arguments.Count) {
|
|
1050
|
+
$arg = $Arguments[$i]
|
|
1051
|
+
switch -Regex ($arg) {
|
|
1052
|
+
'^--no-restart$' {
|
|
1053
|
+
$noRestart = $true
|
|
1054
|
+
$i += 1
|
|
1055
|
+
continue
|
|
1056
|
+
}
|
|
1057
|
+
'^--verbose$|^-v$' {
|
|
1058
|
+
$verbose = $true
|
|
1059
|
+
$i += 1
|
|
1060
|
+
continue
|
|
1061
|
+
}
|
|
1062
|
+
default {
|
|
1063
|
+
Fail "Unsupported option for 'xtream-head unwrap openclaw': $arg"
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
[pscustomobject]@{
|
|
1069
|
+
NoRestart = $noRestart
|
|
1070
|
+
Verbose = $verbose
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
function Invoke-CapturedCommand {
|
|
1075
|
+
param(
|
|
1076
|
+
[string]$Action,
|
|
1077
|
+
[string]$Command,
|
|
1078
|
+
[string[]]$Arguments,
|
|
1079
|
+
[string]$WorkingDirectory
|
|
1080
|
+
)
|
|
1081
|
+
|
|
1082
|
+
$previous = $null
|
|
1083
|
+
try {
|
|
1084
|
+
if ($WorkingDirectory) {
|
|
1085
|
+
$previous = Get-Location
|
|
1086
|
+
Set-Location $WorkingDirectory
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
$output = (& $Command @Arguments 2>&1 | Out-String).Trim()
|
|
1090
|
+
$exitCode = $LASTEXITCODE
|
|
1091
|
+
} finally {
|
|
1092
|
+
if ($previous) {
|
|
1093
|
+
Set-Location $previous
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
if ($exitCode -ne 0) {
|
|
1098
|
+
if (-not $output) {
|
|
1099
|
+
$output = "exit code $exitCode"
|
|
1100
|
+
}
|
|
1101
|
+
Fail "$Action failed: $output"
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
return $output
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
function Get-OpenClawExistingEntryJson {
|
|
1108
|
+
$output = (& openclaw config get plugins.entries.headroom 2>$null | Out-String).Trim()
|
|
1109
|
+
if ($LASTEXITCODE -ne 0) {
|
|
1110
|
+
return $null
|
|
1111
|
+
}
|
|
1112
|
+
return $output
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
function Invoke-OpenClawPrepareEntryJson {
|
|
1116
|
+
param(
|
|
1117
|
+
[string]$ExistingEntryJson,
|
|
1118
|
+
[pscustomobject]$Parsed
|
|
1119
|
+
)
|
|
1120
|
+
|
|
1121
|
+
$dockerArgs = New-Object System.Collections.Generic.List[string]
|
|
1122
|
+
$dockerArgs.AddRange([string[]]@('run','--rm'))
|
|
1123
|
+
$dockerArgs.AddRange((Get-SharedDockerArgs))
|
|
1124
|
+
$dockerArgs.Add('--entrypoint')
|
|
1125
|
+
$dockerArgs.Add('headroom')
|
|
1126
|
+
$dockerArgs.Add($HeadroomImage)
|
|
1127
|
+
$dockerArgs.AddRange([string[]]@('wrap','openclaw','--prepare-only','--proxy-port',"$($Parsed.ProxyPort)",'--startup-timeout-ms',"$($Parsed.StartupTimeoutMs)"))
|
|
1128
|
+
if ($ExistingEntryJson) {
|
|
1129
|
+
$dockerArgs.Add('--existing-entry-json')
|
|
1130
|
+
$dockerArgs.Add($ExistingEntryJson)
|
|
1131
|
+
}
|
|
1132
|
+
if ($Parsed.PythonPath) {
|
|
1133
|
+
$dockerArgs.Add('--python-path')
|
|
1134
|
+
$dockerArgs.Add($Parsed.PythonPath)
|
|
1135
|
+
}
|
|
1136
|
+
if ($Parsed.NoAutoStart) {
|
|
1137
|
+
$dockerArgs.Add('--no-auto-start')
|
|
1138
|
+
}
|
|
1139
|
+
foreach ($providerId in $Parsed.GatewayProviderIds) {
|
|
1140
|
+
$dockerArgs.Add('--gateway-provider-id')
|
|
1141
|
+
$dockerArgs.Add($providerId)
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
$output = (& docker @dockerArgs 2>&1 | Out-String).Trim()
|
|
1145
|
+
if ($LASTEXITCODE -ne 0) {
|
|
1146
|
+
Fail "Failed to prepare docker-native OpenClaw config: $output"
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
return $output
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
function Invoke-OpenClawPrepareUnwrapEntryJson {
|
|
1153
|
+
param([string]$ExistingEntryJson)
|
|
1154
|
+
|
|
1155
|
+
$dockerArgs = New-Object System.Collections.Generic.List[string]
|
|
1156
|
+
$dockerArgs.AddRange([string[]]@('run','--rm'))
|
|
1157
|
+
$dockerArgs.AddRange((Get-SharedDockerArgs))
|
|
1158
|
+
$dockerArgs.Add('--entrypoint')
|
|
1159
|
+
$dockerArgs.Add('headroom')
|
|
1160
|
+
$dockerArgs.Add($HeadroomImage)
|
|
1161
|
+
$dockerArgs.AddRange([string[]]@('unwrap','openclaw','--prepare-only'))
|
|
1162
|
+
if ($ExistingEntryJson) {
|
|
1163
|
+
$dockerArgs.Add('--existing-entry-json')
|
|
1164
|
+
$dockerArgs.Add($ExistingEntryJson)
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
$output = (& docker @dockerArgs 2>&1 | Out-String).Trim()
|
|
1168
|
+
if ($LASTEXITCODE -ne 0) {
|
|
1169
|
+
Fail "Failed to prepare docker-native OpenClaw unwrap config: $output"
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
return $output
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
function Resolve-OpenClawExtensionsDir {
|
|
1176
|
+
$configOutput = Invoke-CapturedCommand -Action 'openclaw config file' -Command 'openclaw' -Arguments @('config','file')
|
|
1177
|
+
$configPath = ($configOutput -split "`r?`n")[-1].Trim()
|
|
1178
|
+
if (-not $configPath) {
|
|
1179
|
+
Fail 'Unable to resolve OpenClaw config path.'
|
|
1180
|
+
}
|
|
1181
|
+
return (Join-Path (Split-Path -Parent $configPath) 'extensions')
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
function Copy-OpenClawPluginIntoExtensions {
|
|
1185
|
+
param([string]$PluginPath)
|
|
1186
|
+
|
|
1187
|
+
$distDir = Join-Path $PluginPath 'dist'
|
|
1188
|
+
$hookShimDir = Join-Path $PluginPath 'hook-shim'
|
|
1189
|
+
if (-not (Test-Path $distDir)) {
|
|
1190
|
+
Fail "Plugin dist folder missing at $distDir. Build the plugin first."
|
|
1191
|
+
}
|
|
1192
|
+
if (-not (Test-Path $hookShimDir)) {
|
|
1193
|
+
Fail "Plugin hook-shim folder missing at $hookShimDir. Build the plugin first."
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
$extensionsDir = Resolve-OpenClawExtensionsDir
|
|
1197
|
+
$targetDir = Join-Path $extensionsDir 'headroom'
|
|
1198
|
+
$targetDist = Join-Path $targetDir 'dist'
|
|
1199
|
+
$targetHookShim = Join-Path $targetDir 'hook-shim'
|
|
1200
|
+
New-Item -ItemType Directory -Force -Path $targetDir | Out-Null
|
|
1201
|
+
if (Test-Path $targetDist) { Remove-Item -Recurse -Force $targetDist }
|
|
1202
|
+
if (Test-Path $targetHookShim) { Remove-Item -Recurse -Force $targetHookShim }
|
|
1203
|
+
Copy-Item -Recurse -Force $distDir $targetDist
|
|
1204
|
+
Copy-Item -Recurse -Force $hookShimDir $targetHookShim
|
|
1205
|
+
|
|
1206
|
+
foreach ($fileName in @('openclaw.plugin.json','package.json','README.md')) {
|
|
1207
|
+
$source = Join-Path $PluginPath $fileName
|
|
1208
|
+
if (Test-Path $source) {
|
|
1209
|
+
Copy-Item -Force $source (Join-Path $targetDir $fileName)
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
return $targetDir
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
function Install-OpenClawPlugin {
|
|
1217
|
+
param([pscustomobject]$Parsed)
|
|
1218
|
+
|
|
1219
|
+
if ($Parsed.PluginPath) {
|
|
1220
|
+
if (-not (Test-Path $Parsed.PluginPath)) {
|
|
1221
|
+
Fail "Plugin path not found: $($Parsed.PluginPath)."
|
|
1222
|
+
}
|
|
1223
|
+
if (-not (Test-Path (Join-Path $Parsed.PluginPath 'package.json'))) {
|
|
1224
|
+
Fail "Invalid plugin path (missing package.json): $($Parsed.PluginPath)"
|
|
1225
|
+
}
|
|
1226
|
+
if (-not (Test-Path (Join-Path $Parsed.PluginPath 'openclaw.plugin.json'))) {
|
|
1227
|
+
Fail "Invalid plugin path (missing openclaw.plugin.json): $($Parsed.PluginPath)"
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
if ($Parsed.PluginPath -and -not $Parsed.SkipBuild) {
|
|
1232
|
+
Require-Command npm
|
|
1233
|
+
Write-Host ' Building OpenClaw plugin (npm install + npm run build)...'
|
|
1234
|
+
[void](Invoke-CapturedCommand -Action 'npm install' -Command 'npm' -Arguments @('install') -WorkingDirectory $Parsed.PluginPath)
|
|
1235
|
+
[void](Invoke-CapturedCommand -Action 'npm run build' -Command 'npm' -Arguments @('run','build') -WorkingDirectory $Parsed.PluginPath)
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
if ($Parsed.PluginPath) {
|
|
1239
|
+
if ($Parsed.Copy) {
|
|
1240
|
+
$arguments = @('plugins','install','--dangerously-force-unsafe-install',$Parsed.PluginPath)
|
|
1241
|
+
$workingDirectory = $null
|
|
1242
|
+
} else {
|
|
1243
|
+
$arguments = @('plugins','install','--dangerously-force-unsafe-install','--link','.')
|
|
1244
|
+
$workingDirectory = $Parsed.PluginPath
|
|
1245
|
+
}
|
|
1246
|
+
} else {
|
|
1247
|
+
$arguments = @('plugins','install','--dangerously-force-unsafe-install',$Parsed.PluginSpec)
|
|
1248
|
+
$workingDirectory = $null
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
$previous = $null
|
|
1252
|
+
try {
|
|
1253
|
+
if ($workingDirectory) {
|
|
1254
|
+
$previous = Get-Location
|
|
1255
|
+
Set-Location $workingDirectory
|
|
1256
|
+
}
|
|
1257
|
+
$installOutput = (& openclaw @arguments 2>&1 | Out-String).Trim()
|
|
1258
|
+
$installExitCode = $LASTEXITCODE
|
|
1259
|
+
} finally {
|
|
1260
|
+
if ($previous) {
|
|
1261
|
+
Set-Location $previous
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
if ($installExitCode -eq 0) {
|
|
1266
|
+
if ($Parsed.Verbose -and $installOutput) {
|
|
1267
|
+
Write-Host $installOutput
|
|
1268
|
+
}
|
|
1269
|
+
return
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
$lowerOutput = $installOutput.ToLowerInvariant()
|
|
1273
|
+
if ($lowerOutput.Contains('plugin already exists')) {
|
|
1274
|
+
Write-Host ' Plugin already installed; continuing with configuration/update steps.'
|
|
1275
|
+
return
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
if ($Parsed.PluginPath -and -not $Parsed.Copy -and $lowerOutput.Contains('also not a valid hook pack')) {
|
|
1279
|
+
Write-Host ' OpenClaw linked-path install bug detected; applying extension-path fallback...'
|
|
1280
|
+
$targetDir = Copy-OpenClawPluginIntoExtensions -PluginPath $Parsed.PluginPath
|
|
1281
|
+
Write-Host " Fallback plugin copy completed: $targetDir"
|
|
1282
|
+
return
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
if (-not $installOutput) {
|
|
1286
|
+
$installOutput = "exit code $installExitCode"
|
|
1287
|
+
}
|
|
1288
|
+
Fail "openclaw plugins install failed: $installOutput"
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
function Restart-OrStartOpenClawGateway {
|
|
1292
|
+
$restartOutput = (& openclaw gateway restart 2>&1 | Out-String).Trim()
|
|
1293
|
+
if ($LASTEXITCODE -eq 0) {
|
|
1294
|
+
return [pscustomobject]@{ Action = 'restarted'; Output = $restartOutput }
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
$startOutput = Invoke-CapturedCommand -Action 'openclaw gateway start' -Command 'openclaw' -Arguments @('gateway','start')
|
|
1298
|
+
return [pscustomobject]@{ Action = 'started'; Output = $startOutput }
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
function Invoke-OpenClawWrap {
|
|
1302
|
+
param([string[]]$Arguments)
|
|
1303
|
+
|
|
1304
|
+
Require-Command openclaw
|
|
1305
|
+
$parsed = Parse-OpenClawWrapArgs -Arguments $Arguments
|
|
1306
|
+
$existingEntryJson = Get-OpenClawExistingEntryJson
|
|
1307
|
+
$entryJson = Invoke-OpenClawPrepareEntryJson -ExistingEntryJson $existingEntryJson -Parsed $parsed
|
|
1308
|
+
|
|
1309
|
+
Write-Host ""
|
|
1310
|
+
Write-Host " ╔═══════════════════════════════════════════════╗"
|
|
1311
|
+
Write-Host " ║ HEADROOM WRAP: OPENCLAW ║"
|
|
1312
|
+
Write-Host " ╚═══════════════════════════════════════════════╝"
|
|
1313
|
+
Write-Host ""
|
|
1314
|
+
if ($parsed.PluginPath) {
|
|
1315
|
+
Write-Host " Plugin source: local ($($parsed.PluginPath))"
|
|
1316
|
+
} else {
|
|
1317
|
+
Write-Host " Plugin source: npm ($($parsed.PluginSpec))"
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
Write-Host ' Writing plugin configuration...'
|
|
1321
|
+
[void](Invoke-CapturedCommand -Action 'openclaw config set plugins.entries.headroom' -Command 'openclaw' -Arguments @('config','set','plugins.entries.headroom',$entryJson,'--strict-json'))
|
|
1322
|
+
Write-Host ' Installing OpenClaw plugin with required unsafe-install flag...'
|
|
1323
|
+
Install-OpenClawPlugin -Parsed $parsed
|
|
1324
|
+
[void](Invoke-CapturedCommand -Action 'openclaw config set plugins.slots.contextEngine' -Command 'openclaw' -Arguments @('config','set','plugins.slots.contextEngine','"headroom"','--strict-json'))
|
|
1325
|
+
[void](Invoke-CapturedCommand -Action 'openclaw config validate' -Command 'openclaw' -Arguments @('config','validate'))
|
|
1326
|
+
|
|
1327
|
+
if ($parsed.NoRestart) {
|
|
1328
|
+
Write-Host ' Skipping gateway restart (--no-restart).'
|
|
1329
|
+
Write-Host ' Run `openclaw gateway restart` (or `openclaw gateway start`) to apply plugin changes.'
|
|
1330
|
+
} else {
|
|
1331
|
+
Write-Host ' Applying plugin changes to OpenClaw gateway...'
|
|
1332
|
+
$gatewayResult = Restart-OrStartOpenClawGateway
|
|
1333
|
+
Write-Host " Gateway $($gatewayResult.Action)."
|
|
1334
|
+
if ($parsed.Verbose -and $gatewayResult.Output) {
|
|
1335
|
+
Write-Host $gatewayResult.Output
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
$inspectOutput = Invoke-CapturedCommand -Action 'openclaw plugins inspect headroom' -Command 'openclaw' -Arguments @('plugins','inspect','headroom')
|
|
1340
|
+
if ($parsed.Verbose -and $inspectOutput) {
|
|
1341
|
+
Write-Host $inspectOutput
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
Write-Host ""
|
|
1345
|
+
Write-Host "✓ OpenClaw is configured to use Xtream Head context compression."
|
|
1346
|
+
Write-Host " Plugin: headroom"
|
|
1347
|
+
Write-Host " Slot: plugins.slots.contextEngine = headroom"
|
|
1348
|
+
Write-Host ""
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
function Invoke-OpenClawUnwrap {
|
|
1352
|
+
param([string[]]$Arguments)
|
|
1353
|
+
|
|
1354
|
+
Require-Command openclaw
|
|
1355
|
+
$parsed = Parse-OpenClawUnwrapArgs -Arguments $Arguments
|
|
1356
|
+
$existingEntryJson = Get-OpenClawExistingEntryJson
|
|
1357
|
+
$entryJson = Invoke-OpenClawPrepareUnwrapEntryJson -ExistingEntryJson $existingEntryJson
|
|
1358
|
+
|
|
1359
|
+
Write-Host ""
|
|
1360
|
+
Write-Host " ╔═══════════════════════════════════════════════╗"
|
|
1361
|
+
Write-Host " ║ HEADROOM UNWRAP: OPENCLAW ║"
|
|
1362
|
+
Write-Host " ╚═══════════════════════════════════════════════╝"
|
|
1363
|
+
Write-Host ""
|
|
1364
|
+
Write-Host ' Disabling Headroom plugin and removing engine mapping...'
|
|
1365
|
+
|
|
1366
|
+
[void](Invoke-CapturedCommand -Action 'openclaw config set plugins.entries.headroom' -Command 'openclaw' -Arguments @('config','set','plugins.entries.headroom',$entryJson,'--strict-json'))
|
|
1367
|
+
[void](Invoke-CapturedCommand -Action 'openclaw config set plugins.slots.contextEngine' -Command 'openclaw' -Arguments @('config','set','plugins.slots.contextEngine','"legacy"','--strict-json'))
|
|
1368
|
+
[void](Invoke-CapturedCommand -Action 'openclaw config validate' -Command 'openclaw' -Arguments @('config','validate'))
|
|
1369
|
+
|
|
1370
|
+
if ($parsed.NoRestart) {
|
|
1371
|
+
Write-Host ' Skipping gateway restart (--no-restart).'
|
|
1372
|
+
Write-Host ' Run `openclaw gateway restart` (or `openclaw gateway start`) to apply unwrap changes.'
|
|
1373
|
+
} else {
|
|
1374
|
+
Write-Host ' Applying unwrap changes to OpenClaw gateway...'
|
|
1375
|
+
$gatewayResult = Restart-OrStartOpenClawGateway
|
|
1376
|
+
Write-Host " Gateway $($gatewayResult.Action)."
|
|
1377
|
+
if ($parsed.Verbose -and $gatewayResult.Output) {
|
|
1378
|
+
Write-Host $gatewayResult.Output
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
if ($parsed.Verbose) {
|
|
1383
|
+
$inspectOutput = Invoke-CapturedCommand -Action 'openclaw plugins inspect headroom' -Command 'openclaw' -Arguments @('plugins','inspect','headroom')
|
|
1384
|
+
if ($inspectOutput) {
|
|
1385
|
+
Write-Host $inspectOutput
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
Write-Host ""
|
|
1390
|
+
Write-Host "✓ OpenClaw Headroom wrap removed."
|
|
1391
|
+
Write-Host " Plugin: headroom (installed, disabled)"
|
|
1392
|
+
Write-Host " Slot: plugins.slots.contextEngine = legacy"
|
|
1393
|
+
Write-Host ""
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
function Parse-WrapArgs {
|
|
1397
|
+
param([string[]]$Arguments)
|
|
1398
|
+
|
|
1399
|
+
$known = New-Object System.Collections.Generic.List[string]
|
|
1400
|
+
$hostArgs = New-Object System.Collections.Generic.List[string]
|
|
1401
|
+
$port = 8787
|
|
1402
|
+
$noRtk = $false
|
|
1403
|
+
$noProxy = $false
|
|
1404
|
+
$learn = $false
|
|
1405
|
+
$backend = $null
|
|
1406
|
+
$anyllm = $null
|
|
1407
|
+
$region = $null
|
|
1408
|
+
|
|
1409
|
+
$i = 0
|
|
1410
|
+
while ($i -lt $Arguments.Count) {
|
|
1411
|
+
$arg = $Arguments[$i]
|
|
1412
|
+
switch -Regex ($arg) {
|
|
1413
|
+
'^--$' {
|
|
1414
|
+
for ($j = $i + 1; $j -lt $Arguments.Count; $j++) {
|
|
1415
|
+
$hostArgs.Add($Arguments[$j])
|
|
1416
|
+
}
|
|
1417
|
+
$i = $Arguments.Count
|
|
1418
|
+
continue
|
|
1419
|
+
}
|
|
1420
|
+
'^--port$|^-p$' {
|
|
1421
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
1422
|
+
$port = Parse-PortValue -Value $Arguments[$i + 1]
|
|
1423
|
+
$known.Add($arg)
|
|
1424
|
+
$known.Add($Arguments[$i + 1])
|
|
1425
|
+
$i += 2
|
|
1426
|
+
continue
|
|
1427
|
+
}
|
|
1428
|
+
'^--port=' {
|
|
1429
|
+
$port = Parse-PortValue -Value ($arg -replace '^--port=', '')
|
|
1430
|
+
$known.Add($arg)
|
|
1431
|
+
$i += 1
|
|
1432
|
+
continue
|
|
1433
|
+
}
|
|
1434
|
+
'^--no-rtk$' {
|
|
1435
|
+
$noRtk = $true
|
|
1436
|
+
$known.Add($arg)
|
|
1437
|
+
$i += 1
|
|
1438
|
+
continue
|
|
1439
|
+
}
|
|
1440
|
+
'^--no-proxy$' {
|
|
1441
|
+
$noProxy = $true
|
|
1442
|
+
$known.Add($arg)
|
|
1443
|
+
$i += 1
|
|
1444
|
+
continue
|
|
1445
|
+
}
|
|
1446
|
+
'^--learn$' {
|
|
1447
|
+
$learn = $true
|
|
1448
|
+
$known.Add($arg)
|
|
1449
|
+
$i += 1
|
|
1450
|
+
continue
|
|
1451
|
+
}
|
|
1452
|
+
'^--verbose$|^-v$' {
|
|
1453
|
+
$known.Add($arg)
|
|
1454
|
+
$i += 1
|
|
1455
|
+
continue
|
|
1456
|
+
}
|
|
1457
|
+
'^--backend$' {
|
|
1458
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
1459
|
+
$backend = $Arguments[$i + 1]
|
|
1460
|
+
$known.Add($arg)
|
|
1461
|
+
$known.Add($Arguments[$i + 1])
|
|
1462
|
+
$i += 2
|
|
1463
|
+
continue
|
|
1464
|
+
}
|
|
1465
|
+
'^--backend=' {
|
|
1466
|
+
$backend = $arg -replace '^--backend=', ''
|
|
1467
|
+
$known.Add($arg)
|
|
1468
|
+
$i += 1
|
|
1469
|
+
continue
|
|
1470
|
+
}
|
|
1471
|
+
'^--anyllm-provider$' {
|
|
1472
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
1473
|
+
$anyllm = $Arguments[$i + 1]
|
|
1474
|
+
$known.Add($arg)
|
|
1475
|
+
$known.Add($Arguments[$i + 1])
|
|
1476
|
+
$i += 2
|
|
1477
|
+
continue
|
|
1478
|
+
}
|
|
1479
|
+
'^--anyllm-provider=' {
|
|
1480
|
+
$anyllm = $arg -replace '^--anyllm-provider=', ''
|
|
1481
|
+
$known.Add($arg)
|
|
1482
|
+
$i += 1
|
|
1483
|
+
continue
|
|
1484
|
+
}
|
|
1485
|
+
'^--region$' {
|
|
1486
|
+
Require-OptionValue -Arguments $Arguments -Index $i -Option $arg
|
|
1487
|
+
$region = $Arguments[$i + 1]
|
|
1488
|
+
$known.Add($arg)
|
|
1489
|
+
$known.Add($Arguments[$i + 1])
|
|
1490
|
+
$i += 2
|
|
1491
|
+
continue
|
|
1492
|
+
}
|
|
1493
|
+
'^--region=' {
|
|
1494
|
+
$region = $arg -replace '^--region=', ''
|
|
1495
|
+
$known.Add($arg)
|
|
1496
|
+
$i += 1
|
|
1497
|
+
continue
|
|
1498
|
+
}
|
|
1499
|
+
default {
|
|
1500
|
+
for ($j = $i; $j -lt $Arguments.Count; $j++) {
|
|
1501
|
+
$hostArgs.Add($Arguments[$j])
|
|
1502
|
+
}
|
|
1503
|
+
$i = $Arguments.Count
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
[pscustomobject]@{
|
|
1509
|
+
KnownArgs = $known.ToArray()
|
|
1510
|
+
HostArgs = $hostArgs.ToArray()
|
|
1511
|
+
Port = $port
|
|
1512
|
+
NoRtk = $noRtk
|
|
1513
|
+
NoProxy = $noProxy
|
|
1514
|
+
Learn = $learn
|
|
1515
|
+
Backend = $backend
|
|
1516
|
+
Anyllm = $anyllm
|
|
1517
|
+
Region = $region
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
function Invoke-PrepareOnly {
|
|
1522
|
+
param(
|
|
1523
|
+
[string]$Tool,
|
|
1524
|
+
[string[]]$KnownArgs
|
|
1525
|
+
)
|
|
1526
|
+
|
|
1527
|
+
$dockerArgs = New-Object System.Collections.Generic.List[string]
|
|
1528
|
+
$dockerArgs.AddRange([string[]]@('run','--rm'))
|
|
1529
|
+
Add-TtyArgs -ArgsList $dockerArgs
|
|
1530
|
+
$dockerArgs.AddRange((Get-SharedDockerArgs))
|
|
1531
|
+
$dockerArgs.Add('--env')
|
|
1532
|
+
$dockerArgs.Add("HEADROOM_RTK_TARGET=$(Get-RtkTarget)")
|
|
1533
|
+
$dockerArgs.Add('--entrypoint')
|
|
1534
|
+
$dockerArgs.Add('headroom')
|
|
1535
|
+
$dockerArgs.Add($HeadroomImage)
|
|
1536
|
+
$dockerArgs.AddRange([string[]]@('wrap',$Tool,'--prepare-only'))
|
|
1537
|
+
foreach ($arg in $KnownArgs) {
|
|
1538
|
+
$dockerArgs.Add($arg)
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
& docker @dockerArgs
|
|
1542
|
+
if ($LASTEXITCODE -ne 0) {
|
|
1543
|
+
throw "Failed to prepare docker-native wrap for $Tool"
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
Require-Command docker
|
|
1548
|
+
|
|
1549
|
+
if ($args.Count -eq 0) {
|
|
1550
|
+
Invoke-HeadroomDocker -Arguments @('--help')
|
|
1551
|
+
exit 0
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
switch ($args[0]) {
|
|
1555
|
+
'install' {
|
|
1556
|
+
if ($args.Count -eq 1 -or $args[1] -eq '--help' -or $args[1] -eq '-?') {
|
|
1557
|
+
Show-InstallHelp
|
|
1558
|
+
exit 0
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
$installCommand = $args[1]
|
|
1562
|
+
$installArgs = if ($args.Count -gt 2) { $args[2..($args.Count - 1)] } else { @() }
|
|
1563
|
+
|
|
1564
|
+
switch ($installCommand) {
|
|
1565
|
+
'apply' {
|
|
1566
|
+
$parsed = Parse-InstallApplyArgs -Arguments $installArgs
|
|
1567
|
+
Start-PersistentDockerInstall -Profile $parsed.Profile -Image $parsed.Image -Port $parsed.Port -Backend $parsed.Backend -AnyllmProvider $parsed.AnyllmProvider -Region $parsed.Region -Mode $parsed.Mode -Memory $parsed.Memory -TelemetryEnabled $parsed.TelemetryEnabled
|
|
1568
|
+
Write-Host "Installed docker-native persistent deployment '$($parsed.Profile)' on port $($parsed.Port)."
|
|
1569
|
+
exit 0
|
|
1570
|
+
}
|
|
1571
|
+
'status' {
|
|
1572
|
+
$profile = Parse-InstallProfileArgs -Arguments $installArgs
|
|
1573
|
+
Show-PersistentDockerInstallStatus -Profile $profile
|
|
1574
|
+
exit 0
|
|
1575
|
+
}
|
|
1576
|
+
'start' {
|
|
1577
|
+
$profile = Parse-InstallProfileArgs -Arguments $installArgs
|
|
1578
|
+
$state = Read-PersistentState -Profile $profile
|
|
1579
|
+
Start-PersistentDockerInstall -Profile $state.profile -Image $state.image -Port $state.port -Backend $state.backend -AnyllmProvider $state.anyllm_provider -Region $state.region -Mode $state.proxy_mode -Memory ([bool]$state.memory_enabled) -TelemetryEnabled ([bool]$state.telemetry_enabled)
|
|
1580
|
+
Write-Host "Started docker-native persistent deployment '$profile'."
|
|
1581
|
+
exit 0
|
|
1582
|
+
}
|
|
1583
|
+
'stop' {
|
|
1584
|
+
$profile = Parse-InstallProfileArgs -Arguments $installArgs
|
|
1585
|
+
Stop-PersistentDockerInstall -Profile $profile
|
|
1586
|
+
Write-Host "Stopped docker-native persistent deployment '$profile'."
|
|
1587
|
+
exit 0
|
|
1588
|
+
}
|
|
1589
|
+
'restart' {
|
|
1590
|
+
$profile = Parse-InstallProfileArgs -Arguments $installArgs
|
|
1591
|
+
$state = Read-PersistentState -Profile $profile
|
|
1592
|
+
Start-PersistentDockerInstall -Profile $state.profile -Image $state.image -Port $state.port -Backend $state.backend -AnyllmProvider $state.anyllm_provider -Region $state.region -Mode $state.proxy_mode -Memory ([bool]$state.memory_enabled) -TelemetryEnabled ([bool]$state.telemetry_enabled)
|
|
1593
|
+
Write-Host "Restarted docker-native persistent deployment '$profile'."
|
|
1594
|
+
exit 0
|
|
1595
|
+
}
|
|
1596
|
+
'remove' {
|
|
1597
|
+
$profile = Parse-InstallProfileArgs -Arguments $installArgs
|
|
1598
|
+
Remove-PersistentDockerInstall -Profile $profile
|
|
1599
|
+
Write-Host "Removed docker-native persistent deployment '$profile'."
|
|
1600
|
+
exit 0
|
|
1601
|
+
}
|
|
1602
|
+
default {
|
|
1603
|
+
Fail "Unsupported install target: $installCommand"
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
'wrap' {
|
|
1608
|
+
if ($args.Count -eq 1 -or $args[1] -eq '--help' -or $args[1] -eq '-?') {
|
|
1609
|
+
Show-WrapHelp
|
|
1610
|
+
exit 0
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
if ($args.Count -lt 2) {
|
|
1614
|
+
Fail 'Usage: xtream-head wrap <claude|codex|aider|cursor|openclaw> [...]'
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
$tool = $args[1]
|
|
1618
|
+
$wrapArgs = if ($args.Count -gt 2) { $args[2..($args.Count - 1)] } else { @() }
|
|
1619
|
+
|
|
1620
|
+
switch ($tool) {
|
|
1621
|
+
'claude' { }
|
|
1622
|
+
'codex' { }
|
|
1623
|
+
'aider' { }
|
|
1624
|
+
'cursor' { }
|
|
1625
|
+
'openclaw' { }
|
|
1626
|
+
default {
|
|
1627
|
+
Fail "Docker-native wrapper does not support 'wrap $tool'. Supported targets: claude, codex, aider, cursor, openclaw"
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
if ($tool -eq 'openclaw') {
|
|
1632
|
+
if (Test-HelpFlag -Arguments $wrapArgs) {
|
|
1633
|
+
$helpArgs = @('wrap','openclaw') + $wrapArgs
|
|
1634
|
+
Invoke-HeadroomDocker -Arguments $helpArgs
|
|
1635
|
+
exit 0
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
Invoke-OpenClawWrap -Arguments $wrapArgs
|
|
1639
|
+
exit 0
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
if (Test-HelpFlag -Arguments $wrapArgs) {
|
|
1643
|
+
$helpArgs = @('wrap', $tool) + $wrapArgs
|
|
1644
|
+
Invoke-HeadroomDocker -Arguments $helpArgs
|
|
1645
|
+
exit 0
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
$parsed = Parse-WrapArgs -Arguments $wrapArgs
|
|
1649
|
+
$contextTool = Get-ContextTool
|
|
1650
|
+
$proxyArgs = New-Object System.Collections.Generic.List[string]
|
|
1651
|
+
if ($parsed.Learn) { $proxyArgs.Add('--learn') }
|
|
1652
|
+
if ($parsed.Backend) { $proxyArgs.AddRange([string[]]@('--backend', $parsed.Backend)) }
|
|
1653
|
+
if ($parsed.Anyllm) { $proxyArgs.AddRange([string[]]@('--anyllm-provider', $parsed.Anyllm)) }
|
|
1654
|
+
if ($parsed.Region) { $proxyArgs.AddRange([string[]]@('--region', $parsed.Region)) }
|
|
1655
|
+
|
|
1656
|
+
$containerName = $null
|
|
1657
|
+
try {
|
|
1658
|
+
if (-not $parsed.NoProxy) {
|
|
1659
|
+
$containerName = Start-ProxyContainer -Port $parsed.Port -ProxyArgs $proxyArgs.ToArray()
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
$prepareArgs = New-Object System.Collections.Generic.List[string]
|
|
1663
|
+
foreach ($arg in $parsed.KnownArgs) {
|
|
1664
|
+
$prepareArgs.Add($arg)
|
|
1665
|
+
}
|
|
1666
|
+
if (-not $parsed.NoProxy) {
|
|
1667
|
+
$prepareArgs.Add('--no-proxy')
|
|
1668
|
+
}
|
|
1669
|
+
if ((-not $parsed.NoRtk) -and $contextTool -eq 'lean-ctx') {
|
|
1670
|
+
$prepareArgs.Add('--no-rtk')
|
|
1671
|
+
}
|
|
1672
|
+
Invoke-PrepareOnly -Tool $tool -KnownArgs $prepareArgs.ToArray()
|
|
1673
|
+
|
|
1674
|
+
if ((-not $parsed.NoRtk) -and $contextTool -eq 'lean-ctx') {
|
|
1675
|
+
Invoke-LeanCtxInit -Agent $tool
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
switch ($tool) {
|
|
1679
|
+
'claude' {
|
|
1680
|
+
if ((-not $parsed.NoRtk) -and $contextTool -eq 'rtk') {
|
|
1681
|
+
Invoke-ClaudeRtkInit
|
|
1682
|
+
}
|
|
1683
|
+
$exitCode = Invoke-WithTemporaryEnv -Environment @{ ANTHROPIC_BASE_URL = "http://127.0.0.1:$($parsed.Port)" } -Command 'claude' -Arguments $parsed.HostArgs
|
|
1684
|
+
exit $exitCode
|
|
1685
|
+
}
|
|
1686
|
+
'codex' {
|
|
1687
|
+
$exitCode = Invoke-WithTemporaryEnv -Environment @{ OPENAI_BASE_URL = "http://127.0.0.1:$($parsed.Port)/v1" } -Command 'codex' -Arguments $parsed.HostArgs
|
|
1688
|
+
exit $exitCode
|
|
1689
|
+
}
|
|
1690
|
+
'aider' {
|
|
1691
|
+
$exitCode = Invoke-WithTemporaryEnv -Environment @{
|
|
1692
|
+
OPENAI_API_BASE = "http://127.0.0.1:$($parsed.Port)/v1"
|
|
1693
|
+
ANTHROPIC_BASE_URL = "http://127.0.0.1:$($parsed.Port)"
|
|
1694
|
+
} -Command 'aider' -Arguments $parsed.HostArgs
|
|
1695
|
+
exit $exitCode
|
|
1696
|
+
}
|
|
1697
|
+
'cursor' {
|
|
1698
|
+
Write-Host "Xtream Head proxy is running for Cursor."
|
|
1699
|
+
Write-Host ""
|
|
1700
|
+
Write-Host "OpenAI base URL: http://127.0.0.1:$($parsed.Port)/v1"
|
|
1701
|
+
Write-Host "Anthropic base URL: http://127.0.0.1:$($parsed.Port)"
|
|
1702
|
+
Write-Host ""
|
|
1703
|
+
Write-Host "Press Ctrl+C to stop the proxy."
|
|
1704
|
+
while ($true) { Start-Sleep -Seconds 1 }
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
} finally {
|
|
1708
|
+
Stop-ProxyContainer -ContainerName $containerName
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
'unwrap' {
|
|
1712
|
+
if ($args.Count -eq 1 -or $args[1] -eq '--help' -or $args[1] -eq '-?') {
|
|
1713
|
+
Invoke-HeadroomDocker -Arguments @('unwrap','--help')
|
|
1714
|
+
exit 0
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
if ($args.Count -ge 2 -and $args[1] -eq 'openclaw') {
|
|
1718
|
+
$unwrapArgs = if ($args.Count -gt 2) { $args[2..($args.Count - 1)] } else { @() }
|
|
1719
|
+
if (Test-HelpFlag -Arguments $unwrapArgs) {
|
|
1720
|
+
$helpArgs = @('unwrap','openclaw') + $unwrapArgs
|
|
1721
|
+
Invoke-HeadroomDocker -Arguments $helpArgs
|
|
1722
|
+
exit 0
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
Invoke-OpenClawUnwrap -Arguments $unwrapArgs
|
|
1726
|
+
exit 0
|
|
1727
|
+
}
|
|
1728
|
+
Invoke-HeadroomDocker -Arguments $args
|
|
1729
|
+
}
|
|
1730
|
+
'proxy' {
|
|
1731
|
+
$port = 8787
|
|
1732
|
+
$forwardArgs = New-Object System.Collections.Generic.List[string]
|
|
1733
|
+
foreach ($arg in $args) { $forwardArgs.Add($arg) }
|
|
1734
|
+
for ($i = 1; $i -lt $args.Count; $i++) {
|
|
1735
|
+
if ($args[$i] -eq '--port' -or $args[$i] -eq '-p') {
|
|
1736
|
+
Require-OptionValue -Arguments $args -Index $i -Option $args[$i]
|
|
1737
|
+
$port = Parse-PortValue -Value $args[$i + 1]
|
|
1738
|
+
break
|
|
1739
|
+
}
|
|
1740
|
+
if ($args[$i] -match '^--port=') {
|
|
1741
|
+
$port = Parse-PortValue -Value ($args[$i] -replace '^--port=', '')
|
|
1742
|
+
break
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
$dockerArgs = New-Object System.Collections.Generic.List[string]
|
|
1747
|
+
$dockerArgs.AddRange([string[]]@('run','--rm'))
|
|
1748
|
+
Add-TtyArgs -ArgsList $dockerArgs
|
|
1749
|
+
$dockerArgs.AddRange([string[]]@('-p',"$port`:$port"))
|
|
1750
|
+
$dockerArgs.AddRange((Get-SharedDockerArgs))
|
|
1751
|
+
$dockerArgs.Add('--entrypoint')
|
|
1752
|
+
$dockerArgs.Add('headroom')
|
|
1753
|
+
$dockerArgs.Add($HeadroomImage)
|
|
1754
|
+
foreach ($arg in $forwardArgs) {
|
|
1755
|
+
$dockerArgs.Add($arg)
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
& docker @dockerArgs
|
|
1759
|
+
exit $LASTEXITCODE
|
|
1760
|
+
}
|
|
1761
|
+
default {
|
|
1762
|
+
Invoke-HeadroomDocker -Arguments $args
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
'@
|
|
1766
|
+
|
|
1767
|
+
$wrapper = $wrapper.Replace('__HEADROOM_INSTALL_IMAGE__', $resolvedInstallImage)
|
|
1768
|
+
|
|
1769
|
+
$cmdWrapper = ([string][char]64) + "echo off`r`npowershell -NoLogo -NoProfile -ExecutionPolicy Bypass -File ""%~dp0headroom.ps1"" %*`r`n"
|
|
1770
|
+
|
|
1771
|
+
Set-Content -Path $wrapperPath -Value $wrapper -Encoding utf8
|
|
1772
|
+
Set-Content -Path $cmdPath -Value $cmdWrapper -Encoding ascii
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
Require-Command docker
|
|
1776
|
+
docker version | Out-Null
|
|
1777
|
+
if ($LASTEXITCODE -ne 0) {
|
|
1778
|
+
throw 'Docker is installed but not available to the current user'
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
|
|
1782
|
+
Write-Wrapper -TargetDir $InstallDir
|
|
1783
|
+
Ensure-PathEntry -PathEntry $InstallDir
|
|
1784
|
+
Ensure-ProfileBlock -PathEntry $InstallDir
|
|
1785
|
+
|
|
1786
|
+
if ($env:HEADROOM_DOCKER_IMAGE) {
|
|
1787
|
+
$null = docker image inspect $InstallImage 2>$null
|
|
1788
|
+
if ($LASTEXITCODE -eq 0) {
|
|
1789
|
+
Write-Info "Using existing HEADROOM_DOCKER_IMAGE=$InstallImage"
|
|
1790
|
+
} else {
|
|
1791
|
+
Write-Info "Pulling $InstallImage"
|
|
1792
|
+
docker pull $InstallImage | Out-Null
|
|
1793
|
+
}
|
|
1794
|
+
} else {
|
|
1795
|
+
Write-Info "Pulling $ImageDefault"
|
|
1796
|
+
docker pull $ImageDefault | Out-Null
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
Write-Host ""
|
|
1800
|
+
Write-Host "Headroom Docker-native install complete."
|
|
1801
|
+
Write-Host ""
|
|
1802
|
+
Write-Host "Installed wrappers:"
|
|
1803
|
+
Write-Host " $InstallDir\headroom.ps1"
|
|
1804
|
+
Write-Host " $InstallDir\headroom.cmd"
|
|
1805
|
+
Write-Host ""
|
|
1806
|
+
Write-Host "Next steps:"
|
|
1807
|
+
Write-Host " 1. Restart PowerShell"
|
|
1808
|
+
Write-Host " 2. Try: xtream-head proxy"
|
|
1809
|
+
Write-Host " 3. Docs: https://github.com/Xtream-ITSolutions/xithead/blob/main/docs/docker-install.md"
|