Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions code_puppy/plugins/puppy_kennel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@
# Cap on stored drawer text length (chars). Keeps SQLite happy and FTS indexes
# from getting comically large. Truncation is fine — verbatim within reason.
MAX_DRAWER_CHARS = int(os.environ.get("PUPPY_KENNEL_MAX_DRAWER_CHARS", "32000"))

# Strip personality emote lines (e.g. *wags tail excitedly*) before storing.
# Set to "0" or "false" to disable and store responses fully verbatim.
STRIP_NOISE = os.environ.get("PUPPY_KENNEL_STRIP_NOISE", "1") not in ("0", "false", "False")
28 changes: 28 additions & 0 deletions code_puppy/plugins/puppy_kennel/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,40 @@

from __future__ import annotations

import re
from typing import Any

from code_puppy.messaging.bus import emit_debug

from . import kennel
from .config import STRIP_NOISE
from .state import is_enabled
from .wings import detect_cwd, repo_wing

# Lines entirely wrapped in *...* (not **...**) are personality emotes:
# *wags tail excitedly*, *zooms around happily*, *woof woof*
# Bold (**...**), bullet points (* item), and inline italics mid-sentence
# are all unaffected because they don't match this pattern.
_EMOTE_LINE_RE = re.compile(r"^\s*\*(?!\*)[^*\n]+\*\s*$")


def _strip_noise(text: str) -> str:
"""Remove personality emote lines from a response before kennel storage.

Processes line-by-line so code-fence content is never touched, even if
a fence happens to contain a line that looks like *emote*.
"""
in_fence = False
out: list[str] = []
for line in text.split("\n"):
if line.strip().startswith("```"):
in_fence = not in_fence
if not in_fence and _EMOTE_LINE_RE.match(line):
continue
out.append(line)
cleaned = re.sub(r"\n{3,}", "\n\n", "\n".join(out))
return cleaned.strip()


def _room_name(session_id: str | None) -> str:
"""Rooms partition a wing by session. Keep the name human-scannable."""
Expand All @@ -48,6 +74,8 @@ def record_run_end(
Failures here must never crash the host app — the kennel is best-
effort memory, not a transactional system of record.
"""
if STRIP_NOISE and response_text:
response_text = _strip_noise(response_text)
if not response_text or not response_text.strip():
return
if not success:
Expand Down
Loading