hud-python 0.4.1__py3-none-any.whl → 0.4.2__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 +250 -250
  6. hud/agents/misc/__init__.py +7 -7
  7. hud/agents/misc/response_agent.py +80 -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 +427 -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 +281 -281
  25. hud/cli/interactive.py +353 -353
  26. hud/cli/mcp_server.py +789 -756
  27. hud/cli/pull.py +336 -336
  28. hud/cli/push.py +370 -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 +379 -379
  44. hud/clients/fastmcp.py +202 -222
  45. hud/clients/mcp_use.py +278 -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 +322 -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 +168 -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.2.dist-info}/METADATA +10 -8
  125. hud_python-0.4.2.dist-info/RECORD +131 -0
  126. {hud_python-0.4.1.dist-info → hud_python-0.4.2.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.2.dist-info}/WHEEL +0 -0
  130. {hud_python-0.4.1.dist-info → hud_python-0.4.2.dist-info}/entry_points.txt +0 -0
hud/cli/init.py CHANGED
@@ -1,281 +1,281 @@
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.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 (with MCP inspector):")
259
+ console.print(" [cyan]hud dev --inspector[/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 (with MCP inspector):")
264
+ console.print(" [cyan]hud dev --inspector[/cyan]")
265
+
266
+ console.print("\n3. Connect from Cursor or test via the MCP inspector:")
267
+ console.print(" Follow the instructions shown by [cyan]hud dev --inspector[/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"))