xithead 1.5.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.
Files changed (649) hide show
  1. package/design-system/README.md +80 -0
  2. package/package.json +20 -1
  3. package/public/apple-touch-icon.png +0 -0
  4. package/public/logo-transparent.png +0 -0
  5. package/public/xithead.ps1 +937 -0
  6. package/scripts/README.md +77 -0
  7. package/scripts/audit_wheel_glibc_symbols.py +217 -0
  8. package/scripts/build-master-design-system.cjs +33 -0
  9. package/scripts/build_rust_extension.sh +58 -0
  10. package/scripts/changelog-gen.py +203 -0
  11. package/scripts/eval_output_shaper.py +235 -0
  12. package/scripts/export_kompress_v2_onnx.py +267 -0
  13. package/scripts/fixtures/anthropic_replay_body.json +133 -0
  14. package/scripts/fixtures/codex_response_create_frame.json +52 -0
  15. package/scripts/install-git-hooks.sh +104 -0
  16. package/scripts/install.ps1 +1809 -0
  17. package/scripts/install.sh +1673 -0
  18. package/scripts/pr-governance.py +297 -0
  19. package/scripts/record_fixtures.py +59 -0
  20. package/scripts/refresh_model_limits.sh +48 -0
  21. package/scripts/replay_codex_ws_load.py +445 -0
  22. package/scripts/repro_codex_replay.py +699 -0
  23. package/scripts/smoke_issue_327.py +233 -0
  24. package/scripts/sync-plugin-versions.py +116 -0
  25. package/scripts/tests/test_changelog_gen.py +302 -0
  26. package/scripts/tests/test_pr_governance.py +163 -0
  27. package/scripts/tests/test_pr_health_labels.py +94 -0
  28. package/scripts/tests/test_pr_health_workflow.py +14 -0
  29. package/scripts/tests/test_sync_plugin_versions.py +131 -0
  30. package/scripts/tests/test_version_sync.py +291 -0
  31. package/scripts/validate-workflows.sh +39 -0
  32. package/scripts/verify-versions.py +106 -0
  33. package/scripts/version-sync.py +207 -0
  34. package/tailwind.config.js +31 -0
  35. package/tsconfig.json +84 -0
  36. package/.actrc +0 -14
  37. package/.actrc.local.example +0 -15
  38. package/.changelog.md +0 -2
  39. package/.claude/agents/academic-anthropologist.md +0 -125
  40. package/.claude/agents/academic-geographer.md +0 -127
  41. package/.claude/agents/academic-historian.md +0 -123
  42. package/.claude/agents/academic-narratologist.md +0 -118
  43. package/.claude/agents/academic-psychologist.md +0 -118
  44. package/.claude/agents/academic-statistician.md +0 -144
  45. package/.claude/agents/accounts-payable-agent.md +0 -205
  46. package/.claude/agents/agentic-identity-trust.md +0 -394
  47. package/.claude/agents/agents-orchestrator.md +0 -367
  48. package/.claude/agents/automation-governance-architect.md +0 -216
  49. package/.claude/agents/blender-addon-engineer.md +0 -243
  50. package/.claude/agents/business-strategist.md +0 -488
  51. package/.claude/agents/change-management-consultant.md +0 -497
  52. package/.claude/agents/chief-financial-officer.md +0 -388
  53. package/.claude/agents/corporate-training-designer.md +0 -192
  54. package/.claude/agents/customer-service.md +0 -398
  55. package/.claude/agents/customer-success-manager.md +0 -460
  56. package/.claude/agents/data-consolidation-agent.md +0 -60
  57. package/.claude/agents/data-privacy-officer.md +0 -412
  58. package/.claude/agents/design-brand-guardian.md +0 -322
  59. package/.claude/agents/design-image-prompt-engineer.md +0 -236
  60. package/.claude/agents/design-inclusive-visuals-specialist.md +0 -73
  61. package/.claude/agents/design-persona-walkthrough.md +0 -272
  62. package/.claude/agents/design-ui-designer.md +0 -386
  63. package/.claude/agents/design-ui-finish-gate-reviewer.md +0 -217
  64. package/.claude/agents/design-ux-architect.md +0 -482
  65. package/.claude/agents/design-ux-researcher.md +0 -329
  66. package/.claude/agents/design-visual-storyteller.md +0 -149
  67. package/.claude/agents/design-whimsy-injector.md +0 -460
  68. package/.claude/agents/economy-designer.md +0 -156
  69. package/.claude/agents/engineering-ai-data-remediation-engineer.md +0 -211
  70. package/.claude/agents/engineering-ai-engineer.md +0 -146
  71. package/.claude/agents/engineering-api-platform-engineer.md +0 -181
  72. package/.claude/agents/engineering-ats-validator-architect.md +0 -383
  73. package/.claude/agents/engineering-autonomous-optimization-architect.md +0 -121
  74. package/.claude/agents/engineering-backend-architect.md +0 -255
  75. package/.claude/agents/engineering-china-network-engineer.md +0 -252
  76. package/.claude/agents/engineering-cms-developer.md +0 -536
  77. package/.claude/agents/engineering-code-reviewer.md +0 -76
  78. package/.claude/agents/engineering-codebase-onboarding-engineer.md +0 -173
  79. package/.claude/agents/engineering-data-engineer.md +0 -349
  80. package/.claude/agents/engineering-data-visualization-engineer.md +0 -151
  81. package/.claude/agents/engineering-database-optimizer.md +0 -188
  82. package/.claude/agents/engineering-database-reliability-engineer.md +0 -201
  83. package/.claude/agents/engineering-desktop-app-engineer.md +0 -209
  84. package/.claude/agents/engineering-developer-tooling-engineer.md +0 -153
  85. package/.claude/agents/engineering-devops-automator.md +0 -385
  86. package/.claude/agents/engineering-drupal-performance.md +0 -347
  87. package/.claude/agents/engineering-drupal-shopping-cart.md +0 -360
  88. package/.claude/agents/engineering-electrical-engineer.md +0 -575
  89. package/.claude/agents/engineering-email-intelligence-engineer.md +0 -390
  90. package/.claude/agents/engineering-embedded-firmware-engineer.md +0 -196
  91. package/.claude/agents/engineering-feishu-integration-developer.md +0 -606
  92. package/.claude/agents/engineering-filament-optimization-specialist.md +0 -283
  93. package/.claude/agents/engineering-finops-engineer.md +0 -164
  94. package/.claude/agents/engineering-frontend-developer.md +0 -257
  95. package/.claude/agents/engineering-gaussdb-expert.md +0 -334
  96. package/.claude/agents/engineering-git-workflow-master.md +0 -98
  97. package/.claude/agents/engineering-i18n-engineer.md +0 -214
  98. package/.claude/agents/engineering-identity-access-engineer.md +0 -217
  99. package/.claude/agents/engineering-incident-response-commander.md +0 -444
  100. package/.claude/agents/engineering-iot-fleet-engineer.md +0 -148
  101. package/.claude/agents/engineering-it-service-manager.md +0 -561
  102. package/.claude/agents/engineering-knowledge-graph-engineer.md +0 -372
  103. package/.claude/agents/engineering-llm-post-training-engineer.md +0 -166
  104. package/.claude/agents/engineering-minimal-change-engineer.md +0 -207
  105. package/.claude/agents/engineering-mobile-app-builder.md +0 -493
  106. package/.claude/agents/engineering-mobile-release-engineer.md +0 -164
  107. package/.claude/agents/engineering-multi-agent-systems-architect.md +0 -600
  108. package/.claude/agents/engineering-network-engineer.md +0 -245
  109. package/.claude/agents/engineering-orgscript-engineer.md +0 -113
  110. package/.claude/agents/engineering-payments-billing-engineer.md +0 -228
  111. package/.claude/agents/engineering-pdf-engine-architect.md +0 -696
  112. package/.claude/agents/engineering-platform-engineer.md +0 -270
  113. package/.claude/agents/engineering-privacy-engineer.md +0 -152
  114. package/.claude/agents/engineering-prompt-engineer.md +0 -209
  115. package/.claude/agents/engineering-rag-pipeline-engineer.md +0 -450
  116. package/.claude/agents/engineering-rapid-prototyper.md +0 -466
  117. package/.claude/agents/engineering-realtime-collaboration-engineer.md +0 -200
  118. package/.claude/agents/engineering-rust-refactoring-specialist.md +0 -313
  119. package/.claude/agents/engineering-search-relevance-engineer.md +0 -237
  120. package/.claude/agents/engineering-section-508-specialist.md +0 -339
  121. package/.claude/agents/engineering-senior-developer.md +0 -176
  122. package/.claude/agents/engineering-servicenow-developer-mentor.md +0 -180
  123. package/.claude/agents/engineering-software-architect.md +0 -112
  124. package/.claude/agents/engineering-solidity-smart-contract-engineer.md +0 -522
  125. package/.claude/agents/engineering-sre.md +0 -90
  126. package/.claude/agents/engineering-technical-writer.md +0 -393
  127. package/.claude/agents/engineering-universal-document-compiler.md +0 -370
  128. package/.claude/agents/engineering-uswds-developer.md +0 -340
  129. package/.claude/agents/engineering-video-streaming-engineer.md +0 -151
  130. package/.claude/agents/engineering-voice-ai-integration-engineer.md +0 -584
  131. package/.claude/agents/engineering-webassembly-engineer.md +0 -153
  132. package/.claude/agents/engineering-wechat-mini-program-developer.md +0 -356
  133. package/.claude/agents/engineering-wordpress-performance.md +0 -346
  134. package/.claude/agents/engineering-wordpress-shopping-cart.md +0 -346
  135. package/.claude/agents/esg-sustainability-officer.md +0 -396
  136. package/.claude/agents/finance-bookkeeper-controller.md +0 -260
  137. package/.claude/agents/finance-financial-analyst.md +0 -234
  138. package/.claude/agents/finance-fpa-analyst.md +0 -263
  139. package/.claude/agents/finance-investment-researcher.md +0 -272
  140. package/.claude/agents/finance-tax-strategist.md +0 -239
  141. package/.claude/agents/game-audio-engineer.md +0 -264
  142. package/.claude/agents/game-designer.md +0 -167
  143. package/.claude/agents/gis-3d-scene-developer.md +0 -111
  144. package/.claude/agents/gis-analyst.md +0 -91
  145. package/.claude/agents/gis-bim-specialist.md +0 -108
  146. package/.claude/agents/gis-cartography-designer.md +0 -150
  147. package/.claude/agents/gis-drone-reality-mapping.md +0 -120
  148. package/.claude/agents/gis-geoai-ml-engineer.md +0 -105
  149. package/.claude/agents/gis-geoprocessing-specialist.md +0 -97
  150. package/.claude/agents/gis-qa-engineer.md +0 -133
  151. package/.claude/agents/gis-solution-engineer.md +0 -101
  152. package/.claude/agents/gis-spatial-data-engineer.md +0 -97
  153. package/.claude/agents/gis-spatial-data-scientist.md +0 -111
  154. package/.claude/agents/gis-technical-consultant.md +0 -86
  155. package/.claude/agents/gis-web-gis-developer.md +0 -108
  156. package/.claude/agents/godot-gameplay-scripter.md +0 -338
  157. package/.claude/agents/godot-multiplayer-engineer.md +0 -301
  158. package/.claude/agents/godot-shader-developer.md +0 -267
  159. package/.claude/agents/government-digital-presales-consultant.md +0 -363
  160. package/.claude/agents/grant-writer.md +0 -511
  161. package/.claude/agents/healthcare-aging-parent-care-companion.md +0 -414
  162. package/.claude/agents/healthcare-clinical-evidence-agent.md +0 -231
  163. package/.claude/agents/healthcare-customer-service.md +0 -389
  164. package/.claude/agents/healthcare-innovation-strategist.md +0 -433
  165. package/.claude/agents/healthcare-marketing-compliance.md +0 -395
  166. package/.claude/agents/healthcare-sovereign-health-systems-agent.md +0 -312
  167. package/.claude/agents/hospitality-guest-services.md +0 -603
  168. package/.claude/agents/hr-onboarding.md +0 -451
  169. package/.claude/agents/identity-graph-operator.md +0 -303
  170. package/.claude/agents/language-translator.md +0 -264
  171. package/.claude/agents/legal-billing-time-tracking.md +0 -569
  172. package/.claude/agents/legal-client-intake.md +0 -492
  173. package/.claude/agents/legal-document-review.md +0 -454
  174. package/.claude/agents/level-designer.md +0 -208
  175. package/.claude/agents/loan-officer-assistant.md +0 -555
  176. package/.claude/agents/lsp-index-engineer.md +0 -320
  177. package/.claude/agents/ma-integration-manager.md +0 -427
  178. package/.claude/agents/macos-spatial-metal-engineer.md +0 -337
  179. package/.claude/agents/marketing-aeo-foundations.md +0 -264
  180. package/.claude/agents/marketing-agentic-search-optimizer.md +0 -279
  181. package/.claude/agents/marketing-ai-citation-strategist.md +0 -172
  182. package/.claude/agents/marketing-app-store-optimizer.md +0 -321
  183. package/.claude/agents/marketing-baidu-seo-specialist.md +0 -226
  184. package/.claude/agents/marketing-bilibili-content-strategist.md +0 -199
  185. package/.claude/agents/marketing-book-co-author.md +0 -110
  186. package/.claude/agents/marketing-carousel-growth-engine.md +0 -204
  187. package/.claude/agents/marketing-china-ecommerce-operator.md +0 -283
  188. package/.claude/agents/marketing-china-market-localization-strategist.md +0 -283
  189. package/.claude/agents/marketing-content-creator.md +0 -54
  190. package/.claude/agents/marketing-cross-border-ecommerce.md +0 -259
  191. package/.claude/agents/marketing-developer-community-builder.md +0 -285
  192. package/.claude/agents/marketing-douyin-strategist.md +0 -149
  193. package/.claude/agents/marketing-email-strategist.md +0 -249
  194. package/.claude/agents/marketing-global-podcast-strategist.md +0 -206
  195. package/.claude/agents/marketing-growth-hacker.md +0 -54
  196. package/.claude/agents/marketing-instagram-curator.md +0 -113
  197. package/.claude/agents/marketing-kuaishou-strategist.md +0 -223
  198. package/.claude/agents/marketing-linkedin-content-creator.md +0 -214
  199. package/.claude/agents/marketing-livestream-commerce-coach.md +0 -305
  200. package/.claude/agents/marketing-multi-platform-publisher.md +0 -217
  201. package/.claude/agents/marketing-podcast-strategist.md +0 -277
  202. package/.claude/agents/marketing-pr-communications-manager.md +0 -473
  203. package/.claude/agents/marketing-private-domain-operator.md +0 -308
  204. package/.claude/agents/marketing-reddit-community-builder.md +0 -123
  205. package/.claude/agents/marketing-seo-specialist.md +0 -370
  206. package/.claude/agents/marketing-short-video-editing-coach.md +0 -412
  207. package/.claude/agents/marketing-social-media-strategist.md +0 -125
  208. package/.claude/agents/marketing-tiktok-strategist.md +0 -125
  209. package/.claude/agents/marketing-twitter-engager.md +0 -126
  210. package/.claude/agents/marketing-video-optimization-specialist.md +0 -119
  211. package/.claude/agents/marketing-wechat-official-account.md +0 -145
  212. package/.claude/agents/marketing-weibo-strategist.md +0 -240
  213. package/.claude/agents/marketing-x-twitter-intelligence-analyst.md +0 -161
  214. package/.claude/agents/marketing-xiaohongshu-specialist.md +0 -138
  215. package/.claude/agents/marketing-zhihu-strategist.md +0 -162
  216. package/.claude/agents/medical-billing-coding-specialist.md +0 -491
  217. package/.claude/agents/narrative-designer.md +0 -243
  218. package/.claude/agents/operations-manager.md +0 -399
  219. package/.claude/agents/organizational-psychologist.md +0 -391
  220. package/.claude/agents/paid-media-auditor.md +0 -71
  221. package/.claude/agents/paid-media-creative-strategist.md +0 -71
  222. package/.claude/agents/paid-media-paid-social-strategist.md +0 -71
  223. package/.claude/agents/paid-media-ppc-strategist.md +0 -71
  224. package/.claude/agents/paid-media-programmatic-buyer.md +0 -71
  225. package/.claude/agents/paid-media-search-query-analyst.md +0 -71
  226. package/.claude/agents/paid-media-tracking-specialist.md +0 -71
  227. package/.claude/agents/personal-growth-mentor.md +0 -159
  228. package/.claude/agents/product-behavioral-nudge-engine.md +0 -83
  229. package/.claude/agents/product-dx-engineer.md +0 -332
  230. package/.claude/agents/product-feedback-synthesizer.md +0 -119
  231. package/.claude/agents/product-manager.md +0 -469
  232. package/.claude/agents/product-sprint-prioritizer.md +0 -154
  233. package/.claude/agents/product-trend-researcher.md +0 -159
  234. package/.claude/agents/project-management-experiment-tracker.md +0 -198
  235. package/.claude/agents/project-management-jira-workflow-steward.md +0 -233
  236. package/.claude/agents/project-management-meeting-notes-specialist.md +0 -95
  237. package/.claude/agents/project-management-project-shepherd.md +0 -194
  238. package/.claude/agents/project-management-studio-operations.md +0 -200
  239. package/.claude/agents/project-management-studio-producer.md +0 -203
  240. package/.claude/agents/project-manager-senior.md +0 -135
  241. package/.claude/agents/real-estate-buyer-seller.md +0 -596
  242. package/.claude/agents/recruitment-specialist.md +0 -515
  243. package/.claude/agents/report-distribution-agent.md +0 -65
  244. package/.claude/agents/research-synthesist.md +0 -136
  245. package/.claude/agents/resume-tailor.md +0 -230
  246. package/.claude/agents/retail-customer-returns.md +0 -566
  247. package/.claude/agents/roblox-avatar-creator.md +0 -297
  248. package/.claude/agents/roblox-experience-designer.md +0 -306
  249. package/.claude/agents/roblox-systems-scripter.md +0 -332
  250. package/.claude/agents/sales-account-strategist.md +0 -227
  251. package/.claude/agents/sales-coach.md +0 -271
  252. package/.claude/agents/sales-data-extraction-agent.md +0 -67
  253. package/.claude/agents/sales-deal-strategist.md +0 -180
  254. package/.claude/agents/sales-discovery-coach.md +0 -225
  255. package/.claude/agents/sales-engineer.md +0 -182
  256. package/.claude/agents/sales-offer-lead-gen-strategist.md +0 -257
  257. package/.claude/agents/sales-outbound-strategist.md +0 -201
  258. package/.claude/agents/sales-outreach.md +0 -425
  259. package/.claude/agents/sales-pipeline-analyst.md +0 -267
  260. package/.claude/agents/sales-proposal-strategist.md +0 -217
  261. package/.claude/agents/security-ai-generated-code-auditor.md +0 -207
  262. package/.claude/agents/security-appsec-engineer.md +0 -536
  263. package/.claude/agents/security-architect.md +0 -307
  264. package/.claude/agents/security-blockchain-security-auditor.md +0 -482
  265. package/.claude/agents/security-cloud-security-architect.md +0 -576
  266. package/.claude/agents/security-compliance-auditor.md +0 -158
  267. package/.claude/agents/security-incident-responder.md +0 -450
  268. package/.claude/agents/security-penetration-tester.md +0 -399
  269. package/.claude/agents/security-secrets-credential-engineer.md +0 -189
  270. package/.claude/agents/security-senior-secops.md +0 -760
  271. package/.claude/agents/security-threat-detection-engineer.md +0 -553
  272. package/.claude/agents/security-threat-intelligence-analyst.md +0 -661
  273. package/.claude/agents/specialized-chief-of-staff.md +0 -279
  274. package/.claude/agents/specialized-civil-engineer.md +0 -356
  275. package/.claude/agents/specialized-codebase-archaeologist.md +0 -341
  276. package/.claude/agents/specialized-cultural-intelligence-strategist.md +0 -88
  277. package/.claude/agents/specialized-developer-advocate.md +0 -317
  278. package/.claude/agents/specialized-document-generator.md +0 -55
  279. package/.claude/agents/specialized-fedramp-rmf-compliance.md +0 -378
  280. package/.claude/agents/specialized-focus-music-architect.md +0 -175
  281. package/.claude/agents/specialized-french-consulting-market.md +0 -194
  282. package/.claude/agents/specialized-korean-business-navigator.md +0 -216
  283. package/.claude/agents/specialized-master-plan-architect.md +0 -157
  284. package/.claude/agents/specialized-mcp-builder.md +0 -260
  285. package/.claude/agents/specialized-model-qa.md +0 -528
  286. package/.claude/agents/specialized-pricing-analyst.md +0 -243
  287. package/.claude/agents/specialized-salesforce-architect.md +0 -182
  288. package/.claude/agents/specialized-strategy-duel-agent.md +0 -130
  289. package/.claude/agents/specialized-workflow-architect.md +0 -597
  290. package/.claude/agents/study-abroad-advisor.md +0 -282
  291. package/.claude/agents/supply-chain-strategist.md +0 -591
  292. package/.claude/agents/support-analytics-reporter.md +0 -387
  293. package/.claude/agents/support-executive-summary-generator.md +0 -212
  294. package/.claude/agents/support-finance-tracker.md +0 -480
  295. package/.claude/agents/support-infrastructure-maintainer.md +0 -628
  296. package/.claude/agents/support-legal-compliance-checker.md +0 -591
  297. package/.claude/agents/support-support-responder.md +0 -607
  298. package/.claude/agents/technical-artist.md +0 -233
  299. package/.claude/agents/terminal-integration-specialist.md +0 -70
  300. package/.claude/agents/testing-accessibility-auditor.md +0 -327
  301. package/.claude/agents/testing-api-tester.md +0 -334
  302. package/.claude/agents/testing-evidence-collector.md +0 -210
  303. package/.claude/agents/testing-performance-benchmarker.md +0 -283
  304. package/.claude/agents/testing-reality-checker.md +0 -249
  305. package/.claude/agents/testing-test-automation-engineer.md +0 -196
  306. package/.claude/agents/testing-test-results-analyzer.md +0 -330
  307. package/.claude/agents/testing-tool-evaluator.md +0 -416
  308. package/.claude/agents/testing-workflow-optimizer.md +0 -463
  309. package/.claude/agents/unity-architect.md +0 -271
  310. package/.claude/agents/unity-editor-tool-developer.md +0 -310
  311. package/.claude/agents/unity-multiplayer-engineer.md +0 -323
  312. package/.claude/agents/unity-shader-graph-artist.md +0 -269
  313. package/.claude/agents/unreal-multiplayer-architect.md +0 -364
  314. package/.claude/agents/unreal-systems-engineer.md +0 -322
  315. package/.claude/agents/unreal-technical-artist.md +0 -256
  316. package/.claude/agents/unreal-world-builder.md +0 -273
  317. package/.claude/agents/visionos-spatial-engineer.md +0 -54
  318. package/.claude/agents/xr-cockpit-interaction-specialist.md +0 -32
  319. package/.claude/agents/xr-immersive-developer.md +0 -32
  320. package/.claude/agents/xr-interface-architect.md +0 -32
  321. package/.claude/agents/zk-steward.md +0 -211
  322. package/.claude-plugin/marketplace.json +0 -30
  323. package/.commitlintrc.json +0 -26
  324. package/.devcontainer/Dockerfile +0 -24
  325. package/.devcontainer/devcontainer.json +0 -70
  326. package/.devcontainer/docker-compose.memory.yml +0 -42
  327. package/.devcontainer/memory-stack/devcontainer.json +0 -84
  328. package/.devcontainer/post-create.sh +0 -83
  329. package/.dockerignore +0 -23
  330. package/.env.act.example +0 -15
  331. package/.env.example +0 -171
  332. package/.eslintrc.json +0 -16
  333. package/.git-blame-ignore-revs +0 -10
  334. package/.gitattributes +0 -2
  335. package/.gitguardian.yaml +0 -50
  336. package/.githooks/pre-commit +0 -6
  337. package/.pre-commit-config.yaml +0 -30
  338. package/.release-please-config-xithead.json +0 -22
  339. package/.release-please-config.json +0 -44
  340. package/.release-please-manifest-xithead.json +0 -3
  341. package/.release-please-manifest.json +0 -3
  342. package/CODE_OF_CONDUCT.md +0 -133
  343. package/CONTRIBUTING.md +0 -133
  344. package/Cargo.lock +0 -5557
  345. package/Cargo.toml +0 -121
  346. package/Dockerfile +0 -38
  347. package/Dockerfile.proxy +0 -48
  348. package/ENTERPRISE.md +0 -5
  349. package/FEATURES_ADVANCED.md +0 -311
  350. package/Headroom-2.gif +0 -0
  351. package/HeadroomDemo-Fast.gif +0 -0
  352. package/MANIFEST.in +0 -4
  353. package/MODERNIZATION_GUIDE.md +0 -358
  354. package/Makefile +0 -140
  355. package/NOTICE +0 -43
  356. package/NPM_TOKEN_SETUP.md +0 -81
  357. package/PR.md +0 -170
  358. package/PUBLISH.md +0 -77
  359. package/README_FRONTEND.md +0 -196
  360. package/REALIGNMENT/00-overview.md +0 -53
  361. package/REALIGNMENT/01-bug-list.md +0 -421
  362. package/REALIGNMENT/02-architecture.md +0 -322
  363. package/REALIGNMENT/03-phase-A-lockdown.md +0 -420
  364. package/REALIGNMENT/04-phase-B-live-zone.md +0 -470
  365. package/REALIGNMENT/05-phase-C-rust-proxy.md +0 -329
  366. package/REALIGNMENT/06-phase-D-bedrock-vertex.md +0 -222
  367. package/REALIGNMENT/07-phase-E-cache-stabilization.md +0 -338
  368. package/REALIGNMENT/08-phase-F-auth-mode.md +0 -254
  369. package/REALIGNMENT/09-phase-G-rtk-observability.md +0 -194
  370. package/REALIGNMENT/10-phase-H-python-retirement.md +0 -214
  371. package/REALIGNMENT/11-phase-I-test-infra.md +0 -385
  372. package/REALIGNMENT/12-decisions-needed.md +0 -196
  373. package/REALIGNMENT/INDEX.md +0 -82
  374. package/REFACTORING_CAMPAIGN.md +0 -277
  375. package/RESTRUCTURE_PLAN.md +0 -100
  376. package/RUST_DEV.md +0 -361
  377. package/SECURITY.md +0 -65
  378. package/SETUP_AUTO_PUBLISH.md +0 -164
  379. package/TESTING-copilot-subscription.md +0 -153
  380. package/codecov.yml +0 -34
  381. package/crates/headroom-core/Cargo.toml +0 -165
  382. package/crates/headroom-core/benches/auth_mode.rs +0 -74
  383. package/crates/headroom-core/benches/ccr_store.rs +0 -224
  384. package/crates/headroom-core/benches/tokenizer.rs +0 -52
  385. package/crates/headroom-core/config/pipeline.toml +0 -151
  386. package/crates/headroom-core/proptest-regressions/transforms/tag_protector.txt +0 -9
  387. package/crates/headroom-core/src/auth_mode.rs +0 -250
  388. package/crates/headroom-core/src/cache_control.rs +0 -414
  389. package/crates/headroom-core/src/ccr/backends/in_memory.rs +0 -317
  390. package/crates/headroom-core/src/ccr/backends/mod.rs +0 -152
  391. package/crates/headroom-core/src/ccr/backends/redis.rs +0 -146
  392. package/crates/headroom-core/src/ccr/backends/sqlite.rs +0 -205
  393. package/crates/headroom-core/src/ccr/mod.rs +0 -119
  394. package/crates/headroom-core/src/compression_policy.rs +0 -505
  395. package/crates/headroom-core/src/lib.rs +0 -33
  396. package/crates/headroom-core/src/relevance/base.rs +0 -139
  397. package/crates/headroom-core/src/relevance/bm25.rs +0 -385
  398. package/crates/headroom-core/src/relevance/embedding.rs +0 -354
  399. package/crates/headroom-core/src/relevance/hybrid.rs +0 -364
  400. package/crates/headroom-core/src/relevance/mod.rs +0 -64
  401. package/crates/headroom-core/src/signals/keyword_detector.rs +0 -433
  402. package/crates/headroom-core/src/signals/line_importance.rs +0 -84
  403. package/crates/headroom-core/src/signals/mod.rs +0 -61
  404. package/crates/headroom-core/src/signals/tiered.rs +0 -141
  405. package/crates/headroom-core/src/tokenizer/estimator.rs +0 -152
  406. package/crates/headroom-core/src/tokenizer/hf_impl.rs +0 -314
  407. package/crates/headroom-core/src/tokenizer/mod.rs +0 -56
  408. package/crates/headroom-core/src/tokenizer/registry.rs +0 -342
  409. package/crates/headroom-core/src/tokenizer/tiktoken_impl.rs +0 -265
  410. package/crates/headroom-core/src/transforms/adaptive_sizer.rs +0 -610
  411. package/crates/headroom-core/src/transforms/anchor_selector.rs +0 -1189
  412. package/crates/headroom-core/src/transforms/content_detector.rs +0 -769
  413. package/crates/headroom-core/src/transforms/detection.rs +0 -222
  414. package/crates/headroom-core/src/transforms/diff_compressor.rs +0 -1685
  415. package/crates/headroom-core/src/transforms/live_zone.rs +0 -2967
  416. package/crates/headroom-core/src/transforms/log_compressor.rs +0 -1295
  417. package/crates/headroom-core/src/transforms/magika_detector.rs +0 -395
  418. package/crates/headroom-core/src/transforms/mod.rs +0 -64
  419. package/crates/headroom-core/src/transforms/pipeline/config.rs +0 -331
  420. package/crates/headroom-core/src/transforms/pipeline/mod.rs +0 -103
  421. package/crates/headroom-core/src/transforms/pipeline/offloads/diff_noise.rs +0 -524
  422. package/crates/headroom-core/src/transforms/pipeline/offloads/diff_offload.rs +0 -279
  423. package/crates/headroom-core/src/transforms/pipeline/offloads/json_offload.rs +0 -400
  424. package/crates/headroom-core/src/transforms/pipeline/offloads/log_offload.rs +0 -284
  425. package/crates/headroom-core/src/transforms/pipeline/offloads/mod.rs +0 -34
  426. package/crates/headroom-core/src/transforms/pipeline/offloads/search_offload.rs +0 -331
  427. package/crates/headroom-core/src/transforms/pipeline/orchestrator.rs +0 -848
  428. package/crates/headroom-core/src/transforms/pipeline/reformats/json_minifier.rs +0 -175
  429. package/crates/headroom-core/src/transforms/pipeline/reformats/log_template.rs +0 -545
  430. package/crates/headroom-core/src/transforms/pipeline/reformats/mod.rs +0 -12
  431. package/crates/headroom-core/src/transforms/pipeline/traits.rs +0 -338
  432. package/crates/headroom-core/src/transforms/recommendations.rs +0 -329
  433. package/crates/headroom-core/src/transforms/safety.rs +0 -215
  434. package/crates/headroom-core/src/transforms/search_compressor.rs +0 -902
  435. package/crates/headroom-core/src/transforms/smart_crusher/analyzer.rs +0 -1262
  436. package/crates/headroom-core/src/transforms/smart_crusher/anchors.rs +0 -407
  437. package/crates/headroom-core/src/transforms/smart_crusher/builder.rs +0 -263
  438. package/crates/headroom-core/src/transforms/smart_crusher/classifier.rs +0 -214
  439. package/crates/headroom-core/src/transforms/smart_crusher/compaction/classifier.rs +0 -283
  440. package/crates/headroom-core/src/transforms/smart_crusher/compaction/compactor.rs +0 -733
  441. package/crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs +0 -961
  442. package/crates/headroom-core/src/transforms/smart_crusher/compaction/ir.rs +0 -252
  443. package/crates/headroom-core/src/transforms/smart_crusher/compaction/mod.rs +0 -127
  444. package/crates/headroom-core/src/transforms/smart_crusher/compaction/walker.rs +0 -397
  445. package/crates/headroom-core/src/transforms/smart_crusher/config.rs +0 -173
  446. package/crates/headroom-core/src/transforms/smart_crusher/constraints.rs +0 -159
  447. package/crates/headroom-core/src/transforms/smart_crusher/crusher.rs +0 -1665
  448. package/crates/headroom-core/src/transforms/smart_crusher/crushers.rs +0 -865
  449. package/crates/headroom-core/src/transforms/smart_crusher/error_keywords.rs +0 -77
  450. package/crates/headroom-core/src/transforms/smart_crusher/field_detect.rs +0 -393
  451. package/crates/headroom-core/src/transforms/smart_crusher/hashing.rs +0 -72
  452. package/crates/headroom-core/src/transforms/smart_crusher/mod.rs +0 -81
  453. package/crates/headroom-core/src/transforms/smart_crusher/observer.rs +0 -66
  454. package/crates/headroom-core/src/transforms/smart_crusher/orchestration.rs +0 -459
  455. package/crates/headroom-core/src/transforms/smart_crusher/outliers.rs +0 -507
  456. package/crates/headroom-core/src/transforms/smart_crusher/planning.rs +0 -904
  457. package/crates/headroom-core/src/transforms/smart_crusher/statistics.rs +0 -510
  458. package/crates/headroom-core/src/transforms/smart_crusher/stats_math.rs +0 -287
  459. package/crates/headroom-core/src/transforms/smart_crusher/traits.rs +0 -203
  460. package/crates/headroom-core/src/transforms/smart_crusher/types.rs +0 -263
  461. package/crates/headroom-core/src/transforms/tag_protector.rs +0 -1272
  462. package/crates/headroom-core/src/transforms/unidiff_detector.rs +0 -232
  463. package/crates/headroom-parity/Cargo.toml +0 -26
  464. package/crates/headroom-parity/examples/diff_fixture.rs +0 -66
  465. package/crates/headroom-parity/src/bin/parity_run.rs +0 -78
  466. package/crates/headroom-parity/src/lib.rs +0 -613
  467. package/crates/headroom-proxy/Cargo.toml +0 -119
  468. package/crates/headroom-proxy/data/model_prices_and_context_window.json +0 -39767
  469. package/crates/headroom-proxy/src/bedrock/auth_mode_layer.rs +0 -192
  470. package/crates/headroom-proxy/src/bedrock/envelope.rs +0 -239
  471. package/crates/headroom-proxy/src/bedrock/eventstream.rs +0 -769
  472. package/crates/headroom-proxy/src/bedrock/eventstream_to_sse.rs +0 -459
  473. package/crates/headroom-proxy/src/bedrock/invoke.rs +0 -735
  474. package/crates/headroom-proxy/src/bedrock/invoke_streaming.rs +0 -1098
  475. package/crates/headroom-proxy/src/bedrock/mod.rs +0 -66
  476. package/crates/headroom-proxy/src/bedrock/sigv4.rs +0 -324
  477. package/crates/headroom-proxy/src/bedrock/vendor.rs +0 -82
  478. package/crates/headroom-proxy/src/cache_stabilization/anthropic_cache_control.rs +0 -698
  479. package/crates/headroom-proxy/src/cache_stabilization/drift_detector.rs +0 -683
  480. package/crates/headroom-proxy/src/cache_stabilization/mod.rs +0 -61
  481. package/crates/headroom-proxy/src/cache_stabilization/openai_cache_key.rs +0 -600
  482. package/crates/headroom-proxy/src/cache_stabilization/tool_def_normalize.rs +0 -514
  483. package/crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs +0 -720
  484. package/crates/headroom-proxy/src/compression/anthropic.rs +0 -92
  485. package/crates/headroom-proxy/src/compression/live_zone_anthropic.rs +0 -1311
  486. package/crates/headroom-proxy/src/compression/live_zone_openai.rs +0 -660
  487. package/crates/headroom-proxy/src/compression/live_zone_responses.rs +0 -678
  488. package/crates/headroom-proxy/src/compression/mod.rs +0 -127
  489. package/crates/headroom-proxy/src/compression/model_limits.rs +0 -211
  490. package/crates/headroom-proxy/src/config.rs +0 -646
  491. package/crates/headroom-proxy/src/error.rs +0 -69
  492. package/crates/headroom-proxy/src/handlers/chat_completions.rs +0 -100
  493. package/crates/headroom-proxy/src/handlers/conversations.rs +0 -241
  494. package/crates/headroom-proxy/src/handlers/mod.rs +0 -13
  495. package/crates/headroom-proxy/src/handlers/responses.rs +0 -256
  496. package/crates/headroom-proxy/src/headers.rs +0 -288
  497. package/crates/headroom-proxy/src/health.rs +0 -41
  498. package/crates/headroom-proxy/src/lib.rs +0 -21
  499. package/crates/headroom-proxy/src/main.rs +0 -141
  500. package/crates/headroom-proxy/src/observability/cache_hit_rate.rs +0 -340
  501. package/crates/headroom-proxy/src/observability/compression_ratio.rs +0 -158
  502. package/crates/headroom-proxy/src/observability/metric_names.rs +0 -174
  503. package/crates/headroom-proxy/src/observability/mod.rs +0 -68
  504. package/crates/headroom-proxy/src/observability/prometheus.rs +0 -394
  505. package/crates/headroom-proxy/src/observability/proxy_metrics.rs +0 -368
  506. package/crates/headroom-proxy/src/proxy.rs +0 -1619
  507. package/crates/headroom-proxy/src/responses_items.rs +0 -565
  508. package/crates/headroom-proxy/src/sse/anthropic.rs +0 -415
  509. package/crates/headroom-proxy/src/sse/framing.rs +0 -366
  510. package/crates/headroom-proxy/src/sse/mod.rs +0 -40
  511. package/crates/headroom-proxy/src/sse/openai_chat.rs +0 -231
  512. package/crates/headroom-proxy/src/sse/openai_responses.rs +0 -458
  513. package/crates/headroom-proxy/src/vertex/adc.rs +0 -315
  514. package/crates/headroom-proxy/src/vertex/envelope.rs +0 -167
  515. package/crates/headroom-proxy/src/vertex/mod.rs +0 -277
  516. package/crates/headroom-proxy/src/vertex/raw_predict.rs +0 -490
  517. package/crates/headroom-proxy/src/vertex/stream_raw_predict.rs +0 -49
  518. package/crates/headroom-proxy/src/websocket.rs +0 -246
  519. package/crates/headroom-py/Cargo.toml +0 -37
  520. package/crates/headroom-py/build.rs +0 -77
  521. package/crates/headroom-py/glibc_compat.c +0 -170
  522. package/crates/headroom-py/src/lib.rs +0 -1655
  523. package/deny.toml +0 -32
  524. package/docker/differential-network-capture/Dockerfile.runner +0 -14
  525. package/docker/differential-network-capture/docker-compose.yml +0 -142
  526. package/docker/differential-network-capture/run-claude-lane.sh +0 -24
  527. package/docker/docker-compose.native.yml +0 -44
  528. package/docker-bake.hcl +0 -88
  529. package/docker-compose.yml +0 -80
  530. package/e2e/_lib/make_shim.ps1 +0 -24
  531. package/e2e/_lib/make_shim.sh +0 -28
  532. package/e2e/docker-native-install.sh +0 -120
  533. package/e2e/init/Dockerfile +0 -79
  534. package/e2e/wrap/Dockerfile +0 -115
  535. package/examples/07-context-compression.ipynb +0 -279
  536. package/examples/deployment/macos-launchagent/com.headroom.proxy.plist.template +0 -65
  537. package/examples/deployment/macos-launchagent/install.sh +0 -227
  538. package/examples/deployment/macos-launchagent/shell-integration.sh +0 -74
  539. package/examples/deployment/macos-launchagent/uninstall.sh +0 -145
  540. package/headroom-savings.png +0 -0
  541. package/headroom_learn.gif +0 -0
  542. package/llms.txt +0 -67
  543. package/mkdocs.yml +0 -136
  544. package/npm/bin/xithead.js +0 -366
  545. package/npm/bin/xtream-head.js +0 -366
  546. package/npm/index.d.ts +0 -57
  547. package/npm/index.js +0 -139
  548. package/npm/package.json +0 -55
  549. package/npm/postinstall.js +0 -43
  550. package/plugins/headroom-agent-hooks/.claude-plugin/plugin.json +0 -17
  551. package/plugins/headroom-agent-hooks/hooks/hooks.json +0 -29
  552. package/plugins/headroom-oauth2/LICENSE +0 -3
  553. package/plugins/headroom-oauth2/SPEC.md +0 -115
  554. package/plugins/headroom-oauth2/pyproject.toml +0 -48
  555. package/plugins/hermes/headroom_retrieve/plugin.yaml +0 -6
  556. package/plugins/openclaw/hook-shim/HOOK.md +0 -21
  557. package/plugins/openclaw/hook-shim/handler.js +0 -3
  558. package/plugins/openclaw/openclaw.plugin.json +0 -98
  559. package/plugins/openclaw/package-lock.json +0 -2692
  560. package/plugins/openclaw/package.json +0 -54
  561. package/plugins/openclaw/prepare-dist.mjs +0 -56
  562. package/plugins/openclaw/src/convert.ts +0 -418
  563. package/plugins/openclaw/src/engine.ts +0 -284
  564. package/plugins/openclaw/src/gateway-config.ts +0 -143
  565. package/plugins/openclaw/src/index.ts +0 -11
  566. package/plugins/openclaw/src/plugin/index.ts +0 -98
  567. package/plugins/openclaw/src/proxy-manager.ts +0 -477
  568. package/plugins/openclaw/src/tools/headroom-retrieve.ts +0 -76
  569. package/plugins/openclaw/test/convert.test.ts +0 -96
  570. package/plugins/openclaw/test/engine-normalization.test.ts +0 -21
  571. package/plugins/openclaw/test/engine.test.ts +0 -101
  572. package/plugins/openclaw/test/gateway-config.test.ts +0 -278
  573. package/plugins/openclaw/test/plugin-runtime-routing.test.ts +0 -141
  574. package/plugins/openclaw/test/proxy-manager.test.ts +0 -343
  575. package/plugins/openclaw/tsup.config.ts +0 -9
  576. package/pyproject.toml +0 -438
  577. package/rust-toolchain.toml +0 -16
  578. package/sdk/typescript/examples/basic-compress.ts +0 -64
  579. package/sdk/typescript/examples/ccr-retrieve.ts +0 -80
  580. package/sdk/typescript/examples/hooks-custom-compression.ts +0 -117
  581. package/sdk/typescript/examples/middleware-composition.ts +0 -59
  582. package/sdk/typescript/examples/multi-provider.ts +0 -53
  583. package/sdk/typescript/examples/openai-anthropic-adapters.ts +0 -73
  584. package/sdk/typescript/examples/shared-context-multi-agent.ts +0 -74
  585. package/sdk/typescript/examples/simulation-dry-run.ts +0 -80
  586. package/sdk/typescript/examples/streaming-chat.ts +0 -71
  587. package/sdk/typescript/examples/structured-output.ts +0 -99
  588. package/sdk/typescript/examples/tool-calling-agent.ts +0 -86
  589. package/sdk/typescript/examples/with-headroom-vercel.ts +0 -57
  590. package/sdk/typescript/package-lock.json +0 -3437
  591. package/sdk/typescript/package.json +0 -108
  592. package/sdk/typescript/src/adapters/anthropic.ts +0 -218
  593. package/sdk/typescript/src/adapters/gemini.ts +0 -83
  594. package/sdk/typescript/src/adapters/openai.ts +0 -77
  595. package/sdk/typescript/src/adapters/vercel-ai.ts +0 -131
  596. package/sdk/typescript/src/client.ts +0 -632
  597. package/sdk/typescript/src/compress.ts +0 -87
  598. package/sdk/typescript/src/errors.ts +0 -114
  599. package/sdk/typescript/src/hooks.ts +0 -113
  600. package/sdk/typescript/src/index.ts +0 -140
  601. package/sdk/typescript/src/paths.ts +0 -272
  602. package/sdk/typescript/src/shared-context.ts +0 -188
  603. package/sdk/typescript/src/simulate.ts +0 -52
  604. package/sdk/typescript/src/types/config.ts +0 -183
  605. package/sdk/typescript/src/types/models.ts +0 -314
  606. package/sdk/typescript/src/types.ts +0 -139
  607. package/sdk/typescript/src/utils/case.ts +0 -34
  608. package/sdk/typescript/src/utils/format.ts +0 -480
  609. package/sdk/typescript/src/utils/stream.ts +0 -50
  610. package/sdk/typescript/test/adapters/anthropic.test.ts +0 -217
  611. package/sdk/typescript/test/adapters/gemini.test.ts +0 -131
  612. package/sdk/typescript/test/adapters/openai.test.ts +0 -174
  613. package/sdk/typescript/test/adapters/vercel-ai.test.ts +0 -306
  614. package/sdk/typescript/test/client-expanded.test.ts +0 -333
  615. package/sdk/typescript/test/client.test.ts +0 -266
  616. package/sdk/typescript/test/compress.test.ts +0 -118
  617. package/sdk/typescript/test/config.test.ts +0 -275
  618. package/sdk/typescript/test/errors.test.ts +0 -169
  619. package/sdk/typescript/test/format-integration.test.ts +0 -252
  620. package/sdk/typescript/test/hooks.test.ts +0 -265
  621. package/sdk/typescript/test/integration.test.ts +0 -249
  622. package/sdk/typescript/test/mdx-examples.test.ts +0 -253
  623. package/sdk/typescript/test/models.test.ts +0 -318
  624. package/sdk/typescript/test/parity.test.ts +0 -337
  625. package/sdk/typescript/test/paths.test.ts +0 -447
  626. package/sdk/typescript/test/shared-context.test.ts +0 -245
  627. package/sdk/typescript/test/simulate.test.ts +0 -84
  628. package/sdk/typescript/test/types.test.ts +0 -244
  629. package/sdk/typescript/test/utils/case.test.ts +0 -129
  630. package/sdk/typescript/test/utils/detect-format.test.ts +0 -133
  631. package/sdk/typescript/test/utils/format.test.ts +0 -434
  632. package/sdk/typescript/test/vercel-ai-e2e.test.ts +0 -179
  633. package/sdk/typescript/tsup.config.ts +0 -17
  634. package/uv.lock +0 -6951
  635. package/xithead.egg-info/PKG-INFO +0 -22
  636. package/xithead.egg-info/SOURCES.txt +0 -16
  637. package/xithead.egg-info/dependency_links.txt +0 -1
  638. package/xithead.egg-info/entry_points.txt +0 -2
  639. package/xithead.egg-info/requires.txt +0 -10
  640. package/xithead.egg-info/top_level.txt +0 -2
  641. package/xithead.ps1 +0 -136
  642. package/xithead.sh +0 -129
  643. package/xithead_dist/pyproject.toml +0 -39
  644. package/xithead_dist/xithead.egg-info/PKG-INFO +0 -22
  645. package/xithead_dist/xithead.egg-info/SOURCES.txt +0 -16
  646. package/xithead_dist/xithead.egg-info/dependency_links.txt +0 -1
  647. package/xithead_dist/xithead.egg-info/entry_points.txt +0 -3
  648. package/xithead_dist/xithead.egg-info/requires.txt +0 -10
  649. package/xithead_dist/xithead.egg-info/top_level.txt +0 -2
@@ -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"