From 2576be9e4939d641d1645f354c71f90952206b27 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 12 May 2026 14:33:27 -0400 Subject: [PATCH] feat(journal): _build_transcript caps content and message window Co-Authored-By: Claude Opus 4.7 (1M context) --- .remember/tmp/save-session.pid | 2 +- fable-mcp/uv.lock | 2 +- .../services/journal_closeout.py | 12 ++++++++ tests/test_journal_closeout.py | 29 +++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/.remember/tmp/save-session.pid b/.remember/tmp/save-session.pid index 937c971..9bc105c 100644 --- a/.remember/tmp/save-session.pid +++ b/.remember/tmp/save-session.pid @@ -1 +1 @@ -2298268 +3158517 diff --git a/fable-mcp/uv.lock b/fable-mcp/uv.lock index 3b2a4f9..046e9b5 100644 --- a/fable-mcp/uv.lock +++ b/fable-mcp/uv.lock @@ -184,7 +184,7 @@ wheels = [ [[package]] name = "fable-mcp" -version = "0.2.6" +version = "0.3.0" source = { editable = "." } dependencies = [ { name = "httpx" }, diff --git a/src/fabledassistant/services/journal_closeout.py b/src/fabledassistant/services/journal_closeout.py index 7e3a47e..843e05c 100644 --- a/src/fabledassistant/services/journal_closeout.py +++ b/src/fabledassistant/services/journal_closeout.py @@ -26,3 +26,15 @@ def _filter_messages(messages): continue kept.append(m) return kept + + +_TRANSCRIPT_WINDOW = 20 +_CONTENT_CAP = 500 + + +def _build_transcript(messages) -> str: + """Format the last 20 messages as `ROLE: content[:500]` lines.""" + tail = list(messages)[-_TRANSCRIPT_WINDOW:] + return "\n".join( + f"{m.role.upper()}: {m.content[:_CONTENT_CAP]}" for m in tail + ) diff --git a/tests/test_journal_closeout.py b/tests/test_journal_closeout.py index e8a27fe..9e96d84 100644 --- a/tests/test_journal_closeout.py +++ b/tests/test_journal_closeout.py @@ -22,3 +22,32 @@ def test_filter_excludes_daily_prep_messages(): assert "Good morning — here is today's plan…" not in contents assert "I want to focus on the auth refactor today." in contents assert "Got it. I'll keep tool calls quiet." in contents + + +def test_build_transcript_labels_roles_and_caps_content(): + from fabledassistant.services.journal_closeout import _build_transcript + + msgs = [ + _msg("user", "hello"), + _msg("assistant", "hi"), + _msg("user", "x" * 600), + ] + out = _build_transcript(msgs) + lines = out.splitlines() + assert lines[0] == "USER: hello" + assert lines[1] == "ASSISTANT: hi" + # Third line content truncated to 500 chars + assert lines[2].startswith("USER: ") + assert len(lines[2]) == len("USER: ") + 500 + + +def test_build_transcript_keeps_only_last_20_messages(): + from fabledassistant.services.journal_closeout import _build_transcript + + msgs = [_msg("user", f"msg-{i}") for i in range(30)] + out = _build_transcript(msgs) + lines = out.splitlines() + assert len(lines) == 20 + # Newest 20 means msg-10 through msg-29 + assert lines[0] == "USER: msg-10" + assert lines[-1] == "USER: msg-29"