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