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/cli/init.py CHANGED
@@ -1,281 +1,280 @@
1
- """Initialize new HUD environments with minimal templates."""
2
-
3
- from __future__ import annotations
4
-
5
- from pathlib import Path
6
-
7
- import typer
8
- from rich.console import Console
9
- from rich.panel import Panel
10
- from rich.syntax import Syntax
11
-
12
- console = Console()
13
-
14
- # Embedded templates
15
- DOCKERFILE_TEMPLATE = """FROM python:3.11-slim
16
-
17
- WORKDIR /app
18
-
19
- # Install git for hud-python dependency
20
- RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
21
-
22
- # Copy and install dependencies
23
- COPY pyproject.toml ./
24
- COPY src/ ./src/
25
- RUN pip install --no-cache-dir -e .
26
-
27
- # Set logging to stderr
28
- ENV HUD_LOG_STREAM=stderr
29
-
30
- # Start context server in background, then MCP server
31
- CMD ["sh", "-c", "python -m hud_controller.context & sleep 1 && exec python -m hud_controller.server"]
32
- """ # noqa: E501
33
-
34
- PYPROJECT_TEMPLATE = """[project]
35
- name = "{name}"
36
- version = "0.1.0"
37
- description = "A minimal HUD environment"
38
- requires-python = ">=3.11"
39
- dependencies = [
40
- "hud-python",
41
- ]
42
-
43
- [build-system]
44
- requires = ["hatchling"]
45
- build-backend = "hatchling.build"
46
-
47
- [tool.hud]
48
- image = "{name}:dev"
49
-
50
- [tool.hatch.metadata]
51
- allow-direct-references = true
52
-
53
- [tool.hatch.build.targets.wheel]
54
- packages = ["src/hud_controller"]
55
- """
56
-
57
- CONTEXT_TEMPLATE = '''"""Minimal context that persists across hot-reloads."""
58
- from hud.server.context import run_context_server
59
- import asyncio
60
-
61
- class Context:
62
- def __init__(self):
63
- self.count = 0
64
-
65
- def act(self):
66
- self.count += 1
67
- return self.count
68
-
69
- def get_count(self):
70
- return self.count
71
-
72
- if __name__ == "__main__":
73
- asyncio.run(run_context_server(Context()))
74
- '''
75
-
76
- SERVER_TEMPLATE = '''"""Minimal MCP server for HUD."""
77
- from hud.server import MCPServer
78
- from hud.server.context import attach_context
79
-
80
- mcp = MCPServer(name="{name}")
81
- ctx = None
82
-
83
- @mcp.initialize
84
- async def init(init_ctx):
85
- global ctx
86
- ctx = attach_context("/tmp/hud_ctx.sock")
87
-
88
- @mcp.shutdown
89
- async def cleanup():
90
- global ctx
91
- ctx = None
92
-
93
- @mcp.tool()
94
- async def act() -> str:
95
- """Perform an action."""
96
- return f"Action #{{ctx.act()}}"
97
-
98
- @mcp.tool()
99
- async def setup() -> str:
100
- """Required for HUD environments."""
101
- return "Ready"
102
-
103
- @mcp.tool()
104
- async def evaluate() -> dict:
105
- """Required for HUD environments."""
106
- return {{"count": ctx.get_count()}}
107
-
108
- if __name__ == "__main__":
109
- mcp.run()
110
- '''
111
-
112
- README_TEMPLATE = '''# {title}
113
-
114
- A minimal HUD environment created with `hud init`.
115
-
116
- ## Quick Start
117
-
118
- ```bash
119
- # Build and run locally
120
- hud dev
121
-
122
- # Or build first
123
- docker build -t {name}:dev .
124
- hud dev --image {name}:dev
125
- ```
126
-
127
- ## Structure
128
-
129
- - `src/hud_controller/server.py` - MCP server with tools
130
- - `src/hud_controller/context.py` - Persistent state across hot-reloads
131
- - `Dockerfile` - Container configuration
132
- - `pyproject.toml` - Python dependencies
133
-
134
- ## Adding Tools
135
-
136
- Add new tools to `server.py`:
137
-
138
- ```python
139
- @mcp.tool()
140
- async def my_tool(param: str) -> str:
141
- """Tool description."""
142
- return f"Result: {{param}}"
143
- ```
144
-
145
- ## Adding State
146
-
147
- Extend the `Context` class in `context.py`:
148
-
149
- ```python
150
- class Context:
151
- def __init__(self):
152
- self.count = 0
153
- self.data = {{}} # Add your state
154
- ```
155
-
156
- ## Learn More
157
-
158
- - [HUD Documentation](https://docs.hud.so)
159
- - [MCP Specification](https://modelcontextprotocol.io)
160
- '''
161
-
162
-
163
- def sanitize_name(name: str) -> str:
164
- """Convert a name to a valid Python package name."""
165
- # Replace spaces and hyphens with underscores
166
- name = name.replace(" ", "_").replace("-", "_")
167
- # Remove any non-alphanumeric characters except underscores
168
- name = "".join(c for c in name if c.isalnum() or c == "_")
169
- # Ensure it doesn't start with a number
170
- if name and name[0].isdigit():
171
- name = f"env_{name}"
172
- return name.lower()
173
-
174
-
175
- def create_environment(name: str | None, directory: str, force: bool) -> None:
176
- """Create a new HUD environment from templates."""
177
- from hud.utils.design import HUDDesign
178
-
179
- design = HUDDesign()
180
-
181
- # Determine environment name
182
- if name is None:
183
- # Use current directory name
184
- current_dir = Path.cwd()
185
- name = current_dir.name
186
- target_dir = current_dir
187
- design.info(f"Using current directory name: {name}")
188
- else:
189
- # Create new directory
190
- target_dir = Path(directory) / name
191
-
192
- # Sanitize name for Python package
193
- package_name = sanitize_name(name)
194
- if package_name != name:
195
- design.warning(f"Package name adjusted for Python: {name} → {package_name}")
196
-
197
- # Check if directory exists
198
- if target_dir.exists() and any(target_dir.iterdir()):
199
- if not force:
200
- design.error(f"Directory {target_dir} already exists and is not empty")
201
- design.info("Use --force to overwrite existing files")
202
- raise typer.Exit(1)
203
- else:
204
- design.warning(f"Overwriting existing files in {target_dir}")
205
-
206
- # Create directory structure
207
- src_dir = target_dir / "src" / "hud_controller"
208
- src_dir.mkdir(parents=True, exist_ok=True)
209
-
210
- # Write files with proper formatting
211
- files_created = []
212
-
213
- # Dockerfile
214
- dockerfile_path = target_dir / "Dockerfile"
215
- dockerfile_path.write_text(DOCKERFILE_TEMPLATE.strip() + "\n")
216
- files_created.append("Dockerfile")
217
-
218
- # pyproject.toml
219
- pyproject_path = target_dir / "pyproject.toml"
220
- pyproject_content = PYPROJECT_TEMPLATE.format(name=package_name).strip() + "\n"
221
- pyproject_path.write_text(pyproject_content)
222
- files_created.append("pyproject.toml")
223
-
224
- # README.md
225
- readme_path = target_dir / "README.md"
226
- readme_content = README_TEMPLATE.format(name=package_name, title=name).strip() + "\n"
227
- readme_path.write_text(readme_content)
228
- files_created.append("README.md")
229
-
230
- # Python files
231
- # __init__.py
232
- init_path = src_dir / "__init__.py"
233
- init_path.write_text('"""HUD Controller Package"""\n')
234
- files_created.append("src/hud_controller/__init__.py")
235
-
236
- # context.py
237
- context_path = src_dir / "context.py"
238
- context_path.write_text(CONTEXT_TEMPLATE.strip() + "\n")
239
- files_created.append("src/hud_controller/context.py")
240
-
241
- # server.py (need to escape the double braces for .format())
242
- server_path = src_dir / "server.py"
243
- server_content = SERVER_TEMPLATE.format(name=package_name).strip() + "\n"
244
- server_path.write_text(server_content)
245
- files_created.append("src/hud_controller/server.py")
246
-
247
- # Success message
248
- design.header(f"Created HUD Environment: {name}")
249
-
250
- design.section_title("Files created")
251
- for file in files_created:
252
- console.print(f" ✓ {file}")
253
-
254
- design.section_title("Next steps")
255
-
256
- # Show commands based on where we created the environment
257
- if target_dir == Path.cwd():
258
- console.print("1. Start development server:")
259
- console.print(" [cyan]hud dev[/cyan]")
260
- else:
261
- console.print("1. Enter the directory:")
262
- console.print(f" [cyan]cd {target_dir}[/cyan]")
263
- console.print("\n2. Start development server:")
264
- console.print(" [cyan]hud dev[/cyan]")
265
-
266
- console.print("\n3. Connect from Cursor:")
267
- console.print(" Follow the instructions shown by [cyan]hud dev[/cyan]")
268
-
269
- console.print("\n4. Customize your environment:")
270
- console.print(" - Add tools to [cyan]src/hud_controller/server.py[/cyan]")
271
- console.print(" - Add state to [cyan]src/hud_controller/context.py[/cyan]")
272
-
273
- # Show a sample of the server code
274
- design.section_title("Your MCP server")
275
- sample_code = '''@mcp.tool()
276
- async def act() -> str:
277
- """Perform an action."""
278
- return f"Action #{ctx.act()}"'''
279
-
280
- syntax = Syntax(sample_code, "python", theme="monokai", line_numbers=False)
281
- console.print(Panel(syntax, border_style="dim"))
1
+ """Initialize new HUD environments with minimal templates."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import typer
8
+ from rich.panel import Panel
9
+ from rich.syntax import Syntax
10
+
11
+ from hud.utils.design import HUDDesign
12
+
13
+ # Embedded templates
14
+ DOCKERFILE_TEMPLATE = """FROM python:3.11-slim
15
+
16
+ WORKDIR /app
17
+
18
+ # Install git for hud-python dependency
19
+ RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
20
+
21
+ # Copy and install dependencies
22
+ COPY pyproject.toml ./
23
+ COPY src/ ./src/
24
+ RUN pip install --no-cache-dir -e .
25
+
26
+ # Set logging to stderr
27
+ ENV HUD_LOG_STREAM=stderr
28
+
29
+ # Start context server in background, then MCP server
30
+ CMD ["sh", "-c", "python -m hud_controller.context & sleep 1 && exec python -m hud_controller.server"]
31
+ """ # noqa: E501
32
+
33
+ PYPROJECT_TEMPLATE = """[project]
34
+ name = "{name}"
35
+ version = "0.1.0"
36
+ description = "A minimal HUD environment"
37
+ requires-python = ">=3.11"
38
+ dependencies = [
39
+ "hud-python",
40
+ ]
41
+
42
+ [build-system]
43
+ requires = ["hatchling"]
44
+ build-backend = "hatchling.build"
45
+
46
+ [tool.hud]
47
+ image = "{name}:dev"
48
+
49
+ [tool.hatch.metadata]
50
+ allow-direct-references = true
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["src/hud_controller"]
54
+ """
55
+
56
+ CONTEXT_TEMPLATE = '''"""Minimal context that persists across hot-reloads."""
57
+ from hud.server.context import run_context_server
58
+ import asyncio
59
+
60
+ class Context:
61
+ def __init__(self):
62
+ self.count = 0
63
+
64
+ def act(self):
65
+ self.count += 1
66
+ return self.count
67
+
68
+ def get_count(self):
69
+ return self.count
70
+
71
+ if __name__ == "__main__":
72
+ asyncio.run(run_context_server(Context()))
73
+ '''
74
+
75
+ SERVER_TEMPLATE = '''"""Minimal MCP server for HUD."""
76
+ from hud.server import MCPServer
77
+ from hud.server.context import attach_context
78
+
79
+ mcp = MCPServer(name="{name}")
80
+ ctx = None
81
+
82
+ @mcp.initialize
83
+ async def init(init_ctx):
84
+ global ctx
85
+ ctx = attach_context("/tmp/hud_ctx.sock")
86
+
87
+ @mcp.shutdown
88
+ async def cleanup():
89
+ global ctx
90
+ ctx = None
91
+
92
+ @mcp.tool()
93
+ async def act() -> str:
94
+ """Perform an action."""
95
+ return f"Action #{{ctx.act()}}"
96
+
97
+ @mcp.tool()
98
+ async def setup() -> str:
99
+ """Required for HUD environments."""
100
+ return "Ready"
101
+
102
+ @mcp.tool()
103
+ async def evaluate() -> dict:
104
+ """Required for HUD environments."""
105
+ return {{"count": ctx.get_count()}}
106
+
107
+ if __name__ == "__main__":
108
+ mcp.run()
109
+ '''
110
+
111
+ README_TEMPLATE = '''# {title}
112
+
113
+ A minimal HUD environment created with `hud init`.
114
+
115
+ ## Quick Start
116
+
117
+ ```bash
118
+ # Build and run locally
119
+ hud dev
120
+
121
+ # Or build first
122
+ docker build -t {name}:dev .
123
+ hud dev --image {name}:dev
124
+ ```
125
+
126
+ ## Structure
127
+
128
+ - `src/hud_controller/server.py` - MCP server with tools
129
+ - `src/hud_controller/context.py` - Persistent state across hot-reloads
130
+ - `Dockerfile` - Container configuration
131
+ - `pyproject.toml` - Python dependencies
132
+
133
+ ## Adding Tools
134
+
135
+ Add new tools to `server.py`:
136
+
137
+ ```python
138
+ @mcp.tool()
139
+ async def my_tool(param: str) -> str:
140
+ """Tool description."""
141
+ return f"Result: {{param}}"
142
+ ```
143
+
144
+ ## Adding State
145
+
146
+ Extend the `Context` class in `context.py`:
147
+
148
+ ```python
149
+ class Context:
150
+ def __init__(self):
151
+ self.count = 0
152
+ self.data = {{}} # Add your state
153
+ ```
154
+
155
+ ## Learn More
156
+
157
+ - [HUD Documentation](https://docs.hud.so)
158
+ - [MCP Specification](https://modelcontextprotocol.io)
159
+ '''
160
+
161
+
162
+ def sanitize_name(name: str) -> str:
163
+ """Convert a name to a valid Python package name."""
164
+ # Replace spaces and hyphens with underscores
165
+ name = name.replace(" ", "_").replace("-", "_")
166
+ # Remove any non-alphanumeric characters except underscores
167
+ name = "".join(c for c in name if c.isalnum() or c == "_")
168
+ # Ensure it doesn't start with a number
169
+ if name and name[0].isdigit():
170
+ name = f"env_{name}"
171
+ return name.lower()
172
+
173
+
174
+ def create_environment(name: str | None, directory: str, force: bool) -> None:
175
+ """Create a new HUD environment from templates."""
176
+ from hud.utils.design import HUDDesign
177
+
178
+ design = HUDDesign()
179
+
180
+ # Determine environment name
181
+ if name is None:
182
+ # Use current directory name
183
+ current_dir = Path.cwd()
184
+ name = current_dir.name
185
+ target_dir = current_dir
186
+ design.info(f"Using current directory name: {name}")
187
+ else:
188
+ # Create new directory
189
+ target_dir = Path(directory) / name
190
+
191
+ # Sanitize name for Python package
192
+ package_name = sanitize_name(name)
193
+ if package_name != name:
194
+ design.warning(f"Package name adjusted for Python: {name} → {package_name}")
195
+
196
+ # Check if directory exists
197
+ if target_dir.exists() and any(target_dir.iterdir()):
198
+ if not force:
199
+ design.error(f"Directory {target_dir} already exists and is not empty")
200
+ design.info("Use --force to overwrite existing files")
201
+ raise typer.Exit(1)
202
+ else:
203
+ design.warning(f"Overwriting existing files in {target_dir}")
204
+
205
+ # Create directory structure
206
+ src_dir = target_dir / "src" / "hud_controller"
207
+ src_dir.mkdir(parents=True, exist_ok=True)
208
+
209
+ # Write files with proper formatting
210
+ files_created = []
211
+
212
+ # Dockerfile
213
+ dockerfile_path = target_dir / "Dockerfile"
214
+ dockerfile_path.write_text(DOCKERFILE_TEMPLATE.strip() + "\n")
215
+ files_created.append("Dockerfile")
216
+
217
+ # pyproject.toml
218
+ pyproject_path = target_dir / "pyproject.toml"
219
+ pyproject_content = PYPROJECT_TEMPLATE.format(name=package_name).strip() + "\n"
220
+ pyproject_path.write_text(pyproject_content)
221
+ files_created.append("pyproject.toml")
222
+
223
+ # README.md
224
+ readme_path = target_dir / "README.md"
225
+ readme_content = README_TEMPLATE.format(name=package_name, title=name).strip() + "\n"
226
+ readme_path.write_text(readme_content)
227
+ files_created.append("README.md")
228
+
229
+ # Python files
230
+ # __init__.py
231
+ init_path = src_dir / "__init__.py"
232
+ init_path.write_text('"""HUD Controller Package"""\n')
233
+ files_created.append("src/hud_controller/__init__.py")
234
+
235
+ # context.py
236
+ context_path = src_dir / "context.py"
237
+ context_path.write_text(CONTEXT_TEMPLATE.strip() + "\n")
238
+ files_created.append("src/hud_controller/context.py")
239
+
240
+ # server.py (need to escape the double braces for .format())
241
+ server_path = src_dir / "server.py"
242
+ server_content = SERVER_TEMPLATE.format(name=package_name).strip() + "\n"
243
+ server_path.write_text(server_content)
244
+ files_created.append("src/hud_controller/server.py")
245
+
246
+ # Success message
247
+ design.header(f"Created HUD Environment: {name}")
248
+
249
+ design.section_title("Files created")
250
+ for file in files_created:
251
+ design.status_item(file, "created")
252
+
253
+ design.section_title("Next steps")
254
+
255
+ # Show commands based on where we created the environment
256
+ if target_dir == Path.cwd():
257
+ design.info("1. Start development server (with MCP inspector):")
258
+ design.command_example("hud dev --inspector")
259
+ else:
260
+ design.info("1. Enter the directory:")
261
+ design.command_example(f"cd {target_dir}")
262
+ design.info("\n2. Start development server (with MCP inspector):")
263
+ design.command_example("hud dev --inspector")
264
+
265
+ design.info("\n3. Connect from Cursor or test via the MCP inspector:")
266
+ design.info(" Follow the instructions shown by hud dev --inspector")
267
+
268
+ design.info("\n4. Customize your environment:")
269
+ design.info(" - Add tools to src/hud_controller/server.py")
270
+ design.info(" - Add state to src/hud_controller/context.py")
271
+
272
+ # Show a sample of the server code
273
+ design.section_title("Your MCP server")
274
+ sample_code = '''@mcp.tool()
275
+ async def act() -> str:
276
+ """Perform an action."""
277
+ return f"Action #{ctx.act()}"'''
278
+
279
+ syntax = Syntax(sample_code, "python", theme="monokai", line_numbers=False)
280
+ design.console.print(Panel(syntax, border_style="dim"))