Skip to content

Commit 6ace9f0

Browse files
committed
Merge branch 'support-custom-title-summary'
2 parents e2e876d + 6da9e9a commit 6ace9f0

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/claude_code_transcripts/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,30 @@ def get_session_summary(filepath, max_length=200):
270270
def _get_jsonl_summary(filepath, max_length=200):
271271
"""Extract summary from JSONL file."""
272272
try:
273+
# First priority: custom title (user renamed session via /rename)
274+
with open(filepath, "r", encoding="utf-8") as f:
275+
for line in f:
276+
line = line.strip()
277+
if not line:
278+
continue
279+
try:
280+
obj = json.loads(line)
281+
if obj.get("type") == "custom-title" and obj.get("customTitle"):
282+
title = obj["customTitle"]
283+
if len(title) > max_length:
284+
return title[: max_length - 3] + "..."
285+
return title
286+
except json.JSONDecodeError:
287+
continue
288+
289+
# Second priority: summary type entries
273290
with open(filepath, "r", encoding="utf-8") as f:
274291
for line in f:
275292
line = line.strip()
276293
if not line:
277294
continue
278295
try:
279296
obj = json.loads(line)
280-
# First priority: summary type entries
281297
if obj.get("type") == "summary" and obj.get("summary"):
282298
summary = obj["summary"]
283299
if len(summary) > max_length:
@@ -286,7 +302,7 @@ def _get_jsonl_summary(filepath, max_length=200):
286302
except json.JSONDecodeError:
287303
continue
288304

289-
# Second pass: find first non-meta user message
305+
# Third pass: find first non-meta user message
290306
with open(filepath, "r", encoding="utf-8") as f:
291307
for line in f:
292308
line = line.strip()

tests/test_generate_html.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,26 @@ def test_truncates_long_summaries(self, tmp_path):
10811081
assert len(summary) <= 100
10821082
assert summary.endswith("...")
10831083

1084+
def test_gets_custom_title_from_jsonl(self, tmp_path):
1085+
"""Test extracting custom title from JSONL file (set via /rename)."""
1086+
jsonl_file = tmp_path / "test.jsonl"
1087+
jsonl_file.write_text(
1088+
'{"type":"custom-title","customTitle":"GIT stuff","sessionId":"abc123"}\n'
1089+
'{"type":"user","message":{"content":"Hello"}}\n'
1090+
)
1091+
summary = get_session_summary(jsonl_file)
1092+
assert summary == "GIT stuff"
1093+
1094+
def test_custom_title_takes_priority_over_summary(self, tmp_path):
1095+
"""Test that custom title takes priority over summary entry."""
1096+
jsonl_file = tmp_path / "test.jsonl"
1097+
jsonl_file.write_text(
1098+
'{"type":"custom-title","customTitle":"My Custom Title","sessionId":"abc123"}\n'
1099+
'{"type":"summary","summary":"Auto-generated summary"}\n'
1100+
)
1101+
summary = get_session_summary(jsonl_file)
1102+
assert summary == "My Custom Title"
1103+
10841104

10851105
class TestFindLocalSessions:
10861106
"""Tests for find_local_sessions which discovers local JSONL files."""

0 commit comments

Comments
 (0)