margin-cli 0.1.2__tar.gz → 0.1.3__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.
- {margin_cli-0.1.2 → margin_cli-0.1.3}/.gitignore +3 -0
- {margin_cli-0.1.2 → margin_cli-0.1.3}/CHANGELOG.md +6 -0
- {margin_cli-0.1.2 → margin_cli-0.1.3}/PKG-INFO +1 -1
- {margin_cli-0.1.2 → margin_cli-0.1.3}/pyproject.toml +1 -1
- {margin_cli-0.1.2 → margin_cli-0.1.3}/src/margin_cli/__init__.py +1 -1
- {margin_cli-0.1.2 → margin_cli-0.1.3}/src/margin_cli/main.py +24 -2
- {margin_cli-0.1.2 → margin_cli-0.1.3}/tests/test_cli.py +76 -0
- {margin_cli-0.1.2 → margin_cli-0.1.3}/LICENSE +0 -0
- {margin_cli-0.1.2 → margin_cli-0.1.3}/README.md +0 -0
- {margin_cli-0.1.2 → margin_cli-0.1.3}/src/margin_cli/execution.py +0 -0
- {margin_cli-0.1.2 → margin_cli-0.1.3}/src/margin_cli/py.typed +0 -0
- {margin_cli-0.1.2 → margin_cli-0.1.3}/src/margin_cli/render.py +0 -0
|
@@ -4,6 +4,12 @@ All notable changes to this package are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.1.3] - 2026-11-20
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- On Windows, `margin run` no longer crashes with `UnicodeEncodeError` when the report is piped
|
|
11
|
+
or redirected and contains characters such as `→`. The report is written as UTF-8.
|
|
12
|
+
|
|
7
13
|
## [0.1.2] - 2026-11-02
|
|
8
14
|
|
|
9
15
|
### Security
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: margin-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: The `margin` command: list, inspect and run margin agents from the terminal.
|
|
5
5
|
Project-URL: Homepage, https://github.com/Waddah0-0/margin
|
|
6
6
|
Project-URL: Source, https://github.com/Waddah0-0/margin/tree/main/packages/cli
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""The ``
|
|
1
|
+
"""The ``margin`` command: list, inspect and run installed agents.
|
|
2
2
|
|
|
3
3
|
Output conventions: the report (or the ``--json`` listing) goes to stdout and nothing else
|
|
4
4
|
does, so ``margin run ... --format json > report.json`` always produces valid JSON. Progress,
|
|
@@ -19,6 +19,7 @@ Exit codes:
|
|
|
19
19
|
from __future__ import annotations
|
|
20
20
|
|
|
21
21
|
import asyncio
|
|
22
|
+
import contextlib
|
|
22
23
|
import json
|
|
23
24
|
import logging
|
|
24
25
|
import sys
|
|
@@ -190,6 +191,27 @@ def _render(result: AgentResult, fmt: ReportFormat) -> str:
|
|
|
190
191
|
return to_json(result) + "\n" if fmt is ReportFormat.json else to_markdown(result)
|
|
191
192
|
|
|
192
193
|
|
|
194
|
+
def _write_stdout(text: str) -> None:
|
|
195
|
+
"""Write ``text`` to stdout as UTF-8, even when redirected with cp1252 on Windows."""
|
|
196
|
+
stream = sys.stdout
|
|
197
|
+
if stream is None:
|
|
198
|
+
return
|
|
199
|
+
reconfigure = getattr(stream, "reconfigure", None)
|
|
200
|
+
if callable(reconfigure):
|
|
201
|
+
with contextlib.suppress(OSError, ValueError, AttributeError):
|
|
202
|
+
reconfigure(encoding="utf-8", errors="replace")
|
|
203
|
+
try:
|
|
204
|
+
stream.write(text)
|
|
205
|
+
stream.flush()
|
|
206
|
+
except UnicodeEncodeError:
|
|
207
|
+
buffer = getattr(stream, "buffer", None)
|
|
208
|
+
if buffer is None:
|
|
209
|
+
raise
|
|
210
|
+
stream.flush()
|
|
211
|
+
buffer.write(text.encode("utf-8", errors="replace"))
|
|
212
|
+
buffer.flush()
|
|
213
|
+
|
|
214
|
+
|
|
193
215
|
def _exit_code(result: AgentResult | None, cancelled: bool, strict: bool) -> ExitCode:
|
|
194
216
|
if cancelled or result is None:
|
|
195
217
|
return ExitCode.CANCELLED
|
|
@@ -278,7 +300,7 @@ def run_agent(
|
|
|
278
300
|
out.write_text(report, encoding="utf-8")
|
|
279
301
|
stderr.print(f"Report written to {out}", highlight=False)
|
|
280
302
|
else:
|
|
281
|
-
|
|
303
|
+
_write_stdout(report)
|
|
282
304
|
for warning in result.warnings:
|
|
283
305
|
stderr.print(f"[yellow]Warning:[/] {escape(warning)}", highlight=False)
|
|
284
306
|
if result.status == "error":
|
|
@@ -244,6 +244,51 @@ def test_partial_exits_0_or_4_with_strict(folder: Path) -> None:
|
|
|
244
244
|
assert invoke("run", "lister", str(folder), "--set", "mode=partial", "--strict")[0] == 4
|
|
245
245
|
|
|
246
246
|
|
|
247
|
+
def test_run_markdown_preserves_unicode_arrows_and_times() -> None:
|
|
248
|
+
code, out, err = invoke("run", "echo", "a \u2192 b \u00d7 c")
|
|
249
|
+
assert code == 0 and "a \u2192 b \u00d7 c" in out and err == ""
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def test_write_stdout_handles_cp1252(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
253
|
+
raw = io.BytesIO()
|
|
254
|
+
wrapper = io.TextIOWrapper(raw, encoding="cp1252", newline="\n")
|
|
255
|
+
try:
|
|
256
|
+
monkeypatch.setattr(sys, "stdout", wrapper)
|
|
257
|
+
cli._write_stdout("a \u2192 b \u00d7 c\n")
|
|
258
|
+
assert raw.getvalue().decode("utf-8") == "a \u2192 b \u00d7 c\n"
|
|
259
|
+
finally:
|
|
260
|
+
wrapper.detach()
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def test_write_stdout_falls_back_to_buffer_when_reconfigure_fails(
|
|
264
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
265
|
+
) -> None:
|
|
266
|
+
raw = io.BytesIO()
|
|
267
|
+
wrapper = io.TextIOWrapper(raw, encoding="cp1252", newline="\n")
|
|
268
|
+
|
|
269
|
+
class NonReconfigurableStream:
|
|
270
|
+
def __init__(self, inner: io.TextIOWrapper) -> None:
|
|
271
|
+
self._inner = inner
|
|
272
|
+
self.buffer = inner.buffer
|
|
273
|
+
|
|
274
|
+
def reconfigure(self, **kwargs: object) -> None:
|
|
275
|
+
raise OSError("cannot reconfigure")
|
|
276
|
+
|
|
277
|
+
def write(self, text: str) -> int:
|
|
278
|
+
return self._inner.write(text)
|
|
279
|
+
|
|
280
|
+
def flush(self) -> None:
|
|
281
|
+
self._inner.flush()
|
|
282
|
+
|
|
283
|
+
try:
|
|
284
|
+
wrapper.write("prefix\n")
|
|
285
|
+
monkeypatch.setattr(sys, "stdout", NonReconfigurableStream(wrapper))
|
|
286
|
+
cli._write_stdout("a \u2192 b \u00d7 c\n")
|
|
287
|
+
assert raw.getvalue().decode("utf-8") == "prefix\na \u2192 b \u00d7 c\n"
|
|
288
|
+
finally:
|
|
289
|
+
wrapper.detach()
|
|
290
|
+
|
|
291
|
+
|
|
247
292
|
# ---- run: LLM selection ---------------------------------------------------------------
|
|
248
293
|
|
|
249
294
|
|
|
@@ -452,3 +497,34 @@ def test_ctrl_c_cancels_and_exits_130() -> None:
|
|
|
452
497
|
out, err = proc.communicate(timeout=30)
|
|
453
498
|
assert proc.returncode == 130, err
|
|
454
499
|
assert out == "" and "Cancelled" in err
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
CP1252_SCRIPT = """
|
|
503
|
+
import sys
|
|
504
|
+
from echo_agent import EchoAgent
|
|
505
|
+
from margin_cli import main as cli
|
|
506
|
+
from margin_core import AgentRegistry
|
|
507
|
+
|
|
508
|
+
assert (sys.stdout.encoding or "").lower() in {"cp1252", "windows-1252"}, sys.stdout.encoding
|
|
509
|
+
registry = AgentRegistry([])
|
|
510
|
+
registry.register(EchoAgent)
|
|
511
|
+
cli.get_registry = lambda: registry
|
|
512
|
+
cli.app(["run", "echo", "a \\u2192 b \\u00d7 c", "--quiet"])
|
|
513
|
+
"""
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def test_run_subprocess_cp1252_stdout_outputs_valid_utf8() -> None:
|
|
517
|
+
env = {**os.environ, "MARGIN_ENV_FILE": "", "PYTHONIOENCODING": "cp1252"}
|
|
518
|
+
env.pop("PYTHONUTF8", None)
|
|
519
|
+
proc = subprocess.run(
|
|
520
|
+
[sys.executable, "-c", CP1252_SCRIPT],
|
|
521
|
+
capture_output=True,
|
|
522
|
+
env=env,
|
|
523
|
+
timeout=30,
|
|
524
|
+
check=False,
|
|
525
|
+
)
|
|
526
|
+
assert proc.returncode == 0, proc.stderr.decode("utf-8", errors="replace")
|
|
527
|
+
assert proc.stderr == b""
|
|
528
|
+
text = proc.stdout.decode("utf-8")
|
|
529
|
+
assert "# echo report" in text
|
|
530
|
+
assert "a \u2192 b \u00d7 c" in text
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|