Skip to content

Commit f0723f5

Browse files
sourcehawkclaude
andcommitted
fix(skills/bounding-heavy-commands): print a control character of a held command as a question mark
The held lines of the check folded whitespace but kept other control characters, so an argument or a path with a terminal escape sequence went to the terminal as it was and could change what the check showed. Each character that is not printable is now a question mark. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5430ca6 commit f0723f5

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎skills/bounding-heavy-commands/scripts/bounded_run.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,12 @@ def _process_age_seconds(pid: int, proc_root: str, ticks: int) -> Optional[int]:
764764
return None
765765

766766

767+
def _one_line(text: str) -> str:
768+
# The check prints one line for each command: a line break in an argument or a path would split the line,
769+
# and a control character would act on the terminal.
770+
return "".join(character if character.isprintable() else "?" for character in " ".join(text.split()))
771+
772+
767773
def _held_command(pid: int, proc_root: str) -> Optional[str]:
768774
text = _read_text(os.path.join(proc_root, str(pid), "cmdline"))
769775
if not text:
@@ -773,8 +779,7 @@ def _held_command(pid: int, proc_root: str) -> Optional[str]:
773779
at = arguments.index("--inside-cap")
774780
if arguments[at + 3:at + 4] == ["--"]:
775781
arguments = arguments[at + 4:]
776-
# The check prints one line for each command, so a line break inside an argument becomes a space.
777-
return " ".join(" ".join(arguments).split())[:HELD_COMMAND_CHARACTERS]
782+
return _one_line(" ".join(arguments))[:HELD_COMMAND_CHARACTERS]
778783

779784

780785
def held_commands(parent: str, skip: Sequence[str], proc_root: str = "/proc", ticks: Optional[int] = None) -> List[str]:
@@ -805,7 +810,7 @@ def mib(text: Optional[str]) -> str:
805810
except OSError:
806811
working = None
807812
if working is not None:
808-
working = " ".join(working.split())
813+
working = _one_line(working)
809814
command = _held_command(pid, proc_root) if pid is not None else None
810815
held.append("unit=%s budget=%s used=%s age=%s dir=%s command=%s" % (
811816
name[:-len(".scope")], mib(limit), mib(current), "-" if age is None else "%ds" % age,

‎skills/bounding-heavy-commands/scripts/tests/test_bounded_run.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@ def test_a_directory_with_a_line_break_stays_on_one_line(self):
11371137
self.process(100, self.inside("tool"), cwd="/work/two\nlines")
11381138
self.assertEqual(self.held(), ["unit=bounded-run-100-aaaaaa budget=4096M used=1024M age=120s dir=/work/two lines command=tool"])
11391139

1140+
def test_control_characters_of_the_command_and_the_directory_become_question_marks(self):
1141+
self.scope("bounded-run-100-aaaaaa.scope")
1142+
self.process(100, self.inside("printf", "\x1b[2Jdone"), cwd="/work/\x1b[31mred")
1143+
self.assertEqual(self.held(), ["unit=bounded-run-100-aaaaaa budget=4096M used=1024M age=120s dir=/work/?[31mred command=printf ?[2Jdone"])
1144+
11401145
def test_a_command_without_the_prefix_of_the_wrapper_is_given_whole(self):
11411146
self.scope("bounded-run-100-aaaaaa.scope")
11421147
self.process(100, ["sleep", "60"])

0 commit comments

Comments
 (0)