hud-python 0.4.1__py3-none-any.whl → 0.4.3__py3-none-any.whl

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.

Potentially problematic release.


This version of hud-python might be problematic. Click here for more details.

Files changed (130) hide show
  1. hud/__init__.py +22 -22
  2. hud/agents/__init__.py +13 -15
  3. hud/agents/base.py +599 -599
  4. hud/agents/claude.py +373 -373
  5. hud/agents/langchain.py +261 -250
  6. hud/agents/misc/__init__.py +7 -7
  7. hud/agents/misc/response_agent.py +82 -80
  8. hud/agents/openai.py +352 -352
  9. hud/agents/openai_chat_generic.py +154 -154
  10. hud/agents/tests/__init__.py +1 -1
  11. hud/agents/tests/test_base.py +742 -742
  12. hud/agents/tests/test_claude.py +324 -324
  13. hud/agents/tests/test_client.py +363 -363
  14. hud/agents/tests/test_openai.py +237 -237
  15. hud/cli/__init__.py +617 -617
  16. hud/cli/__main__.py +8 -8
  17. hud/cli/analyze.py +371 -371
  18. hud/cli/analyze_metadata.py +230 -230
  19. hud/cli/build.py +498 -427
  20. hud/cli/clone.py +185 -185
  21. hud/cli/cursor.py +92 -92
  22. hud/cli/debug.py +392 -392
  23. hud/cli/docker_utils.py +83 -83
  24. hud/cli/init.py +280 -281
  25. hud/cli/interactive.py +353 -353
  26. hud/cli/mcp_server.py +764 -756
  27. hud/cli/pull.py +330 -336
  28. hud/cli/push.py +404 -370
  29. hud/cli/remote_runner.py +311 -311
  30. hud/cli/runner.py +160 -160
  31. hud/cli/tests/__init__.py +3 -3
  32. hud/cli/tests/test_analyze.py +284 -284
  33. hud/cli/tests/test_cli_init.py +265 -265
  34. hud/cli/tests/test_cli_main.py +27 -27
  35. hud/cli/tests/test_clone.py +142 -142
  36. hud/cli/tests/test_cursor.py +253 -253
  37. hud/cli/tests/test_debug.py +453 -453
  38. hud/cli/tests/test_mcp_server.py +139 -139
  39. hud/cli/tests/test_utils.py +388 -388
  40. hud/cli/utils.py +263 -263
  41. hud/clients/README.md +143 -143
  42. hud/clients/__init__.py +16 -16
  43. hud/clients/base.py +378 -379
  44. hud/clients/fastmcp.py +222 -222
  45. hud/clients/mcp_use.py +298 -278
  46. hud/clients/tests/__init__.py +1 -1
  47. hud/clients/tests/test_client_integration.py +111 -111
  48. hud/clients/tests/test_fastmcp.py +342 -342
  49. hud/clients/tests/test_protocol.py +188 -188
  50. hud/clients/utils/__init__.py +1 -1
  51. hud/clients/utils/retry_transport.py +160 -160
  52. hud/datasets.py +327 -322
  53. hud/misc/__init__.py +1 -1
  54. hud/misc/claude_plays_pokemon.py +292 -292
  55. hud/otel/__init__.py +35 -35
  56. hud/otel/collector.py +142 -142
  57. hud/otel/config.py +164 -164
  58. hud/otel/context.py +536 -536
  59. hud/otel/exporters.py +366 -366
  60. hud/otel/instrumentation.py +97 -97
  61. hud/otel/processors.py +118 -118
  62. hud/otel/tests/__init__.py +1 -1
  63. hud/otel/tests/test_processors.py +197 -197
  64. hud/server/__init__.py +5 -5
  65. hud/server/context.py +114 -114
  66. hud/server/helper/__init__.py +5 -5
  67. hud/server/low_level.py +132 -132
  68. hud/server/server.py +170 -166
  69. hud/server/tests/__init__.py +3 -3
  70. hud/settings.py +73 -73
  71. hud/shared/__init__.py +5 -5
  72. hud/shared/exceptions.py +180 -180
  73. hud/shared/requests.py +264 -264
  74. hud/shared/tests/test_exceptions.py +157 -157
  75. hud/shared/tests/test_requests.py +275 -275
  76. hud/telemetry/__init__.py +25 -25
  77. hud/telemetry/instrument.py +379 -379
  78. hud/telemetry/job.py +309 -309
  79. hud/telemetry/replay.py +74 -74
  80. hud/telemetry/trace.py +83 -83
  81. hud/tools/__init__.py +33 -33
  82. hud/tools/base.py +365 -365
  83. hud/tools/bash.py +161 -161
  84. hud/tools/computer/__init__.py +15 -15
  85. hud/tools/computer/anthropic.py +437 -437
  86. hud/tools/computer/hud.py +376 -376
  87. hud/tools/computer/openai.py +295 -295
  88. hud/tools/computer/settings.py +82 -82
  89. hud/tools/edit.py +314 -314
  90. hud/tools/executors/__init__.py +30 -30
  91. hud/tools/executors/base.py +539 -539
  92. hud/tools/executors/pyautogui.py +621 -621
  93. hud/tools/executors/tests/__init__.py +1 -1
  94. hud/tools/executors/tests/test_base_executor.py +338 -338
  95. hud/tools/executors/tests/test_pyautogui_executor.py +165 -165
  96. hud/tools/executors/xdo.py +511 -511
  97. hud/tools/playwright.py +412 -412
  98. hud/tools/tests/__init__.py +3 -3
  99. hud/tools/tests/test_base.py +282 -282
  100. hud/tools/tests/test_bash.py +158 -158
  101. hud/tools/tests/test_bash_extended.py +197 -197
  102. hud/tools/tests/test_computer.py +425 -425
  103. hud/tools/tests/test_computer_actions.py +34 -34
  104. hud/tools/tests/test_edit.py +259 -259
  105. hud/tools/tests/test_init.py +27 -27
  106. hud/tools/tests/test_playwright_tool.py +183 -183
  107. hud/tools/tests/test_tools.py +145 -145
  108. hud/tools/tests/test_utils.py +156 -156
  109. hud/tools/types.py +72 -72
  110. hud/tools/utils.py +50 -50
  111. hud/types.py +136 -136
  112. hud/utils/__init__.py +10 -10
  113. hud/utils/async_utils.py +65 -65
  114. hud/utils/design.py +236 -168
  115. hud/utils/mcp.py +55 -55
  116. hud/utils/progress.py +149 -149
  117. hud/utils/telemetry.py +66 -66
  118. hud/utils/tests/test_async_utils.py +173 -173
  119. hud/utils/tests/test_init.py +17 -17
  120. hud/utils/tests/test_progress.py +261 -261
  121. hud/utils/tests/test_telemetry.py +82 -82
  122. hud/utils/tests/test_version.py +8 -8
  123. hud/version.py +7 -7
  124. {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/METADATA +10 -8
  125. hud_python-0.4.3.dist-info/RECORD +131 -0
  126. {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/licenses/LICENSE +21 -21
  127. hud/agents/art.py +0 -101
  128. hud_python-0.4.1.dist-info/RECORD +0 -132
  129. {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/WHEEL +0 -0
  130. {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/entry_points.txt +0 -0
hud/utils/design.py CHANGED
@@ -1,168 +1,236 @@
1
- """HUD Design System - Consistent styling utilities for CLI output.
2
-
3
- This module provides a unified design system for HUD CLI commands,
4
- ensuring consistent colors, formatting, and visual hierarchy across
5
- all commands.
6
-
7
- Color Palette:
8
- - Gold (#c0960c): Primary brand color for headers and important elements
9
- - Black: Standard text and underlined links
10
- - Red: Errors and failures
11
- - Green: Success messages
12
- - Dim/Gray: Secondary information
13
- """
14
-
15
- from __future__ import annotations
16
-
17
- from rich.console import Console
18
- from rich.panel import Panel
19
- from rich.table import Table
20
-
21
- # HUD Brand Colors
22
- GOLD = "rgb(192,150,12)" # #c0960c
23
- RED = "red"
24
- GREEN = "green"
25
- DIM = "dim"
26
-
27
-
28
- class HUDDesign:
29
- """Design system for HUD CLI output."""
30
-
31
- def __init__(self, console: Console | None = None, stderr: bool = False) -> None:
32
- """Initialize the design system.
33
-
34
- Args:
35
- console: Rich console instance. Creates new one if not provided.
36
- stderr: If True, output to stderr instead of stdout.
37
- """
38
- self.console = console or Console(stderr=stderr)
39
-
40
- def header(self, title: str, icon: str = "🚀") -> None:
41
- """Print a header panel with gold border.
42
-
43
- Args:
44
- title: The title text
45
- icon: Optional emoji icon
46
- """
47
- self.console.print(Panel.fit(f"{icon} [bold]{title}[/bold]", border_style=GOLD))
48
-
49
- def section_title(self, title: str) -> None:
50
- """Print a section title in gold.
51
-
52
- Args:
53
- title: The section title
54
- """
55
- self.console.print(f"\n[bold {GOLD}]{title}[/bold {GOLD}]")
56
-
57
- def success(self, message: str) -> None:
58
- """Print a success message.
59
-
60
- Args:
61
- message: The success message
62
- """
63
- self.console.print(f"[{GREEN} not bold]✅ {message}[/{GREEN} not bold]")
64
-
65
- def error(self, message: str) -> None:
66
- """Print an error message.
67
-
68
- Args:
69
- message: The error message
70
- """
71
- self.console.print(f"[{RED} not bold]❌ {message}[/{RED} not bold]")
72
-
73
- def warning(self, message: str) -> None:
74
- """Print a warning message.
75
-
76
- Args:
77
- message: The warning message
78
- """
79
- self.console.print(f"[yellow]⚠️ {message}[/yellow]")
80
-
81
- def info(self, message: str) -> None:
82
- """Print an info message.
83
-
84
- Args:
85
- message: The info message
86
- """
87
- self.console.print(f"[default not bold]{message}[/default not bold]")
88
-
89
- def dim_info(self, label: str, value: str) -> None:
90
- """Print dimmed info with a label.
91
-
92
- Args:
93
- label: The label text
94
- value: The value text
95
- """
96
- self.console.print(f"[{DIM}]{label}[/{DIM}] [default]{value}[/default]")
97
-
98
- def link(self, url: str) -> None:
99
- """Print an underlined link.
100
-
101
- Args:
102
- url: The URL to display
103
- """
104
- self.console.print(f"[default not bold underline]{url}[/default not bold underline]")
105
-
106
- def json_config(self, json_str: str) -> None:
107
- """Print JSON configuration with light theme.
108
-
109
- Args:
110
- json_str: JSON string to display
111
- """
112
- # Just print the JSON as plain text to avoid any syntax coloring
113
- self.console.print(f"[default not bold]{json_str}[/default not bold]")
114
-
115
- def key_value_table(self, data: dict[str, str], show_header: bool = False) -> None:
116
- """Print a key-value table.
117
-
118
- Args:
119
- data: Dictionary of key-value pairs
120
- show_header: Whether to show table header
121
- """
122
- table = Table(show_header=show_header, box=None, padding=(0, 1))
123
- table.add_column("Key", style=DIM, no_wrap=True)
124
- table.add_column("Value")
125
-
126
- for key, value in data.items():
127
- table.add_row(key, value)
128
-
129
- self.console.print(table)
130
-
131
- def progress_message(self, message: str) -> None:
132
- """Print a progress message.
133
-
134
- Args:
135
- message: The progress message
136
- """
137
- self.console.print(f"[{DIM} not bold]{message}[/{DIM} not bold]")
138
-
139
- def phase(self, phase_num: int, title: str) -> None:
140
- """Print a phase header (for debug command).
141
-
142
- Args:
143
- phase_num: Phase number
144
- title: Phase title
145
- """
146
- self.console.print(f"\n{'=' * 80}", style=GOLD)
147
- self.console.print(f"[bold {GOLD}]PHASE {phase_num}: {title}[/bold {GOLD}]")
148
- self.console.print(f"{'=' * 80}", style=GOLD)
149
-
150
- def command(self, cmd: list[str]) -> None:
151
- """Print a command being executed.
152
-
153
- Args:
154
- cmd: Command parts as list
155
- """
156
- self.console.print(f"[bold]$ {' '.join(cmd)}[/bold]")
157
-
158
- def hint(self, hint: str) -> None:
159
- """Print a hint message.
160
-
161
- Args:
162
- hint: The hint text
163
- """
164
- self.console.print(f"\n[yellow]💡 Hint: {hint}[/yellow]")
165
-
166
-
167
- # Global design instance for convenience
168
- design = HUDDesign()
1
+ """HUD Design System - Consistent styling utilities for CLI output.
2
+
3
+ This module provides a unified design system for HUD CLI commands,
4
+ ensuring consistent colors, formatting, and visual hierarchy across
5
+ all commands.
6
+
7
+ Color Palette:
8
+ - Gold (#c0960c): Primary brand color for headers and important elements
9
+ - Black: Standard text and underlined links
10
+ - Red: Errors and failures
11
+ - Green: Success messages
12
+ - Dim/Gray: Secondary information
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from rich.console import Console
18
+ from rich.panel import Panel
19
+ from rich.table import Table
20
+
21
+ # HUD Brand Colors
22
+ GOLD = "rgb(192,150,12)" # #c0960c
23
+ RED = "red"
24
+ GREEN = "green"
25
+ DIM = "dim"
26
+
27
+
28
+ class HUDDesign:
29
+ """Design system for HUD CLI output."""
30
+
31
+ def __init__(self) -> None:
32
+ """Initialize the design system."""
33
+ self._stdout_console = Console(stderr=False)
34
+ self._stderr_console = Console(stderr=True)
35
+
36
+ def header(self, title: str, icon: str = "🚀", stderr: bool = True) -> None:
37
+ """Print a header panel with gold border.
38
+
39
+ Args:
40
+ title: The title text
41
+ icon: Optional emoji icon
42
+ stderr: If True, output to stderr (default), otherwise stdout
43
+ """
44
+ console = self._stderr_console if stderr else self._stdout_console
45
+ console.print(Panel.fit(f"{icon} [bold]{title}[/bold]", border_style=GOLD))
46
+
47
+ def section_title(self, title: str, stderr: bool = True) -> None:
48
+ """Print a section title in gold.
49
+
50
+ Args:
51
+ title: The section title
52
+ stderr: If True, output to stderr (default), otherwise stdout
53
+ """
54
+ console = self._stderr_console if stderr else self._stdout_console
55
+ console.print(f"\n[bold {GOLD}]{title}[/bold {GOLD}]")
56
+
57
+ def success(self, message: str, stderr: bool = True) -> None:
58
+ """Print a success message.
59
+
60
+ Args:
61
+ message: The success message
62
+ stderr: If True, output to stderr (default), otherwise stdout
63
+ """
64
+ console = self._stderr_console if stderr else self._stdout_console
65
+ console.print(f"[{GREEN} not bold]✅ {message}[/{GREEN} not bold]")
66
+
67
+ def error(self, message: str, stderr: bool = True) -> None:
68
+ """Print an error message.
69
+
70
+ Args:
71
+ message: The error message
72
+ stderr: If True, output to stderr (default), otherwise stdout
73
+ """
74
+ console = self._stderr_console if stderr else self._stdout_console
75
+ console.print(f"[{RED} not bold]❌ {message}[/{RED} not bold]")
76
+
77
+ def warning(self, message: str, stderr: bool = True) -> None:
78
+ """Print a warning message.
79
+
80
+ Args:
81
+ message: The warning message
82
+ stderr: If True, output to stderr (default), otherwise stdout
83
+ """
84
+ console = self._stderr_console if stderr else self._stdout_console
85
+ console.print(f"[yellow]⚠️ {message}[/yellow]")
86
+
87
+ def info(self, message: str, stderr: bool = True) -> None:
88
+ """Print an info message.
89
+
90
+ Args:
91
+ message: The info message
92
+ stderr: If True, output to stderr (default), otherwise stdout
93
+ """
94
+ console = self._stderr_console if stderr else self._stdout_console
95
+ console.print(f"[default not bold]{message}[/default not bold]")
96
+
97
+ def dim_info(self, label: str, value: str, stderr: bool = True) -> None:
98
+ """Print dimmed info with a label.
99
+
100
+ Args:
101
+ label: The label text
102
+ value: The value text
103
+ stderr: If True, output to stderr (default), otherwise stdout
104
+ """
105
+ console = self._stderr_console if stderr else self._stdout_console
106
+ console.print(f"[{DIM}]{label}[/{DIM}] [default]{value}[/default]")
107
+
108
+ def link(self, url: str, stderr: bool = True) -> None:
109
+ """Print an underlined link.
110
+
111
+ Args:
112
+ url: The URL to display
113
+ stderr: If True, output to stderr (default), otherwise stdout
114
+ """
115
+ console = self._stderr_console if stderr else self._stdout_console
116
+ console.print(f"[default not bold underline]{url}[/default not bold underline]")
117
+
118
+ def json_config(self, json_str: str, stderr: bool = True) -> None:
119
+ """Print JSON configuration with light theme.
120
+
121
+ Args:
122
+ json_str: JSON string to display
123
+ stderr: If True, output to stderr (default), otherwise stdout
124
+ """
125
+ # Just print the JSON as plain text to avoid any syntax coloring
126
+ console = self._stderr_console if stderr else self._stdout_console
127
+ console.print(f"[default not bold]{json_str}[/default not bold]")
128
+
129
+ def key_value_table(self, data: dict[str, str], show_header: bool = False, stderr: bool = True) -> None:
130
+ """Print a key-value table.
131
+
132
+ Args:
133
+ data: Dictionary of key-value pairs
134
+ show_header: Whether to show table header
135
+ stderr: If True, output to stderr (default), otherwise stdout
136
+ """
137
+ table = Table(show_header=show_header, box=None, padding=(0, 1))
138
+ table.add_column("Key", style=DIM, no_wrap=True)
139
+ table.add_column("Value")
140
+
141
+ for key, value in data.items():
142
+ table.add_row(key, value)
143
+
144
+ console = self._stderr_console if stderr else self._stdout_console
145
+ console.print(table)
146
+
147
+ def progress_message(self, message: str, stderr: bool = True) -> None:
148
+ """Print a progress message.
149
+
150
+ Args:
151
+ message: The progress message
152
+ stderr: If True, output to stderr (default), otherwise stdout
153
+ """
154
+ console = self._stderr_console if stderr else self._stdout_console
155
+ console.print(f"[{DIM} not bold]{message}[/{DIM} not bold]")
156
+
157
+ def phase(self, phase_num: int, title: str, stderr: bool = True) -> None:
158
+ """Print a phase header (for debug command).
159
+
160
+ Args:
161
+ phase_num: Phase number
162
+ title: Phase title
163
+ stderr: If True, output to stderr (default), otherwise stdout
164
+ """
165
+ console = self._stderr_console if stderr else self._stdout_console
166
+ console.print(f"\n{'=' * 80}", style=GOLD)
167
+ console.print(f"[bold {GOLD}]PHASE {phase_num}: {title}[/bold {GOLD}]")
168
+ console.print(f"{'=' * 80}", style=GOLD)
169
+
170
+ def command(self, cmd: list[str], stderr: bool = True) -> None:
171
+ """Print a command being executed.
172
+
173
+ Args:
174
+ cmd: Command parts as list
175
+ stderr: If True, output to stderr (default), otherwise stdout
176
+ """
177
+ console = self._stderr_console if stderr else self._stdout_console
178
+ console.print(f"[bold]$ {' '.join(cmd)}[/bold]")
179
+
180
+ def hint(self, hint: str, stderr: bool = True) -> None:
181
+ """Print a hint message.
182
+
183
+ Args:
184
+ hint: The hint text
185
+ stderr: If True, output to stderr (default), otherwise stdout
186
+ """
187
+ console = self._stderr_console if stderr else self._stdout_console
188
+ console.print(f"\n[yellow]💡 Hint: {hint}[/yellow]")
189
+
190
+ def status_item(self, label: str, value: str, status: str = "success", primary: bool = False, stderr: bool = True) -> None:
191
+ """Print a status item with indicator.
192
+
193
+ Args:
194
+ label: The label text
195
+ value: The value text
196
+ status: Status type - "success" (✓), "error" (✗), "warning" (⚠), "info" (•)
197
+ primary: If True, highlight the value as primary
198
+ stderr: If True, output to stderr (default), otherwise stdout
199
+ """
200
+ indicators = {
201
+ "success": f"[{GREEN} not bold]✓[/{GREEN} not bold]",
202
+ "error": f"[{RED} not bold]✗[/{RED} not bold]",
203
+ "warning": "[yellow]⚠[/yellow]",
204
+ "info": f"[{DIM}]•[/{DIM}]"
205
+ }
206
+
207
+ indicator = indicators.get(status, indicators["info"])
208
+ console = self._stderr_console if stderr else self._stdout_console
209
+
210
+ if primary:
211
+ console.print(f"{indicator} {label}: [bold cyan]{value}[/bold cyan]")
212
+ else:
213
+ console.print(f"{indicator} {label}: {value}")
214
+
215
+ def command_example(self, command: str, description: str | None = None, stderr: bool = True) -> None:
216
+ """Print a command example with cyan highlighting.
217
+
218
+ Args:
219
+ command: The command to show
220
+ description: Optional description after the command
221
+ stderr: If True, output to stderr (default), otherwise stdout
222
+ """
223
+ console = self._stderr_console if stderr else self._stdout_console
224
+ if description:
225
+ console.print(f" [cyan]{command}[/cyan] # {description}")
226
+ else:
227
+ console.print(f" [cyan]{command}[/cyan]")
228
+
229
+ @property
230
+ def console(self) -> Console:
231
+ """Get the stderr console for direct access when needed."""
232
+ return self._stderr_console
233
+
234
+
235
+ # Global design instance for convenience
236
+ design = HUDDesign()
hud/utils/mcp.py CHANGED
@@ -1,55 +1,55 @@
1
- from __future__ import annotations
2
-
3
- from typing import Any
4
-
5
- from pydantic import BaseModel, Field
6
-
7
- from hud.settings import settings
8
-
9
-
10
- class MCPConfigPatch(BaseModel):
11
- """Patch for MCP config."""
12
-
13
- headers: dict[str, Any] | None = Field(default_factory=dict, alias="headers")
14
- meta: dict[str, Any] | None = Field(default_factory=dict, alias="meta")
15
-
16
-
17
- def patch_mcp_config(mcp_config: dict[str, dict[str, Any]], patch: MCPConfigPatch) -> None:
18
- """Patch MCP config with additional values."""
19
- hud_mcp_url = settings.hud_mcp_url
20
-
21
- for server_cfg in mcp_config.values():
22
- url = server_cfg.get("url", "")
23
-
24
- # 1) HTTP header lane (only for hud MCP servers)
25
- if hud_mcp_url in url and patch.headers:
26
- for key, value in patch.headers.items():
27
- headers = server_cfg.setdefault("headers", {})
28
- headers.setdefault(key, value)
29
-
30
- # 2) Metadata lane (for all servers)
31
- if patch.meta:
32
- for key, value in patch.meta.items():
33
- meta = server_cfg.setdefault("meta", {})
34
- meta.setdefault(key, value)
35
-
36
-
37
- def setup_hud_telemetry(mcp_config: dict[str, dict[str, Any]], auto_trace: bool = True) -> None:
38
- """Setup telemetry for hud servers."""
39
- if not mcp_config:
40
- raise ValueError("Please run initialize() before setting up client-side telemetry")
41
-
42
- from hud.otel import get_current_task_run_id
43
- from hud.telemetry import trace
44
-
45
- run_id = get_current_task_run_id()
46
- if not run_id and auto_trace:
47
- auto_trace_cm = trace("My Trace")
48
- run_id = auto_trace_cm.__enter__()
49
-
50
- # Patch HUD servers with run-id (works whether auto or user trace)
51
- if run_id:
52
- patch_mcp_config(
53
- mcp_config,
54
- MCPConfigPatch(headers={"Run-Id": run_id}, meta={"run_id": run_id}),
55
- )
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from pydantic import BaseModel, Field
6
+
7
+ from hud.settings import settings
8
+
9
+
10
+ class MCPConfigPatch(BaseModel):
11
+ """Patch for MCP config."""
12
+
13
+ headers: dict[str, Any] | None = Field(default_factory=dict, alias="headers")
14
+ meta: dict[str, Any] | None = Field(default_factory=dict, alias="meta")
15
+
16
+
17
+ def patch_mcp_config(mcp_config: dict[str, dict[str, Any]], patch: MCPConfigPatch) -> None:
18
+ """Patch MCP config with additional values."""
19
+ hud_mcp_url = settings.hud_mcp_url
20
+
21
+ for server_cfg in mcp_config.values():
22
+ url = server_cfg.get("url", "")
23
+
24
+ # 1) HTTP header lane (only for hud MCP servers)
25
+ if hud_mcp_url in url and patch.headers:
26
+ for key, value in patch.headers.items():
27
+ headers = server_cfg.setdefault("headers", {})
28
+ headers.setdefault(key, value)
29
+
30
+ # 2) Metadata lane (for all servers)
31
+ if patch.meta:
32
+ for key, value in patch.meta.items():
33
+ meta = server_cfg.setdefault("meta", {})
34
+ meta.setdefault(key, value)
35
+
36
+
37
+ def setup_hud_telemetry(mcp_config: dict[str, dict[str, Any]], auto_trace: bool = True) -> None:
38
+ """Setup telemetry for hud servers."""
39
+ if not mcp_config:
40
+ raise ValueError("Please run initialize() before setting up client-side telemetry")
41
+
42
+ from hud.otel import get_current_task_run_id
43
+ from hud.telemetry import trace
44
+
45
+ run_id = get_current_task_run_id()
46
+ if not run_id and auto_trace:
47
+ auto_trace_cm = trace("My Trace")
48
+ run_id = auto_trace_cm.__enter__()
49
+
50
+ # Patch HUD servers with run-id (works whether auto or user trace)
51
+ if run_id:
52
+ patch_mcp_config(
53
+ mcp_config,
54
+ MCPConfigPatch(headers={"Run-Id": run_id}, meta={"run_id": run_id}),
55
+ )