dutchmate-cli 0.1.0__tar.gz → 0.2.1__tar.gz
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-0.2.1/LICENSE +18 -0
- dutchmate_cli-0.2.1/PKG-INFO +35 -0
- dutchmate_cli-0.2.1/pyproject.toml +56 -0
- dutchmate_cli-0.2.1/pyproject.toml.orig +45 -0
- dutchmate_cli-0.2.1/src/dutchmate_cli/capture.py +9 -0
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/client.py +159 -31
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/config.py +5 -9
- dutchmate_cli-0.2.1/src/dutchmate_cli/console.py +90 -0
- dutchmate_cli-0.2.1/src/dutchmate_cli/follow.py +100 -0
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/lifecycle.py +33 -9
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/main.py +172 -59
- dutchmate_cli-0.2.1/src/dutchmate_cli/monitor.py +42 -0
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/send.py +9 -13
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/sessions.py +11 -2
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/status.py +90 -5
- dutchmate_cli-0.2.1/src/dutchmate_cli/wait.py +9 -0
- dutchmate_cli-0.1.0/LICENSE +0 -73
- dutchmate_cli-0.1.0/PKG-INFO +0 -15
- dutchmate_cli-0.1.0/pyproject.toml +0 -25
- dutchmate_cli-0.1.0/pyproject.toml.orig +0 -23
- dutchmate_cli-0.1.0/src/dutchmate_cli/capture.py +0 -94
- dutchmate_cli-0.1.0/src/dutchmate_cli/wait.py +0 -41
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/__init__.py +0 -0
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/baseline.py +0 -0
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/devices.py +0 -0
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/dut.py +0 -0
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/gpio.py +0 -0
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/logs.py +0 -0
- {dutchmate_cli-0.1.0 → dutchmate_cli-0.2.1}/src/dutchmate_cli/mcp.py +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nahit Pawar and DUTchMate contributors.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dutchmate-cli
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Command-line client component for DUTchMate Device Core.
|
|
5
|
+
Keywords: embedded,firmware,debugging,uart,cli
|
|
6
|
+
Author: Nahit Pawar
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
19
|
+
Classifier: Topic :: Software Development :: Embedded Systems
|
|
20
|
+
Requires-Dist: dutchmate-core==0.2.1
|
|
21
|
+
Requires-Dist: httpx>=0.27
|
|
22
|
+
Requires-Dist: tomli>=2.0 ; python_full_version < '3.11'
|
|
23
|
+
Requires-Dist: typer>=0.12
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Project-URL: Documentation, https://github.com/leonahi/DUTchMate/tree/main/docs
|
|
26
|
+
Project-URL: Repository, https://github.com/leonahi/DUTchMate
|
|
27
|
+
Project-URL: Issues, https://github.com/leonahi/DUTchMate/issues
|
|
28
|
+
Project-URL: Changelog, https://github.com/leonahi/DUTchMate/releases
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
`dutchmate-cli` implements the terminal workflows for starting Device Core,
|
|
32
|
+
inspecting device status, and reading UART evidence.
|
|
33
|
+
|
|
34
|
+
Install [`dutchmate`](https://pypi.org/project/dutchmate/) for the `dutchmate`
|
|
35
|
+
and `dm` commands and their matching service and MCP components.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "dutchmate-cli"
|
|
3
|
+
version = "0.2.1"
|
|
4
|
+
description = "Command-line client component for DUTchMate Device Core."
|
|
5
|
+
requires-python = ">=3.10"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
keywords = [
|
|
9
|
+
"embedded",
|
|
10
|
+
"firmware",
|
|
11
|
+
"debugging",
|
|
12
|
+
"uart",
|
|
13
|
+
"cli",
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Operating System :: MacOS :: MacOS X",
|
|
18
|
+
"Operating System :: POSIX :: Linux",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python :: 3.14",
|
|
25
|
+
"Topic :: Software Development :: Debuggers",
|
|
26
|
+
"Topic :: Software Development :: Embedded Systems",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"dutchmate-core==0.2.1",
|
|
30
|
+
"httpx>=0.27",
|
|
31
|
+
"tomli>=2.0; python_version < '3.11'",
|
|
32
|
+
"typer>=0.12",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.readme]
|
|
36
|
+
content-type = "text/markdown"
|
|
37
|
+
text = """
|
|
38
|
+
`dutchmate-cli` implements the terminal workflows for starting Device Core,
|
|
39
|
+
inspecting device status, and reading UART evidence.
|
|
40
|
+
|
|
41
|
+
Install [`dutchmate`](https://pypi.org/project/dutchmate/) for the `dutchmate`
|
|
42
|
+
and `dm` commands and their matching service and MCP components.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
[[project.authors]]
|
|
46
|
+
name = "Nahit Pawar"
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Documentation = "https://github.com/leonahi/DUTchMate/tree/main/docs"
|
|
50
|
+
Repository = "https://github.com/leonahi/DUTchMate"
|
|
51
|
+
Issues = "https://github.com/leonahi/DUTchMate/issues"
|
|
52
|
+
Changelog = "https://github.com/leonahi/DUTchMate/releases"
|
|
53
|
+
|
|
54
|
+
[build-system]
|
|
55
|
+
requires = ["uv_build>=0.11.26,<0.12"]
|
|
56
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "dutchmate-cli"
|
|
3
|
+
version = "0.2.1"
|
|
4
|
+
description = "Command-line client component for DUTchMate Device Core."
|
|
5
|
+
readme = { content-type = "text/markdown", text = """
|
|
6
|
+
`dutchmate-cli` implements the terminal workflows for starting Device Core,
|
|
7
|
+
inspecting device status, and reading UART evidence.
|
|
8
|
+
|
|
9
|
+
Install [`dutchmate`](https://pypi.org/project/dutchmate/) for the `dutchmate`
|
|
10
|
+
and `dm` commands and their matching service and MCP components.
|
|
11
|
+
""" }
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
authors = [{ name = "Nahit Pawar" }]
|
|
16
|
+
keywords = ["embedded", "firmware", "debugging", "uart", "cli"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: MacOS :: MacOS X",
|
|
20
|
+
"Operating System :: POSIX :: Linux",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
|
+
"Topic :: Software Development :: Debuggers",
|
|
28
|
+
"Topic :: Software Development :: Embedded Systems",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"dutchmate-core==0.2.1",
|
|
32
|
+
"httpx>=0.27",
|
|
33
|
+
"tomli>=2.0; python_version < '3.11'",
|
|
34
|
+
"typer>=0.12",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Documentation = "https://github.com/leonahi/DUTchMate/tree/main/docs"
|
|
39
|
+
Repository = "https://github.com/leonahi/DUTchMate"
|
|
40
|
+
Issues = "https://github.com/leonahi/DUTchMate/issues"
|
|
41
|
+
Changelog = "https://github.com/leonahi/DUTchMate/releases"
|
|
42
|
+
|
|
43
|
+
[build-system]
|
|
44
|
+
requires = ["uv_build>=0.11.26,<0.12"]
|
|
45
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""CLI formatting for the thin capture Monitor alias."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
|
|
5
|
+
from dutchmate_cli.monitor import format_monitor_result
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def format_capture_result(payload: Mapping[str, object]) -> str:
|
|
9
|
+
return format_monitor_result(payload).replace("Monitor", "Capture", 1)
|
|
@@ -8,8 +8,11 @@ from urllib.parse import quote
|
|
|
8
8
|
|
|
9
9
|
import httpx
|
|
10
10
|
|
|
11
|
+
from dutchmate_core.evidence.tail import validate_evidence_query
|
|
12
|
+
from dutchmate_core.operations import MonitorCondition
|
|
13
|
+
from dutchmate_core.operations.monitor import validate_monitor_request
|
|
11
14
|
from dutchmate_core.validation import (
|
|
12
|
-
|
|
15
|
+
prepare_uart_tx_payload,
|
|
13
16
|
validate_capture_duration,
|
|
14
17
|
validate_gpio_configuration,
|
|
15
18
|
validate_session_id,
|
|
@@ -54,6 +57,46 @@ def fetch_status(
|
|
|
54
57
|
return _response_payload(response, description="status payload")
|
|
55
58
|
|
|
56
59
|
|
|
60
|
+
def change_connection(
|
|
61
|
+
action: str,
|
|
62
|
+
*,
|
|
63
|
+
service_url: str = DEFAULT_SERVICE_URL,
|
|
64
|
+
transport: httpx.BaseTransport | None = None,
|
|
65
|
+
) -> dict[str, object]:
|
|
66
|
+
"""Request atomic ownership transfer; no local serial access."""
|
|
67
|
+
if action not in {"release", "reacquire"}:
|
|
68
|
+
raise ValueError("Unknown connection lifecycle action")
|
|
69
|
+
response = _request_service(
|
|
70
|
+
method="POST",
|
|
71
|
+
path=f"/connection/{action}",
|
|
72
|
+
service_url=service_url,
|
|
73
|
+
transport=transport,
|
|
74
|
+
timeout_s=65.0,
|
|
75
|
+
)
|
|
76
|
+
return _response_payload(response, description="connection boundary")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def fetch_evidence(
|
|
80
|
+
*,
|
|
81
|
+
cursor: str | None = None,
|
|
82
|
+
limit: int = 100,
|
|
83
|
+
wait_s: float = 1.0,
|
|
84
|
+
service_url: str = DEFAULT_SERVICE_URL,
|
|
85
|
+
transport: httpx.BaseTransport | None = None,
|
|
86
|
+
) -> dict[str, object]:
|
|
87
|
+
"""Page the authoritative durable tail; the service owns the opaque cursor."""
|
|
88
|
+
|
|
89
|
+
validate_evidence_query(cursor=cursor, limit=limit, wait_s=wait_s)
|
|
90
|
+
params: dict[str, str | int | float] = {"limit": limit, "wait_s": wait_s}
|
|
91
|
+
if cursor is not None:
|
|
92
|
+
params["cursor"] = cursor
|
|
93
|
+
response = _request_service(
|
|
94
|
+
method="GET", path="/dut/evidence", service_url=service_url,
|
|
95
|
+
transport=transport, params=params, timeout_s=wait_s + DEFAULT_TIMEOUT_SECONDS,
|
|
96
|
+
)
|
|
97
|
+
return _response_payload(response, description="evidence page")
|
|
98
|
+
|
|
99
|
+
|
|
57
100
|
def list_debug_sessions(
|
|
58
101
|
*,
|
|
59
102
|
limit: int = 50,
|
|
@@ -183,33 +226,126 @@ def wait_for_pattern(
|
|
|
183
226
|
return _response_payload(response, description="wait-pattern response")
|
|
184
227
|
|
|
185
228
|
|
|
229
|
+
def _bounded_request(
|
|
230
|
+
*,
|
|
231
|
+
path: str,
|
|
232
|
+
payload: dict[str, object],
|
|
233
|
+
duration_s: object | None,
|
|
234
|
+
until: object | None,
|
|
235
|
+
timeout_s: object | None,
|
|
236
|
+
service_url: str,
|
|
237
|
+
transport: httpx.BaseTransport | None,
|
|
238
|
+
) -> dict[str, object]:
|
|
239
|
+
if until is not None and not isinstance(until, str):
|
|
240
|
+
raise ValueError("Completion condition must be a string")
|
|
241
|
+
request = validate_monitor_request(
|
|
242
|
+
duration_s=duration_s,
|
|
243
|
+
conditions=(MonitorCondition(pattern=until),) if isinstance(until, str) else None,
|
|
244
|
+
timeout_s=timeout_s,
|
|
245
|
+
)
|
|
246
|
+
if request.mode == "duration":
|
|
247
|
+
payload["duration_s"] = request.duration_s
|
|
248
|
+
else:
|
|
249
|
+
payload.update(
|
|
250
|
+
{
|
|
251
|
+
"conditions": [{"pattern": item.pattern} for item in request.conditions],
|
|
252
|
+
"timeout_s": request.timeout_s,
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
bound_s = request.duration_s or request.timeout_s
|
|
256
|
+
assert bound_s is not None
|
|
257
|
+
response = _request_service(
|
|
258
|
+
method="POST",
|
|
259
|
+
path=path,
|
|
260
|
+
service_url=service_url,
|
|
261
|
+
transport=transport,
|
|
262
|
+
json=payload,
|
|
263
|
+
timeout_s=max(DEFAULT_TIMEOUT_SECONDS, bound_s + CAPTURE_TIMEOUT_GRACE_SECONDS),
|
|
264
|
+
)
|
|
265
|
+
return _response_payload(response, description="bounded operation response")
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def monitor_uart(
|
|
269
|
+
*,
|
|
270
|
+
duration_s: object | None = None,
|
|
271
|
+
until: object | None = None,
|
|
272
|
+
timeout_s: object | None = None,
|
|
273
|
+
service_url: str = DEFAULT_SERVICE_URL,
|
|
274
|
+
transport: httpx.BaseTransport | None = None,
|
|
275
|
+
) -> dict[str, object]:
|
|
276
|
+
"""Run one bounded Monitor through the service."""
|
|
277
|
+
|
|
278
|
+
return _bounded_request(
|
|
279
|
+
path="/dut/monitor",
|
|
280
|
+
payload={},
|
|
281
|
+
duration_s=duration_s,
|
|
282
|
+
until=until,
|
|
283
|
+
timeout_s=timeout_s,
|
|
284
|
+
service_url=service_url,
|
|
285
|
+
transport=transport,
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _tx_request(
|
|
290
|
+
*,
|
|
291
|
+
data_b64: object = None,
|
|
292
|
+
text: object = None,
|
|
293
|
+
line_ending: object = None,
|
|
294
|
+
) -> dict[str, object]:
|
|
295
|
+
prepare_uart_tx_payload(data_b64=data_b64, text=text, line_ending=line_ending)
|
|
296
|
+
return (
|
|
297
|
+
{"data_b64": data_b64}
|
|
298
|
+
if data_b64 is not None
|
|
299
|
+
else {"text": text, "line_ending": line_ending}
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
|
|
186
303
|
def send_uart_command(
|
|
187
|
-
cmd: str,
|
|
188
304
|
*,
|
|
189
|
-
|
|
190
|
-
|
|
305
|
+
data_b64: object = None,
|
|
306
|
+
text: object = None,
|
|
307
|
+
line_ending: object = None,
|
|
191
308
|
service_url: str = DEFAULT_SERVICE_URL,
|
|
192
309
|
transport: httpx.BaseTransport | None = None,
|
|
193
310
|
) -> dict[str, object]:
|
|
194
|
-
"""Send one
|
|
311
|
+
"""Send one exact, audited payload through the service."""
|
|
195
312
|
|
|
196
|
-
|
|
197
|
-
if not isinstance(force, bool):
|
|
198
|
-
raise ValueError("UART send force must be a boolean")
|
|
313
|
+
payload = _tx_request(data_b64=data_b64, text=text, line_ending=line_ending)
|
|
199
314
|
response = _request_service(
|
|
200
315
|
method="POST",
|
|
201
316
|
path="/dut/uart/send",
|
|
202
317
|
service_url=service_url,
|
|
203
318
|
transport=transport,
|
|
204
|
-
json=
|
|
205
|
-
"cmd": cmd,
|
|
206
|
-
"append_newline": append_newline,
|
|
207
|
-
"force": force,
|
|
208
|
-
},
|
|
319
|
+
json=payload,
|
|
209
320
|
)
|
|
210
321
|
return _response_payload(response, description="UART-send response")
|
|
211
322
|
|
|
212
323
|
|
|
324
|
+
def interact_uart(
|
|
325
|
+
*,
|
|
326
|
+
data_b64: object = None,
|
|
327
|
+
text: object = None,
|
|
328
|
+
line_ending: object = None,
|
|
329
|
+
duration_s: object | None = None,
|
|
330
|
+
until: object | None = None,
|
|
331
|
+
timeout_s: object | None = None,
|
|
332
|
+
service_url: str = DEFAULT_SERVICE_URL,
|
|
333
|
+
transport: httpx.BaseTransport | None = None,
|
|
334
|
+
) -> dict[str, object]:
|
|
335
|
+
"""Send once and observe under the service's Interact lease."""
|
|
336
|
+
|
|
337
|
+
payload = _tx_request(data_b64=data_b64, text=text, line_ending=line_ending)
|
|
338
|
+
return _bounded_request(
|
|
339
|
+
path="/dut/interact",
|
|
340
|
+
payload=payload,
|
|
341
|
+
duration_s=duration_s,
|
|
342
|
+
until=until,
|
|
343
|
+
timeout_s=timeout_s,
|
|
344
|
+
service_url=service_url,
|
|
345
|
+
transport=transport,
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
|
|
213
349
|
def configure_gpio_mode(
|
|
214
350
|
*,
|
|
215
351
|
channel: str,
|
|
@@ -308,23 +444,6 @@ def capture_uart(
|
|
|
308
444
|
)
|
|
309
445
|
|
|
310
446
|
|
|
311
|
-
def run_boot_test(
|
|
312
|
-
*,
|
|
313
|
-
duration_s: float,
|
|
314
|
-
service_url: str = DEFAULT_SERVICE_URL,
|
|
315
|
-
transport: httpx.BaseTransport | None = None,
|
|
316
|
-
) -> dict[str, object]:
|
|
317
|
-
"""Reset the DUT and capture boot evidence through the Device Core Service."""
|
|
318
|
-
|
|
319
|
-
return _run_timed_capture_request(
|
|
320
|
-
path="/dut/boot-test",
|
|
321
|
-
description="boot-test",
|
|
322
|
-
duration_s=duration_s,
|
|
323
|
-
service_url=service_url,
|
|
324
|
-
transport=transport,
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
|
|
328
447
|
def _run_timed_capture_request(
|
|
329
448
|
*,
|
|
330
449
|
path: str,
|
|
@@ -359,7 +478,7 @@ def _request_service(
|
|
|
359
478
|
service_url: str,
|
|
360
479
|
transport: httpx.BaseTransport | None = None,
|
|
361
480
|
json: Mapping[str, object] | None = None,
|
|
362
|
-
params: Mapping[str, str | int] | None = None,
|
|
481
|
+
params: Mapping[str, str | int | float] | None = None,
|
|
363
482
|
timeout_s: float = DEFAULT_TIMEOUT_SECONDS,
|
|
364
483
|
) -> httpx.Response:
|
|
365
484
|
try:
|
|
@@ -406,6 +525,15 @@ def _response_error_message(response: httpx.Response) -> str:
|
|
|
406
525
|
error = payload.get("error")
|
|
407
526
|
if isinstance(detail, str) and detail:
|
|
408
527
|
suffix = _uart_send_error_suffix(payload.get("context"))
|
|
528
|
+
context = payload.get("context")
|
|
529
|
+
reason = context.get("reason") if isinstance(context, Mapping) else None
|
|
530
|
+
if reason in (
|
|
531
|
+
"cleanup_unconfirmed",
|
|
532
|
+
"ambiguous_device",
|
|
533
|
+
"device_not_found",
|
|
534
|
+
"open_failed",
|
|
535
|
+
):
|
|
536
|
+
suffix += f" [{reason}]"
|
|
409
537
|
if isinstance(error, str) and error:
|
|
410
538
|
return f"{prefix} [{error}]: {detail}{suffix}"
|
|
411
539
|
return f"{prefix}: {detail}{suffix}"
|
|
@@ -8,11 +8,7 @@ from dataclasses import dataclass
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from typing import Any, Final, cast
|
|
10
10
|
|
|
11
|
-
from dutchmate_core.
|
|
12
|
-
BackendConfig,
|
|
13
|
-
BackendConfigError,
|
|
14
|
-
parse_backend_config,
|
|
15
|
-
)
|
|
11
|
+
from dutchmate_core.profile import DutProfileConfig, DutProfileError, parse_dut_profile_config
|
|
16
12
|
from dutchmate_core.validation import (
|
|
17
13
|
DEFAULT_SESSION_MAX_SIZE_MB,
|
|
18
14
|
validate_session_max_size_mb,
|
|
@@ -51,7 +47,7 @@ class CliConfig:
|
|
|
51
47
|
|
|
52
48
|
daemon: DaemonConfig = DaemonConfig()
|
|
53
49
|
sessions: SessionsConfig = SessionsConfig()
|
|
54
|
-
|
|
50
|
+
profile: DutProfileConfig = DutProfileConfig()
|
|
55
51
|
|
|
56
52
|
@property
|
|
57
53
|
def service_url(self) -> str:
|
|
@@ -78,10 +74,10 @@ def parse_cli_config(raw_config: Mapping[str, object]) -> CliConfig:
|
|
|
78
74
|
daemon = _parse_daemon_config(_optional_table(raw_config, "daemon"))
|
|
79
75
|
sessions = _parse_sessions_config(_optional_table(raw_config, "sessions"))
|
|
80
76
|
try:
|
|
81
|
-
|
|
82
|
-
except
|
|
77
|
+
profile = parse_dut_profile_config(raw_config)
|
|
78
|
+
except DutProfileError as exc:
|
|
83
79
|
raise CliConfigError(str(exc)) from exc
|
|
84
|
-
return CliConfig(daemon=daemon, sessions=sessions,
|
|
80
|
+
return CliConfig(daemon=daemon, sessions=sessions, profile=profile)
|
|
85
81
|
|
|
86
82
|
|
|
87
83
|
def _parse_daemon_config(raw_daemon: Mapping[str, object]) -> DaemonConfig:
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Line-oriented human console using only Device Core Service APIs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from collections.abc import Callable, Mapping
|
|
7
|
+
from threading import Event, Thread
|
|
8
|
+
from typing import TextIO
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
|
|
12
|
+
from dutchmate_cli.client import (
|
|
13
|
+
DEFAULT_SERVICE_URL,
|
|
14
|
+
ServiceClientError,
|
|
15
|
+
fetch_status,
|
|
16
|
+
send_uart_command,
|
|
17
|
+
)
|
|
18
|
+
from dutchmate_cli.follow import _EvidenceView, write_view
|
|
19
|
+
from dutchmate_core.validation import prepare_uart_tx_payload
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _resolve_ending(status: Mapping[str, object], requested: str) -> str:
|
|
23
|
+
if requested != "profile_default":
|
|
24
|
+
return requested
|
|
25
|
+
value = status.get("effective_profile")
|
|
26
|
+
for key in ("hardware", "uart", "default_line_ending"):
|
|
27
|
+
value = value.get(key) if isinstance(value, Mapping) else None
|
|
28
|
+
if not isinstance(value, str) or value not in {"none", "lf", "cr", "crlf"}:
|
|
29
|
+
raise ServiceClientError("Service status does not expose the profile default line ending")
|
|
30
|
+
return value
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def run_console(
|
|
34
|
+
*,
|
|
35
|
+
service_url: str = DEFAULT_SERVICE_URL,
|
|
36
|
+
line_ending: str = "profile_default",
|
|
37
|
+
input_stream: TextIO | None = None,
|
|
38
|
+
transport: httpx.BaseTransport | None = None,
|
|
39
|
+
emit: Callable[[str], None] = write_view,
|
|
40
|
+
) -> None:
|
|
41
|
+
"""Follow durable evidence while sending complete input lines through audited TX."""
|
|
42
|
+
|
|
43
|
+
prepare_uart_tx_payload(text="validate", line_ending=line_ending)
|
|
44
|
+
status = fetch_status(service_url=service_url, transport=transport)
|
|
45
|
+
capabilities = status.get("capabilities")
|
|
46
|
+
if not isinstance(capabilities, list) or "uart_send" not in capabilities:
|
|
47
|
+
raise ServiceClientError("Console requires effective uart_send [unsupported_capability]")
|
|
48
|
+
# Resolve the immutable service profile once; every request names the exact ending.
|
|
49
|
+
ending = _resolve_ending(status, line_ending)
|
|
50
|
+
view = _EvidenceView(service_url=service_url, cursor=None, transport=transport, emit=emit)
|
|
51
|
+
view.poll(wait_s=0)
|
|
52
|
+
stopped = Event()
|
|
53
|
+
failures: list[ServiceClientError] = []
|
|
54
|
+
|
|
55
|
+
def follow() -> None:
|
|
56
|
+
try:
|
|
57
|
+
view.run(stopped)
|
|
58
|
+
# Include the last completed send's evidence on EOF without another long poll.
|
|
59
|
+
view.poll(wait_s=0)
|
|
60
|
+
except ServiceClientError as exc:
|
|
61
|
+
failures.append(exc)
|
|
62
|
+
stopped.set()
|
|
63
|
+
emit(f"\n{exc}\n")
|
|
64
|
+
|
|
65
|
+
worker = Thread(target=follow, name="dutchmate-console-view")
|
|
66
|
+
worker.start()
|
|
67
|
+
try:
|
|
68
|
+
stream = input_stream if input_stream is not None else sys.stdin
|
|
69
|
+
while not stopped.is_set():
|
|
70
|
+
line = stream.readline()
|
|
71
|
+
if not line or stopped.is_set():
|
|
72
|
+
break
|
|
73
|
+
text = line.removesuffix("\n").removesuffix("\r")
|
|
74
|
+
try:
|
|
75
|
+
send_uart_command(
|
|
76
|
+
text=text,
|
|
77
|
+
line_ending=ending,
|
|
78
|
+
service_url=service_url,
|
|
79
|
+
transport=transport,
|
|
80
|
+
)
|
|
81
|
+
except (ServiceClientError, ValueError) as exc:
|
|
82
|
+
# Rejections (including operation_active) do not retry or end observation.
|
|
83
|
+
emit(f"\n{exc}\n")
|
|
84
|
+
except KeyboardInterrupt:
|
|
85
|
+
pass
|
|
86
|
+
finally:
|
|
87
|
+
stopped.set()
|
|
88
|
+
worker.join()
|
|
89
|
+
if failures:
|
|
90
|
+
raise failures[0]
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Human views of durable service evidence; never owns a physical reader."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from collections.abc import Callable, Mapping
|
|
7
|
+
from contextlib import suppress
|
|
8
|
+
from threading import Event
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
|
|
12
|
+
from dutchmate_cli.client import DEFAULT_SERVICE_URL, ServiceClientError, fetch_evidence
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def write_view(text: str) -> None:
|
|
16
|
+
sys.stdout.write(text)
|
|
17
|
+
sys.stdout.flush()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def format_evidence(record: Mapping[str, object]) -> str:
|
|
21
|
+
"""Display lossy RX text and bounded markers from the authoritative projection."""
|
|
22
|
+
|
|
23
|
+
if record.get("type") == "uart_rx":
|
|
24
|
+
text = record.get("display_text")
|
|
25
|
+
return (
|
|
26
|
+
"".join(c for c in text if c.isprintable() or c in "\n\r\t")
|
|
27
|
+
if isinstance(text, str)
|
|
28
|
+
else ""
|
|
29
|
+
)
|
|
30
|
+
fields = [str(record.get("type", "evidence"))]
|
|
31
|
+
for key in (
|
|
32
|
+
"session_id",
|
|
33
|
+
"evidence_seq",
|
|
34
|
+
"operation_type",
|
|
35
|
+
"outcome",
|
|
36
|
+
"status",
|
|
37
|
+
"accepted_bytes",
|
|
38
|
+
):
|
|
39
|
+
if key in record:
|
|
40
|
+
fields.append(f"{key}={record[key]}")
|
|
41
|
+
if record.get("type") == "uart_tx_attempt":
|
|
42
|
+
fields.append(f"text={str(record.get('display_text', ''))[:160]!r}")
|
|
43
|
+
marker = " ".join(fields)
|
|
44
|
+
return "\n[" + "".join(c for c in marker[:768] if c.isprintable()) + "]\n"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class _EvidenceView:
|
|
48
|
+
def __init__(
|
|
49
|
+
self,
|
|
50
|
+
*,
|
|
51
|
+
service_url: str,
|
|
52
|
+
cursor: str | None,
|
|
53
|
+
transport: httpx.BaseTransport | None,
|
|
54
|
+
emit: Callable[[str], None],
|
|
55
|
+
) -> None:
|
|
56
|
+
self.service_url = service_url
|
|
57
|
+
self.cursor = cursor
|
|
58
|
+
self.transport = transport
|
|
59
|
+
self.emit = emit
|
|
60
|
+
|
|
61
|
+
def poll(self, *, wait_s: float) -> bool:
|
|
62
|
+
page = fetch_evidence(
|
|
63
|
+
cursor=self.cursor,
|
|
64
|
+
wait_s=wait_s,
|
|
65
|
+
service_url=self.service_url,
|
|
66
|
+
transport=self.transport,
|
|
67
|
+
)
|
|
68
|
+
records = page.get("records")
|
|
69
|
+
next_cursor = page.get("next_cursor")
|
|
70
|
+
if not isinstance(records, list) or not isinstance(next_cursor, str) or not next_cursor:
|
|
71
|
+
raise ServiceClientError("Device Core Service returned an invalid evidence page")
|
|
72
|
+
for record in records:
|
|
73
|
+
if not isinstance(record, Mapping):
|
|
74
|
+
raise ServiceClientError("Device Core Service returned an invalid evidence record")
|
|
75
|
+
self.emit(format_evidence(record))
|
|
76
|
+
omitted = page.get("omitted_records")
|
|
77
|
+
if isinstance(omitted, int) and omitted > 0:
|
|
78
|
+
self.emit(f"\n[{omitted} whole records deferred by response cap; continuing cursor]\n")
|
|
79
|
+
# Advance only after rendering. Slow output is recovered by the next durable request.
|
|
80
|
+
self.cursor = next_cursor
|
|
81
|
+
return bool(records)
|
|
82
|
+
|
|
83
|
+
def run(self, stopped: Event) -> None:
|
|
84
|
+
while not stopped.is_set():
|
|
85
|
+
if not self.poll(wait_s=1.0):
|
|
86
|
+
stopped.wait(0.05)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def run_follow(
|
|
90
|
+
*,
|
|
91
|
+
service_url: str = DEFAULT_SERVICE_URL,
|
|
92
|
+
cursor: str | None = None,
|
|
93
|
+
transport: httpx.BaseTransport | None = None,
|
|
94
|
+
emit: Callable[[str], None] = write_view,
|
|
95
|
+
) -> None:
|
|
96
|
+
"""Attach at tail by default; Ctrl-C closes only this client view."""
|
|
97
|
+
|
|
98
|
+
view = _EvidenceView(service_url=service_url, cursor=cursor, transport=transport, emit=emit)
|
|
99
|
+
with suppress(KeyboardInterrupt):
|
|
100
|
+
view.run(Event())
|