feat(kvb-org-operator): color the command in run on a terminal

The operator found the command hard to spot in the run output. run now prints each step's command bold cyan when stdout is a terminal and NO_COLOR is unset or empty (no-color.org); piped or captured output stays byte-identical. Only the command line is colored. The new test runs run on a pseudo-terminal with and without NO_COLOR and piped. Operator order relayed by the Maintainer session on 2026-11-06; the change was written by a subagent and reviewed here.

🎯 Fix: 95 %
💥 Break: 1 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 94
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %

```
/home/kevinveenbirkenbach/Repositories/github.com/kevinveenbirkenbach/skills/.worktrees/feature/kvb-org-operator-run-color
```

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-10 21:15:59 +00:00
1 parent 85462df5ab
commit 99323abc35
2 files changed
+49 -3

No files matched your search

+35
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import json
import os
import pty
import shutil
import subprocess
import sys
@@ -94,6 +95,28 @@ class TestOperator(unittest.TestCase):
cwd=self.tmp.name, check=False,
)
def _tty(self, extra: dict[str, str]) -> str:
leader, follower = pty.openpty()
self.addCleanup(os.close, leader)
try:
result = subprocess.run(
[sys.executable, str(OPERATOR), "run"], input=b"q\n", stdout=follower, stderr=subprocess.PIPE,
env={**self.env, "SHELL": "/bin/sh", **extra}, cwd=self.tmp.name, check=False,
)
finally:
os.close(follower)
self.assertEqual(result.returncode, 0, result.stderr)
chunks = []
while True:
try:
chunk = os.read(leader, 65536)
except OSError:
break
if not chunk:
break
chunks.append(chunk)
return b"".join(chunks).decode()
def _open(self) -> list[str]:
return [row["task"] for row in json.loads("\n".join(self._out("list", "--json")))]
@@ -231,6 +254,18 @@ class TestOperator(unittest.TestCase):
self.assertNotIn("\x1b", out)
self.assertEqual(self._open(), ["operator/second", "operator/third"])
def test_run_colors_the_command_only_on_a_terminal_without_no_color(self):
self._add("go", self.base, "true", "runnable", "manual")
piped = self._feed("q\n").stdout
self.assertIn(" command: true\n", piped)
self.assertNotIn("\x1b", piped)
colored = self._tty({})
self.assertIn(" command: \x1b[1;36mtrue\x1b[0m\r\n", colored)
self.assertEqual(colored.count("\x1b"), 2)
plain = self._tty({"NO_COLOR": "1"})
self.assertIn(" command: true\r\n", plain)
self.assertNotIn("\x1b", plain)
def test_run_previews_pushed_commits_and_keeps_failed_rows_open(self):
repo = self._repo("ahead", upstream=True)
self._add("push", repo, "false", "branch ahead", f"pushed:{repo}")