dutchmate-cli 0.1.0__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.
- dutchmate_cli/__init__.py +1 -0
- dutchmate_cli/baseline.py +38 -0
- dutchmate_cli/capture.py +94 -0
- dutchmate_cli/client.py +427 -0
- dutchmate_cli/config.py +160 -0
- dutchmate_cli/devices.py +63 -0
- dutchmate_cli/dut.py +32 -0
- dutchmate_cli/gpio.py +33 -0
- dutchmate_cli/lifecycle.py +225 -0
- dutchmate_cli/logs.py +92 -0
- dutchmate_cli/main.py +615 -0
- dutchmate_cli/mcp.py +51 -0
- dutchmate_cli/send.py +32 -0
- dutchmate_cli/sessions.py +137 -0
- dutchmate_cli/status.py +185 -0
- dutchmate_cli/wait.py +41 -0
- dutchmate_cli-0.1.0.dist-info/METADATA +15 -0
- dutchmate_cli-0.1.0.dist-info/RECORD +20 -0
- dutchmate_cli-0.1.0.dist-info/WHEEL +4 -0
- dutchmate_cli-0.1.0.dist-info/licenses/LICENSE +73 -0
dutchmate_cli/main.py
ADDED
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
"""Command-line entrypoint for DUTchMate."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Annotated, NoReturn
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from dutchmate_cli.baseline import format_baseline_mutation
|
|
10
|
+
from dutchmate_cli.capture import format_boot_test_result, format_capture_result
|
|
11
|
+
from dutchmate_cli.client import (
|
|
12
|
+
ServiceClientError,
|
|
13
|
+
ServiceUnavailableError,
|
|
14
|
+
capture_uart,
|
|
15
|
+
clear_session_baseline,
|
|
16
|
+
configure_gpio_mode,
|
|
17
|
+
fetch_recent_logs,
|
|
18
|
+
fetch_status,
|
|
19
|
+
get_debug_session,
|
|
20
|
+
list_debug_sessions,
|
|
21
|
+
mark_session_baseline,
|
|
22
|
+
reset_dut,
|
|
23
|
+
run_boot_test,
|
|
24
|
+
send_uart_command,
|
|
25
|
+
set_boot_mode,
|
|
26
|
+
wait_for_pattern,
|
|
27
|
+
)
|
|
28
|
+
from dutchmate_cli.config import CliConfig, CliConfigError, load_cli_config
|
|
29
|
+
from dutchmate_cli.devices import DeviceSelectionError, format_devices, resolve_start_serial_port
|
|
30
|
+
from dutchmate_cli.dut import format_boot_mode_result, format_reset_result
|
|
31
|
+
from dutchmate_cli.gpio import format_gpio_mode_result
|
|
32
|
+
from dutchmate_cli.lifecycle import (
|
|
33
|
+
LifecycleError,
|
|
34
|
+
start_service,
|
|
35
|
+
stop_service,
|
|
36
|
+
)
|
|
37
|
+
from dutchmate_cli.logs import format_recent_logs
|
|
38
|
+
from dutchmate_cli.mcp import McpLaunchError, McpLogLevel, launch_mcp
|
|
39
|
+
from dutchmate_cli.send import format_uart_send
|
|
40
|
+
from dutchmate_cli.sessions import format_session_detail, format_session_list
|
|
41
|
+
from dutchmate_cli.status import format_status
|
|
42
|
+
from dutchmate_cli.wait import format_wait_pattern
|
|
43
|
+
from dutchmate_core.backends.settings import (
|
|
44
|
+
BackendConfigError,
|
|
45
|
+
resolve_backend_mode,
|
|
46
|
+
resolve_backend_settings,
|
|
47
|
+
)
|
|
48
|
+
from dutchmate_core.device_connection.discovery import (
|
|
49
|
+
list_dutchmate_candidates,
|
|
50
|
+
list_serial_ports,
|
|
51
|
+
)
|
|
52
|
+
from dutchmate_core.validation import validate_capture_duration, validate_gpio_configuration
|
|
53
|
+
|
|
54
|
+
app = typer.Typer(help="DUTchMate hardware debug helper.", no_args_is_help=True)
|
|
55
|
+
dut_app = typer.Typer(help="Run DUT-level workflows through configured control roles.")
|
|
56
|
+
gpio_app = typer.Typer(help="Configure and inspect DUT control GPIO channels.")
|
|
57
|
+
app.add_typer(dut_app, name="dut")
|
|
58
|
+
app.add_typer(gpio_app, name="gpio")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@app.callback()
|
|
62
|
+
def main() -> None:
|
|
63
|
+
"""DUTchMate command-line interface."""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _validate_positive_seconds(value: float) -> float:
|
|
67
|
+
try:
|
|
68
|
+
return validate_capture_duration(value)
|
|
69
|
+
except ValueError as exc:
|
|
70
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@app.command()
|
|
74
|
+
def start(
|
|
75
|
+
host: Annotated[
|
|
76
|
+
str | None,
|
|
77
|
+
typer.Option("--host", help="Host interface for the local Device Core Service."),
|
|
78
|
+
] = None,
|
|
79
|
+
port: Annotated[
|
|
80
|
+
int | None,
|
|
81
|
+
typer.Option("--port", min=1, max=65535, help="HTTP port for the local service."),
|
|
82
|
+
] = None,
|
|
83
|
+
serial_port: Annotated[
|
|
84
|
+
str | None,
|
|
85
|
+
typer.Option("--serial-port", help="Selected backend serial device path."),
|
|
86
|
+
] = None,
|
|
87
|
+
backend: Annotated[
|
|
88
|
+
str | None,
|
|
89
|
+
typer.Option("--backend", help="Required backend mode: basic or enhanced."),
|
|
90
|
+
] = None,
|
|
91
|
+
baudrate: Annotated[
|
|
92
|
+
int | None,
|
|
93
|
+
typer.Option("--baudrate", help="DUT UART baudrate."),
|
|
94
|
+
] = None,
|
|
95
|
+
) -> None:
|
|
96
|
+
"""Start the Device Core Service."""
|
|
97
|
+
config = _load_config_or_fail()
|
|
98
|
+
resolved_host = host or config.daemon.host
|
|
99
|
+
resolved_port = port or config.daemon.port
|
|
100
|
+
try:
|
|
101
|
+
resolved_mode = resolve_backend_mode(config.backend, backend)
|
|
102
|
+
configured_serial_port = serial_port or config.backend.serial_port
|
|
103
|
+
resolved_serial_port = (
|
|
104
|
+
resolve_start_serial_port(
|
|
105
|
+
configured_serial_port,
|
|
106
|
+
list_dutchmate_candidates(),
|
|
107
|
+
)
|
|
108
|
+
if resolved_mode == "enhanced"
|
|
109
|
+
else configured_serial_port
|
|
110
|
+
)
|
|
111
|
+
backend_settings = resolve_backend_settings(
|
|
112
|
+
config.backend,
|
|
113
|
+
mode=resolved_mode,
|
|
114
|
+
serial_port=resolved_serial_port,
|
|
115
|
+
baudrate=baudrate,
|
|
116
|
+
)
|
|
117
|
+
except (BackendConfigError, DeviceSelectionError) as exc:
|
|
118
|
+
_fail(str(exc))
|
|
119
|
+
|
|
120
|
+
try:
|
|
121
|
+
result = start_service(
|
|
122
|
+
host=resolved_host,
|
|
123
|
+
port=resolved_port,
|
|
124
|
+
session_root=config.sessions.path,
|
|
125
|
+
session_max_size_mb=config.sessions.max_size_mb,
|
|
126
|
+
session_max_count=config.sessions.max_count,
|
|
127
|
+
backend_settings=backend_settings,
|
|
128
|
+
)
|
|
129
|
+
except LifecycleError as exc:
|
|
130
|
+
_fail(str(exc))
|
|
131
|
+
|
|
132
|
+
typer.echo(f"Device Core Service started (pid {result.pid}, {result.url})")
|
|
133
|
+
if not result.ready:
|
|
134
|
+
typer.echo(f"Status endpoint is not ready yet. Logs: {result.log_file}")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@app.command()
|
|
138
|
+
def stop() -> None:
|
|
139
|
+
"""Stop the Device Core Service."""
|
|
140
|
+
try:
|
|
141
|
+
result = stop_service()
|
|
142
|
+
except LifecycleError as exc:
|
|
143
|
+
_fail(str(exc))
|
|
144
|
+
|
|
145
|
+
typer.echo(f"Device Core Service stopped (pid {result.pid})")
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@app.command()
|
|
149
|
+
def devices(
|
|
150
|
+
all_ports: Annotated[
|
|
151
|
+
bool,
|
|
152
|
+
typer.Option("--all", help="Show all serial ports, not just DUTchMate candidates."),
|
|
153
|
+
] = False,
|
|
154
|
+
) -> None:
|
|
155
|
+
"""List serial ports that may be DUTchMate Debug Helpers."""
|
|
156
|
+
candidates = list_serial_ports() if all_ports else list_dutchmate_candidates()
|
|
157
|
+
typer.echo(format_devices(candidates))
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@app.command()
|
|
161
|
+
def status(
|
|
162
|
+
service_url: Annotated[
|
|
163
|
+
str | None,
|
|
164
|
+
typer.Option(
|
|
165
|
+
"--service-url",
|
|
166
|
+
help="Base URL for the local Device Core Service.",
|
|
167
|
+
),
|
|
168
|
+
] = None,
|
|
169
|
+
) -> None:
|
|
170
|
+
"""Show DUTchMate service and hardware status."""
|
|
171
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
172
|
+
try:
|
|
173
|
+
payload = fetch_status(service_url=resolved_service_url)
|
|
174
|
+
except ServiceUnavailableError as exc:
|
|
175
|
+
_fail(str(exc))
|
|
176
|
+
except ServiceClientError as exc:
|
|
177
|
+
_fail(str(exc))
|
|
178
|
+
|
|
179
|
+
typer.echo(format_status(payload))
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@app.command("sessions")
|
|
183
|
+
def sessions_command(
|
|
184
|
+
limit: Annotated[
|
|
185
|
+
int,
|
|
186
|
+
typer.Option("--limit", min=1, max=100, help="Maximum sessions to return."),
|
|
187
|
+
] = 50,
|
|
188
|
+
cursor: Annotated[
|
|
189
|
+
str | None,
|
|
190
|
+
typer.Option("--cursor", help="Opaque continuation cursor from a previous page."),
|
|
191
|
+
] = None,
|
|
192
|
+
service_url: Annotated[
|
|
193
|
+
str | None,
|
|
194
|
+
typer.Option("--service-url", help="Base URL for the local Device Core Service."),
|
|
195
|
+
] = None,
|
|
196
|
+
) -> None:
|
|
197
|
+
"""List bounded debug-session summaries."""
|
|
198
|
+
|
|
199
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
200
|
+
try:
|
|
201
|
+
payload = list_debug_sessions(
|
|
202
|
+
limit=limit,
|
|
203
|
+
cursor=cursor,
|
|
204
|
+
service_url=resolved_service_url,
|
|
205
|
+
)
|
|
206
|
+
except ValueError as exc:
|
|
207
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
208
|
+
except ServiceUnavailableError as exc:
|
|
209
|
+
_fail(str(exc))
|
|
210
|
+
except ServiceClientError as exc:
|
|
211
|
+
_fail(str(exc))
|
|
212
|
+
typer.echo(format_session_list(payload))
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
@app.command("session")
|
|
216
|
+
def session_command(
|
|
217
|
+
session_id: Annotated[str, typer.Argument(help="Exact debug-session ID.")],
|
|
218
|
+
service_url: Annotated[
|
|
219
|
+
str | None,
|
|
220
|
+
typer.Option("--service-url", help="Base URL for the local Device Core Service."),
|
|
221
|
+
] = None,
|
|
222
|
+
) -> None:
|
|
223
|
+
"""Show bounded detail for one debug session."""
|
|
224
|
+
|
|
225
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
226
|
+
try:
|
|
227
|
+
payload = get_debug_session(session_id, service_url=resolved_service_url)
|
|
228
|
+
except ValueError as exc:
|
|
229
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
230
|
+
except ServiceUnavailableError as exc:
|
|
231
|
+
_fail(str(exc))
|
|
232
|
+
except ServiceClientError as exc:
|
|
233
|
+
_fail(str(exc))
|
|
234
|
+
typer.echo(format_session_detail(payload))
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
@app.command("mark-baseline")
|
|
238
|
+
def mark_baseline_command(
|
|
239
|
+
session_id: Annotated[str, typer.Argument(help="Eligible native debug-session ID.")],
|
|
240
|
+
service_url: Annotated[
|
|
241
|
+
str | None,
|
|
242
|
+
typer.Option("--service-url", help="Base URL for the local Device Core Service."),
|
|
243
|
+
] = None,
|
|
244
|
+
) -> None:
|
|
245
|
+
"""Designate one completed capture or boot test as the baseline."""
|
|
246
|
+
|
|
247
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
248
|
+
try:
|
|
249
|
+
payload = mark_session_baseline(
|
|
250
|
+
session_id,
|
|
251
|
+
service_url=resolved_service_url,
|
|
252
|
+
)
|
|
253
|
+
except ValueError as exc:
|
|
254
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
255
|
+
except ServiceUnavailableError as exc:
|
|
256
|
+
_fail(str(exc))
|
|
257
|
+
except ServiceClientError as exc:
|
|
258
|
+
_fail(str(exc))
|
|
259
|
+
typer.echo(format_baseline_mutation(payload, action="mark"))
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
@app.command("clear-baseline")
|
|
263
|
+
def clear_baseline_command(
|
|
264
|
+
session_id: Annotated[str, typer.Argument(help="Exact debug-session ID to clear.")],
|
|
265
|
+
service_url: Annotated[
|
|
266
|
+
str | None,
|
|
267
|
+
typer.Option("--service-url", help="Base URL for the local Device Core Service."),
|
|
268
|
+
] = None,
|
|
269
|
+
) -> None:
|
|
270
|
+
"""Clear the baseline only if it names the requested session."""
|
|
271
|
+
|
|
272
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
273
|
+
try:
|
|
274
|
+
payload = clear_session_baseline(
|
|
275
|
+
session_id,
|
|
276
|
+
service_url=resolved_service_url,
|
|
277
|
+
)
|
|
278
|
+
except ValueError as exc:
|
|
279
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
280
|
+
except ServiceUnavailableError as exc:
|
|
281
|
+
_fail(str(exc))
|
|
282
|
+
except ServiceClientError as exc:
|
|
283
|
+
_fail(str(exc))
|
|
284
|
+
typer.echo(format_baseline_mutation(payload, action="clear"))
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
@app.command("logs")
|
|
288
|
+
def logs_command(
|
|
289
|
+
session_id: Annotated[
|
|
290
|
+
str | None,
|
|
291
|
+
typer.Option("--session", help="Exact native debug-session ID."),
|
|
292
|
+
] = None,
|
|
293
|
+
last: Annotated[
|
|
294
|
+
int,
|
|
295
|
+
typer.Option("--last", min=1, max=1000, help="Newest complete lines to return."),
|
|
296
|
+
] = 300,
|
|
297
|
+
service_url: Annotated[
|
|
298
|
+
str | None,
|
|
299
|
+
typer.Option("--service-url", help="Base URL for the local Device Core Service."),
|
|
300
|
+
] = None,
|
|
301
|
+
) -> None:
|
|
302
|
+
"""Show recent UART logs from an active or terminal native session."""
|
|
303
|
+
|
|
304
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
305
|
+
try:
|
|
306
|
+
payload = fetch_recent_logs(
|
|
307
|
+
session_id=session_id,
|
|
308
|
+
lines=last,
|
|
309
|
+
service_url=resolved_service_url,
|
|
310
|
+
)
|
|
311
|
+
except ValueError as exc:
|
|
312
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
313
|
+
except ServiceUnavailableError as exc:
|
|
314
|
+
_fail(str(exc))
|
|
315
|
+
except ServiceClientError as exc:
|
|
316
|
+
_fail(str(exc))
|
|
317
|
+
typer.echo(format_recent_logs(payload))
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
@app.command("wait")
|
|
321
|
+
def wait_command(
|
|
322
|
+
pattern: Annotated[str, typer.Argument(help="Case-sensitive literal pattern.")],
|
|
323
|
+
timeout_s: Annotated[
|
|
324
|
+
float,
|
|
325
|
+
typer.Option(
|
|
326
|
+
"--timeout",
|
|
327
|
+
callback=_validate_positive_seconds,
|
|
328
|
+
help="Maximum wait in seconds.",
|
|
329
|
+
),
|
|
330
|
+
],
|
|
331
|
+
service_url: Annotated[
|
|
332
|
+
str | None,
|
|
333
|
+
typer.Option("--service-url", help="Base URL for the local Device Core Service."),
|
|
334
|
+
] = None,
|
|
335
|
+
) -> None:
|
|
336
|
+
"""Wait for a literal in new complete UART lines."""
|
|
337
|
+
|
|
338
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
339
|
+
try:
|
|
340
|
+
payload = wait_for_pattern(
|
|
341
|
+
pattern=pattern,
|
|
342
|
+
timeout_s=timeout_s,
|
|
343
|
+
service_url=resolved_service_url,
|
|
344
|
+
)
|
|
345
|
+
except ValueError as exc:
|
|
346
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
347
|
+
except ServiceUnavailableError as exc:
|
|
348
|
+
_fail(str(exc))
|
|
349
|
+
except ServiceClientError as exc:
|
|
350
|
+
_fail(str(exc))
|
|
351
|
+
typer.echo(format_wait_pattern(payload))
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
@app.command("send")
|
|
355
|
+
def send_command(
|
|
356
|
+
cmd: Annotated[str, typer.Argument(help="UTF-8 text command to send.")],
|
|
357
|
+
no_newline: Annotated[
|
|
358
|
+
bool,
|
|
359
|
+
typer.Option("--no-newline", help="Do not append the default LF terminator."),
|
|
360
|
+
] = False,
|
|
361
|
+
force: Annotated[
|
|
362
|
+
bool,
|
|
363
|
+
typer.Option("--force", help="Permit a visibly recorded send during capture."),
|
|
364
|
+
] = False,
|
|
365
|
+
service_url: Annotated[
|
|
366
|
+
str | None,
|
|
367
|
+
typer.Option("--service-url", help="Base URL for the local Device Core Service."),
|
|
368
|
+
] = None,
|
|
369
|
+
) -> None:
|
|
370
|
+
"""Send one bounded text command to the DUT UART."""
|
|
371
|
+
|
|
372
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
373
|
+
try:
|
|
374
|
+
payload = send_uart_command(
|
|
375
|
+
cmd,
|
|
376
|
+
append_newline=not no_newline,
|
|
377
|
+
force=force,
|
|
378
|
+
service_url=resolved_service_url,
|
|
379
|
+
)
|
|
380
|
+
except ValueError as exc:
|
|
381
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
382
|
+
except ServiceUnavailableError as exc:
|
|
383
|
+
_fail(str(exc))
|
|
384
|
+
except ServiceClientError as exc:
|
|
385
|
+
_fail(str(exc))
|
|
386
|
+
typer.echo(format_uart_send(payload))
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
@app.command()
|
|
390
|
+
def capture(
|
|
391
|
+
seconds: Annotated[
|
|
392
|
+
float,
|
|
393
|
+
typer.Option(
|
|
394
|
+
"--seconds",
|
|
395
|
+
callback=_validate_positive_seconds,
|
|
396
|
+
help="Capture duration in seconds.",
|
|
397
|
+
),
|
|
398
|
+
],
|
|
399
|
+
service_url: Annotated[
|
|
400
|
+
str | None,
|
|
401
|
+
typer.Option(
|
|
402
|
+
"--service-url",
|
|
403
|
+
help="Base URL for the local Device Core Service.",
|
|
404
|
+
),
|
|
405
|
+
] = None,
|
|
406
|
+
) -> None:
|
|
407
|
+
"""Capture DUT UART evidence into a debug session."""
|
|
408
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
409
|
+
try:
|
|
410
|
+
payload = capture_uart(
|
|
411
|
+
duration_s=seconds,
|
|
412
|
+
service_url=resolved_service_url,
|
|
413
|
+
)
|
|
414
|
+
except ServiceUnavailableError as exc:
|
|
415
|
+
_fail(str(exc))
|
|
416
|
+
except ServiceClientError as exc:
|
|
417
|
+
_fail(str(exc))
|
|
418
|
+
|
|
419
|
+
typer.echo(format_capture_result(payload))
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
@app.command("boot-test")
|
|
423
|
+
def boot_test(
|
|
424
|
+
seconds: Annotated[
|
|
425
|
+
float,
|
|
426
|
+
typer.Option(
|
|
427
|
+
"--seconds",
|
|
428
|
+
callback=_validate_positive_seconds,
|
|
429
|
+
help="Boot capture duration in seconds.",
|
|
430
|
+
),
|
|
431
|
+
],
|
|
432
|
+
service_url: Annotated[
|
|
433
|
+
str | None,
|
|
434
|
+
typer.Option(
|
|
435
|
+
"--service-url",
|
|
436
|
+
help="Base URL for the local Device Core Service.",
|
|
437
|
+
),
|
|
438
|
+
] = None,
|
|
439
|
+
) -> None:
|
|
440
|
+
"""Reset the DUT and capture boot evidence into a debug session."""
|
|
441
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
442
|
+
try:
|
|
443
|
+
payload = run_boot_test(
|
|
444
|
+
duration_s=seconds,
|
|
445
|
+
service_url=resolved_service_url,
|
|
446
|
+
)
|
|
447
|
+
except ServiceUnavailableError as exc:
|
|
448
|
+
_fail(str(exc))
|
|
449
|
+
except ServiceClientError as exc:
|
|
450
|
+
_fail(str(exc))
|
|
451
|
+
|
|
452
|
+
typer.echo(format_boot_test_result(payload))
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
@gpio_app.command("mode")
|
|
456
|
+
def gpio_mode(
|
|
457
|
+
channel: Annotated[
|
|
458
|
+
str,
|
|
459
|
+
typer.Argument(help="Control channel to configure, for example CTRL0."),
|
|
460
|
+
],
|
|
461
|
+
role: Annotated[
|
|
462
|
+
str,
|
|
463
|
+
typer.Argument(help="User-facing role name, for example reset or power_enable."),
|
|
464
|
+
],
|
|
465
|
+
dut_signal: Annotated[
|
|
466
|
+
str,
|
|
467
|
+
typer.Argument(help="DUT signal connected to the channel, for example RESET_N."),
|
|
468
|
+
],
|
|
469
|
+
mode: Annotated[
|
|
470
|
+
str,
|
|
471
|
+
typer.Option("--mode", help="GPIO drive mode: open_drain or push_pull."),
|
|
472
|
+
],
|
|
473
|
+
active_level: Annotated[
|
|
474
|
+
str,
|
|
475
|
+
typer.Option("--active-level", help="Asserted signal level: low or high."),
|
|
476
|
+
],
|
|
477
|
+
idle_level: Annotated[
|
|
478
|
+
str | None,
|
|
479
|
+
typer.Option("--idle-level", help="Optional idle signal level: low or high."),
|
|
480
|
+
] = None,
|
|
481
|
+
service_url: Annotated[
|
|
482
|
+
str | None,
|
|
483
|
+
typer.Option(
|
|
484
|
+
"--service-url",
|
|
485
|
+
help="Base URL for the local Device Core Service.",
|
|
486
|
+
),
|
|
487
|
+
] = None,
|
|
488
|
+
) -> None:
|
|
489
|
+
"""Configure a DUT control GPIO channel."""
|
|
490
|
+
try:
|
|
491
|
+
request = validate_gpio_configuration(
|
|
492
|
+
channel=channel,
|
|
493
|
+
role=role,
|
|
494
|
+
dut_signal=dut_signal,
|
|
495
|
+
mode=mode,
|
|
496
|
+
active_level=active_level,
|
|
497
|
+
idle_level=idle_level,
|
|
498
|
+
)
|
|
499
|
+
except ValueError as exc:
|
|
500
|
+
raise typer.BadParameter(str(exc)) from exc
|
|
501
|
+
|
|
502
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
503
|
+
try:
|
|
504
|
+
payload = configure_gpio_mode(
|
|
505
|
+
channel=request.channel,
|
|
506
|
+
role=request.role,
|
|
507
|
+
dut_signal=request.dut_signal,
|
|
508
|
+
mode=request.mode,
|
|
509
|
+
active_level=request.active_level,
|
|
510
|
+
idle_level=request.idle_level,
|
|
511
|
+
service_url=resolved_service_url,
|
|
512
|
+
)
|
|
513
|
+
except ServiceUnavailableError as exc:
|
|
514
|
+
_fail(str(exc))
|
|
515
|
+
except ServiceClientError as exc:
|
|
516
|
+
_fail(str(exc))
|
|
517
|
+
|
|
518
|
+
typer.echo(format_gpio_mode_result(payload))
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
@dut_app.command("reset")
|
|
522
|
+
def dut_reset(
|
|
523
|
+
pulse_ms: Annotated[
|
|
524
|
+
int,
|
|
525
|
+
typer.Option("--pulse-ms", min=1, max=10000, help="Reset pulse width in milliseconds."),
|
|
526
|
+
] = 100,
|
|
527
|
+
service_url: Annotated[
|
|
528
|
+
str | None,
|
|
529
|
+
typer.Option(
|
|
530
|
+
"--service-url",
|
|
531
|
+
help="Base URL for the local Device Core Service.",
|
|
532
|
+
),
|
|
533
|
+
] = None,
|
|
534
|
+
) -> None:
|
|
535
|
+
"""Pulse the DUT reset control role."""
|
|
536
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
537
|
+
try:
|
|
538
|
+
payload = reset_dut(pulse_ms=pulse_ms, service_url=resolved_service_url)
|
|
539
|
+
except ServiceUnavailableError as exc:
|
|
540
|
+
_fail(str(exc))
|
|
541
|
+
except ServiceClientError as exc:
|
|
542
|
+
_fail(str(exc))
|
|
543
|
+
|
|
544
|
+
typer.echo(format_reset_result(payload))
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
@dut_app.command("boot-mode")
|
|
548
|
+
def dut_boot_mode(
|
|
549
|
+
mode: Annotated[
|
|
550
|
+
str,
|
|
551
|
+
typer.Argument(help="Boot mode to apply: normal or bootloader."),
|
|
552
|
+
],
|
|
553
|
+
service_url: Annotated[
|
|
554
|
+
str | None,
|
|
555
|
+
typer.Option(
|
|
556
|
+
"--service-url",
|
|
557
|
+
help="Base URL for the local Device Core Service.",
|
|
558
|
+
),
|
|
559
|
+
] = None,
|
|
560
|
+
) -> None:
|
|
561
|
+
"""Set the DUT boot/control role."""
|
|
562
|
+
resolved_service_url = _resolve_service_url(service_url)
|
|
563
|
+
try:
|
|
564
|
+
payload = set_boot_mode(mode=mode, service_url=resolved_service_url)
|
|
565
|
+
except ServiceUnavailableError as exc:
|
|
566
|
+
_fail(str(exc))
|
|
567
|
+
except ServiceClientError as exc:
|
|
568
|
+
_fail(str(exc))
|
|
569
|
+
|
|
570
|
+
typer.echo(format_boot_mode_result(payload))
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
@app.command()
|
|
574
|
+
def mcp(
|
|
575
|
+
service_url: Annotated[
|
|
576
|
+
str | None,
|
|
577
|
+
typer.Option(
|
|
578
|
+
"--service-url",
|
|
579
|
+
envvar="DUTCHMATE_SERVICE_URL",
|
|
580
|
+
help="Base URL for the local Device Core Service.",
|
|
581
|
+
),
|
|
582
|
+
] = None,
|
|
583
|
+
log_level: Annotated[
|
|
584
|
+
McpLogLevel,
|
|
585
|
+
typer.Option(
|
|
586
|
+
"--log-level",
|
|
587
|
+
case_sensitive=False,
|
|
588
|
+
help="MCP process log level.",
|
|
589
|
+
),
|
|
590
|
+
] = McpLogLevel.INFO,
|
|
591
|
+
) -> None:
|
|
592
|
+
"""Run the MCP server over stdio."""
|
|
593
|
+
|
|
594
|
+
try:
|
|
595
|
+
launch_mcp(service_url=service_url, log_level=log_level)
|
|
596
|
+
except McpLaunchError as exc:
|
|
597
|
+
_fail(str(exc))
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
def _fail(message: str) -> NoReturn:
|
|
601
|
+
typer.echo(f"Error: {message}", err=True)
|
|
602
|
+
raise typer.Exit(code=1)
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
def _load_config_or_fail() -> CliConfig:
|
|
606
|
+
try:
|
|
607
|
+
return load_cli_config()
|
|
608
|
+
except CliConfigError as exc:
|
|
609
|
+
_fail(str(exc))
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
def _resolve_service_url(service_url: str | None) -> str:
|
|
613
|
+
if service_url is not None:
|
|
614
|
+
return service_url
|
|
615
|
+
return _load_config_or_fail().service_url
|
dutchmate_cli/mcp.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""Process launcher for the separately packaged MCP stdio adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import NoReturn
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class McpLogLevel(str, Enum):
|
|
13
|
+
"""Log levels accepted by the MCP server entrypoint."""
|
|
14
|
+
|
|
15
|
+
DEBUG = "debug"
|
|
16
|
+
INFO = "info"
|
|
17
|
+
WARNING = "warning"
|
|
18
|
+
ERROR = "error"
|
|
19
|
+
CRITICAL = "critical"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class McpLaunchError(RuntimeError):
|
|
23
|
+
"""Raised when the MCP server process cannot be launched."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def launch_mcp(*, service_url: str | None, log_level: McpLogLevel) -> NoReturn:
|
|
27
|
+
"""Replace the CLI process with the MCP stdio server process."""
|
|
28
|
+
|
|
29
|
+
sibling_executable = _sibling_mcp_executable()
|
|
30
|
+
executable = sibling_executable or "dutchmate-mcp"
|
|
31
|
+
command = [executable]
|
|
32
|
+
if service_url is not None:
|
|
33
|
+
command.extend(["--service-url", service_url])
|
|
34
|
+
command.extend(["--log-level", log_level.value])
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
if sibling_executable is not None:
|
|
38
|
+
os.execv(executable, command)
|
|
39
|
+
os.execvp(executable, command)
|
|
40
|
+
except FileNotFoundError as exc:
|
|
41
|
+
raise McpLaunchError(
|
|
42
|
+
"dutchmate-mcp executable is not installed; "
|
|
43
|
+
"install the DUTchMate MCP server package"
|
|
44
|
+
) from exc
|
|
45
|
+
except OSError as exc:
|
|
46
|
+
raise McpLaunchError(f"could not launch dutchmate-mcp: {exc}") from exc
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _sibling_mcp_executable() -> str | None:
|
|
50
|
+
candidate = Path(sys.executable).with_name("dutchmate-mcp")
|
|
51
|
+
return str(candidate) if candidate.is_file() else None
|
dutchmate_cli/send.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""CLI formatting for UART-send outcomes."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def format_uart_send(payload: Mapping[str, object]) -> str:
|
|
7
|
+
"""Format a complete standalone or forced in-session UART send."""
|
|
8
|
+
|
|
9
|
+
lines = [
|
|
10
|
+
"UART command sent",
|
|
11
|
+
f"Performed: {_display(payload.get('performed_at'))}",
|
|
12
|
+
]
|
|
13
|
+
device_timestamp = payload.get("device_timestamp_us")
|
|
14
|
+
if device_timestamp is not None:
|
|
15
|
+
lines.append(f"Device timestamp: {device_timestamp} us")
|
|
16
|
+
attempt_id = payload.get("attempt_id")
|
|
17
|
+
if attempt_id is not None:
|
|
18
|
+
lines.extend(
|
|
19
|
+
[
|
|
20
|
+
f"Attempt: {_display(attempt_id)}",
|
|
21
|
+
(
|
|
22
|
+
"Perturbation logged: yes"
|
|
23
|
+
if payload.get("perturbation_logged") is True
|
|
24
|
+
else "Perturbation logged: no"
|
|
25
|
+
),
|
|
26
|
+
]
|
|
27
|
+
)
|
|
28
|
+
return "\n".join(lines)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _display(value: object) -> str:
|
|
32
|
+
return "none" if value is None or value == "" else str(value)
|