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.
- hud/__init__.py +22 -22
- hud/agents/__init__.py +13 -15
- hud/agents/base.py +599 -599
- hud/agents/claude.py +373 -373
- hud/agents/langchain.py +261 -250
- hud/agents/misc/__init__.py +7 -7
- hud/agents/misc/response_agent.py +82 -80
- hud/agents/openai.py +352 -352
- hud/agents/openai_chat_generic.py +154 -154
- hud/agents/tests/__init__.py +1 -1
- hud/agents/tests/test_base.py +742 -742
- hud/agents/tests/test_claude.py +324 -324
- hud/agents/tests/test_client.py +363 -363
- hud/agents/tests/test_openai.py +237 -237
- hud/cli/__init__.py +617 -617
- hud/cli/__main__.py +8 -8
- hud/cli/analyze.py +371 -371
- hud/cli/analyze_metadata.py +230 -230
- hud/cli/build.py +498 -427
- hud/cli/clone.py +185 -185
- hud/cli/cursor.py +92 -92
- hud/cli/debug.py +392 -392
- hud/cli/docker_utils.py +83 -83
- hud/cli/init.py +280 -281
- hud/cli/interactive.py +353 -353
- hud/cli/mcp_server.py +764 -756
- hud/cli/pull.py +330 -336
- hud/cli/push.py +404 -370
- hud/cli/remote_runner.py +311 -311
- hud/cli/runner.py +160 -160
- hud/cli/tests/__init__.py +3 -3
- hud/cli/tests/test_analyze.py +284 -284
- hud/cli/tests/test_cli_init.py +265 -265
- hud/cli/tests/test_cli_main.py +27 -27
- hud/cli/tests/test_clone.py +142 -142
- hud/cli/tests/test_cursor.py +253 -253
- hud/cli/tests/test_debug.py +453 -453
- hud/cli/tests/test_mcp_server.py +139 -139
- hud/cli/tests/test_utils.py +388 -388
- hud/cli/utils.py +263 -263
- hud/clients/README.md +143 -143
- hud/clients/__init__.py +16 -16
- hud/clients/base.py +378 -379
- hud/clients/fastmcp.py +222 -222
- hud/clients/mcp_use.py +298 -278
- hud/clients/tests/__init__.py +1 -1
- hud/clients/tests/test_client_integration.py +111 -111
- hud/clients/tests/test_fastmcp.py +342 -342
- hud/clients/tests/test_protocol.py +188 -188
- hud/clients/utils/__init__.py +1 -1
- hud/clients/utils/retry_transport.py +160 -160
- hud/datasets.py +327 -322
- hud/misc/__init__.py +1 -1
- hud/misc/claude_plays_pokemon.py +292 -292
- hud/otel/__init__.py +35 -35
- hud/otel/collector.py +142 -142
- hud/otel/config.py +164 -164
- hud/otel/context.py +536 -536
- hud/otel/exporters.py +366 -366
- hud/otel/instrumentation.py +97 -97
- hud/otel/processors.py +118 -118
- hud/otel/tests/__init__.py +1 -1
- hud/otel/tests/test_processors.py +197 -197
- hud/server/__init__.py +5 -5
- hud/server/context.py +114 -114
- hud/server/helper/__init__.py +5 -5
- hud/server/low_level.py +132 -132
- hud/server/server.py +170 -166
- hud/server/tests/__init__.py +3 -3
- hud/settings.py +73 -73
- hud/shared/__init__.py +5 -5
- hud/shared/exceptions.py +180 -180
- hud/shared/requests.py +264 -264
- hud/shared/tests/test_exceptions.py +157 -157
- hud/shared/tests/test_requests.py +275 -275
- hud/telemetry/__init__.py +25 -25
- hud/telemetry/instrument.py +379 -379
- hud/telemetry/job.py +309 -309
- hud/telemetry/replay.py +74 -74
- hud/telemetry/trace.py +83 -83
- hud/tools/__init__.py +33 -33
- hud/tools/base.py +365 -365
- hud/tools/bash.py +161 -161
- hud/tools/computer/__init__.py +15 -15
- hud/tools/computer/anthropic.py +437 -437
- hud/tools/computer/hud.py +376 -376
- hud/tools/computer/openai.py +295 -295
- hud/tools/computer/settings.py +82 -82
- hud/tools/edit.py +314 -314
- hud/tools/executors/__init__.py +30 -30
- hud/tools/executors/base.py +539 -539
- hud/tools/executors/pyautogui.py +621 -621
- hud/tools/executors/tests/__init__.py +1 -1
- hud/tools/executors/tests/test_base_executor.py +338 -338
- hud/tools/executors/tests/test_pyautogui_executor.py +165 -165
- hud/tools/executors/xdo.py +511 -511
- hud/tools/playwright.py +412 -412
- hud/tools/tests/__init__.py +3 -3
- hud/tools/tests/test_base.py +282 -282
- hud/tools/tests/test_bash.py +158 -158
- hud/tools/tests/test_bash_extended.py +197 -197
- hud/tools/tests/test_computer.py +425 -425
- hud/tools/tests/test_computer_actions.py +34 -34
- hud/tools/tests/test_edit.py +259 -259
- hud/tools/tests/test_init.py +27 -27
- hud/tools/tests/test_playwright_tool.py +183 -183
- hud/tools/tests/test_tools.py +145 -145
- hud/tools/tests/test_utils.py +156 -156
- hud/tools/types.py +72 -72
- hud/tools/utils.py +50 -50
- hud/types.py +136 -136
- hud/utils/__init__.py +10 -10
- hud/utils/async_utils.py +65 -65
- hud/utils/design.py +236 -168
- hud/utils/mcp.py +55 -55
- hud/utils/progress.py +149 -149
- hud/utils/telemetry.py +66 -66
- hud/utils/tests/test_async_utils.py +173 -173
- hud/utils/tests/test_init.py +17 -17
- hud/utils/tests/test_progress.py +261 -261
- hud/utils/tests/test_telemetry.py +82 -82
- hud/utils/tests/test_version.py +8 -8
- hud/version.py +7 -7
- {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/METADATA +10 -8
- hud_python-0.4.3.dist-info/RECORD +131 -0
- {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/licenses/LICENSE +21 -21
- hud/agents/art.py +0 -101
- hud_python-0.4.1.dist-info/RECORD +0 -132
- {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/WHEEL +0 -0
- {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.
|
|
9
|
-
from rich.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
COPY
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
[
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
[
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
self.count
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
from hud.server import
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
""
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
- `src/hud_controller/
|
|
130
|
-
- `
|
|
131
|
-
- `
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
"
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
self.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
- [
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
package_name
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
design.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
src_dir =
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
dockerfile_path
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
#
|
|
231
|
-
|
|
232
|
-
init_path
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
context_path
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
"
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
syntax
|
|
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"))
|