refactor(envelope): drop the reply counter and the injects line, keep time and vault changes
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
"""The envelope (§3.3): a background block after the user's text.
|
||||
|
||||
Assembled when the turn starts, never when the message is queued: the
|
||||
time, how many replies the master gave in a row without opening a branch,
|
||||
what changed in the vault since the last envelope (added lines for the
|
||||
``full`` files, names and counts for the rest) and how many normal
|
||||
injects ride along below. Ceilings keep it a signal, not a document.
|
||||
time and what changed in the vault since the last envelope (added lines
|
||||
for the ``full`` files, names and counts for the rest). Ceilings keep it
|
||||
a signal, not a document; the injects that ride along are bundled below
|
||||
it by the queue, with their own header.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -36,7 +36,7 @@ class Envelope:
|
||||
names_only_within: float = 600.0
|
||||
last_at: datetime | None = None
|
||||
|
||||
def build(self, *, streak: int, injects: int, now: datetime | None = None) -> str:
|
||||
def build(self, *, now: datetime | None = None) -> str:
|
||||
now = now or datetime.now(UTC)
|
||||
changes = self.watch.take() if self.watch is not None else []
|
||||
names_only = (
|
||||
@@ -46,11 +46,9 @@ class Envelope:
|
||||
text = render(
|
||||
now=now,
|
||||
tz=self.tz,
|
||||
streak=streak,
|
||||
changes=changes,
|
||||
since=self.last_at,
|
||||
names_only=names_only,
|
||||
injects=injects,
|
||||
max_lines=self.max_lines,
|
||||
per_file=self.per_file,
|
||||
)
|
||||
@@ -62,30 +60,22 @@ def render(
|
||||
*,
|
||||
now: datetime,
|
||||
tz: str,
|
||||
streak: int,
|
||||
changes: Sequence[Change],
|
||||
since: datetime | None,
|
||||
names_only: bool,
|
||||
injects: int,
|
||||
max_lines: int = 120,
|
||||
per_file: int = 30,
|
||||
) -> str:
|
||||
zone = ZoneInfo(tz)
|
||||
stamp = now.astimezone(zone)
|
||||
lines = [
|
||||
HEADER,
|
||||
f"время: {stamp:%Y-%m-%d %H:%M} ({_zone_label(tz)})",
|
||||
f"мастер: {_replies(streak)} подряд без ветки",
|
||||
]
|
||||
lines = [HEADER, f"время: {stamp:%Y-%m-%d %H:%M} ({_zone_label(tz)})"]
|
||||
ordered = sorted(changes, key=lambda c: (not c.full, c.path))
|
||||
since_label = (
|
||||
f"с {since.astimezone(zone):%H:%M}" if since is not None else "со старта" # noqa: RUF001
|
||||
)
|
||||
if ordered:
|
||||
names = ", ".join(f"{c.path} (+{c.added_count})" for c in ordered)
|
||||
lines.append(f"vault, изменено {since_label} (mtime): {names}")
|
||||
if injects:
|
||||
lines.append(f"инжекты {since_label}: ({injects}) ниже")
|
||||
lines.append(f"vault, изменено {since_label}: {names}")
|
||||
if not names_only:
|
||||
_append_diffs(lines, ordered, max_lines=max_lines, per_file=per_file)
|
||||
return "\n".join(lines[:max_lines])
|
||||
@@ -110,13 +100,5 @@ def _append_diffs(
|
||||
budget -= 1
|
||||
|
||||
|
||||
def _replies(n: int) -> str:
|
||||
if n % 10 == 1 and n % 100 != 11:
|
||||
return f"{n} реплика"
|
||||
if 2 <= n % 10 <= 4 and not 12 <= n % 100 <= 14:
|
||||
return f"{n} реплики"
|
||||
return f"{n} реплик"
|
||||
|
||||
|
||||
def _zone_label(tz: str) -> str:
|
||||
return tz.rsplit("/", 1)[-1].replace("_", " ")
|
||||
|
||||
Reference in New Issue
Block a user