feat(journal): _build_transcript caps content and message window
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1 +1 @@
|
|||||||
2298268
|
3158517
|
||||||
|
|||||||
Generated
+1
-1
@@ -184,7 +184,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fable-mcp"
|
name = "fable-mcp"
|
||||||
version = "0.2.6"
|
version = "0.3.0"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "httpx" },
|
{ name = "httpx" },
|
||||||
|
|||||||
@@ -26,3 +26,15 @@ def _filter_messages(messages):
|
|||||||
continue
|
continue
|
||||||
kept.append(m)
|
kept.append(m)
|
||||||
return kept
|
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
|
||||||
|
)
|
||||||
|
|||||||
@@ -22,3 +22,32 @@ def test_filter_excludes_daily_prep_messages():
|
|||||||
assert "Good morning — here is today's plan…" not in contents
|
assert "Good morning — here is today's plan…" not in contents
|
||||||
assert "I want to focus on the auth refactor today." 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
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user