refactor(hermes_cli): small modules — default_soul scaffold constants, input_sanitize sub table, diagnostics_upload request helper, gui_uninstall/dep_ensure packing

This commit is contained in:
Teknium
2026-09-03 00:06:30 -07:00
parent 6bb3dad890
commit d874884777
7 changed files with 103 additions and 189 deletions
+12 -14
View File
@@ -4,30 +4,28 @@ from __future__ import annotations
import re
_BRACKETED_PASTE_BOUNDARY_START = re.compile(r"(^|[\s\n>:\]\)])\[200~")
_BRACKETED_PASTE_BOUNDARY_END = re.compile(r"\[201~(?=$|[\s\n<\[\(\):;.,!?])")
_BRACKETED_PASTE_DEGRADED_START = re.compile(r"(^|[\s\n>:\]\)])00~")
_BRACKETED_PASTE_DEGRADED_END = re.compile(r"01~(?=$|[\s\n<\[\(\):;.,!?])")
# Degraded visible bracketed-paste forms, matched only at boundaries so embedded literals stay intact.
_BOUNDARY_SUBS = (
(re.compile(r"(^|[\s\n>:\]\)])\[200~"), r"\1"),
(re.compile(r"\[201~(?=$|[\s\n<\[\(\):;.,!?])"), ""),
(re.compile(r"(^|[\s\n>:\]\)])00~"), r"\1"),
(re.compile(r"01~(?=$|[\s\n<\[\(\):;.,!?])"), ""),
)
# Corruption signature from desktop bracketed-paste leaks (#62557).
_DESKTOP_PASTE_ARTIFACT = "~[[e"
def strip_leaked_bracketed_paste_wrappers(text: str) -> str:
"""Strip leaked bracketed-paste wrapper markers from user-visible text.
Canonical wrappers are stripped unconditionally. Degraded visible forms like ``[200~`` /
``[201~`` and ``00~`` / ``01~`` are removed only at boundaries so embedded literals such as
``literal[200~tag`` stay intact.
"""
"""Strip leaked bracketed-paste wrapper markers: canonical wrappers unconditionally, degraded visible forms
(``[200~`` / ``[201~`` and ``00~`` / ``01~``) only at boundaries so ``literal[200~tag`` stays intact."""
if not text:
return text
for wrapper in ("\x1b[200~", "\x1b[201~", "^[[200~", "^[[201~"):
text = text.replace(wrapper, "")
text = _BRACKETED_PASTE_BOUNDARY_START.sub(r"\1", text)
text = _BRACKETED_PASTE_BOUNDARY_END.sub("", text)
text = _BRACKETED_PASTE_DEGRADED_START.sub(r"\1", text)
return _BRACKETED_PASTE_DEGRADED_END.sub("", text)
for pattern, repl in _BOUNDARY_SUBS:
text = pattern.sub(repl, text)
return text
def collapse_repeated_input_artifacts(text: str, min_repeats: int = 4) -> str: