Skip to content

Commit 4d8d3b3

Browse files
committed
Fixed bug where index.html did not always show long summaries
Also made it so output shows full path to index.html https://gistpreview.github.io/?0ce06835c48f621d068e7b10ccc9b86d
1 parent 2000721 commit 4d8d3b3

File tree

2 files changed

+120
-6
lines changed

2 files changed

+120
-6
lines changed

src/claude_code_publish/__init__.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,16 @@ def generate_html(json_path, output_dir, github_repo=None):
852852
link = f"page-{page_num:03d}.html#{msg_id}"
853853
rendered_content = render_markdown_text(conv["user_text"])
854854

855+
# Collect all messages including from subsequent continuation conversations
856+
# This ensures long_texts from continuations appear with the original prompt
857+
all_messages = list(conv["messages"])
858+
for j in range(i + 1, len(conversations)):
859+
if not conversations[j].get("is_continuation"):
860+
break
861+
all_messages.extend(conversations[j]["messages"])
862+
855863
# Analyze conversation for stats (excluding commits from inline display now)
856-
stats = analyze_conversation(conv["messages"])
864+
stats = analyze_conversation(all_messages)
857865
tool_stats_str = format_tool_stats(stats["tool_counts"])
858866

859867
stats_html = ""
@@ -904,8 +912,9 @@ def generate_html(json_path, output_dir, github_repo=None):
904912
<script>{JS}</script>
905913
</body>
906914
</html>"""
907-
(output_dir / "index.html").write_text(index_content)
908-
print(f"Generated index.html ({total_convs} prompts, {total_pages} pages)")
915+
index_path = output_dir / "index.html"
916+
index_path.write_text(index_content)
917+
print(f"Generated {index_path.resolve()} ({total_convs} prompts, {total_pages} pages)")
909918

910919

911920
@click.group(cls=DefaultGroup, default="session", default_if_no_args=False)
@@ -1172,8 +1181,16 @@ def generate_html_from_session_data(session_data, output_dir, github_repo=None):
11721181
link = f"page-{page_num:03d}.html#{msg_id}"
11731182
rendered_content = render_markdown_text(conv["user_text"])
11741183

1184+
# Collect all messages including from subsequent continuation conversations
1185+
# This ensures long_texts from continuations appear with the original prompt
1186+
all_messages = list(conv["messages"])
1187+
for j in range(i + 1, len(conversations)):
1188+
if not conversations[j].get("is_continuation"):
1189+
break
1190+
all_messages.extend(conversations[j]["messages"])
1191+
11751192
# Analyze conversation for stats (excluding commits from inline display now)
1176-
stats = analyze_conversation(conv["messages"])
1193+
stats = analyze_conversation(all_messages)
11771194
tool_stats_str = format_tool_stats(stats["tool_counts"])
11781195

11791196
stats_html = ""
@@ -1224,8 +1241,9 @@ def generate_html_from_session_data(session_data, output_dir, github_repo=None):
12241241
<script>{JS}</script>
12251242
</body>
12261243
</html>"""
1227-
(output_dir / "index.html").write_text(index_content)
1228-
click.echo(f"Generated index.html ({total_convs} prompts, {total_pages} pages)")
1244+
index_path = output_dir / "index.html"
1245+
index_path.write_text(index_content)
1246+
click.echo(f"Generated {index_path.resolve()} ({total_convs} prompts, {total_pages} pages)")
12291247

12301248

12311249
@cli.command("import")

tests/test_generate_html.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,102 @@ def mock_run(*args, **kwargs):
626626
assert "gistpreview.github.io" in index_content
627627

628628

629+
class TestContinuationLongTexts:
630+
"""Tests for long text extraction from continuation conversations."""
631+
632+
def test_long_text_in_continuation_appears_in_index(self, output_dir):
633+
"""Test that long texts from continuation conversations appear in index.
634+
635+
This is a regression test for a bug where conversations marked as
636+
continuations (isCompactSummary=True) were completely skipped when
637+
building the index, causing their long_texts to be lost.
638+
"""
639+
# Create a session with:
640+
# 1. An initial user prompt
641+
# 2. Some messages
642+
# 3. A continuation prompt (isCompactSummary=True)
643+
# 4. An assistant message with a long text summary (>300 chars)
644+
session_data = {
645+
"loglines": [
646+
# Initial user prompt
647+
{
648+
"type": "user",
649+
"timestamp": "2025-01-01T10:00:00.000Z",
650+
"message": {"content": "Build a Redis JavaScript module", "role": "user"},
651+
},
652+
# Some assistant work
653+
{
654+
"type": "assistant",
655+
"timestamp": "2025-01-01T10:00:05.000Z",
656+
"message": {
657+
"role": "assistant",
658+
"content": [{"type": "text", "text": "I'll start working on this."}],
659+
},
660+
},
661+
# Continuation prompt (context was summarized)
662+
{
663+
"type": "user",
664+
"timestamp": "2025-01-01T11:00:00.000Z",
665+
"isCompactSummary": True,
666+
"message": {
667+
"content": "This session is being continued from a previous conversation...",
668+
"role": "user",
669+
},
670+
},
671+
# More assistant work after continuation
672+
{
673+
"type": "assistant",
674+
"timestamp": "2025-01-01T11:00:05.000Z",
675+
"message": {
676+
"role": "assistant",
677+
"content": [{"type": "text", "text": "Continuing the work..."}],
678+
},
679+
},
680+
# Final summary - this is a LONG text (>300 chars) that should appear in index
681+
{
682+
"type": "assistant",
683+
"timestamp": "2025-01-01T12:00:00.000Z",
684+
"message": {
685+
"role": "assistant",
686+
"content": [
687+
{
688+
"type": "text",
689+
"text": (
690+
"All tasks completed successfully. Here's a summary of what was built:\n\n"
691+
"## Redis JavaScript Module\n\n"
692+
"A loadable Redis module providing JavaScript scripting via the mquickjs engine.\n\n"
693+
"### Commands Implemented\n"
694+
"- JS.EVAL - Execute JavaScript with KEYS/ARGV arrays\n"
695+
"- JS.LOAD / JS.CALL - Cache and call scripts by SHA1\n"
696+
"- JS.EXISTS / JS.FLUSH - Manage script cache\n\n"
697+
"All 41 tests pass. Changes pushed to branch."
698+
),
699+
}
700+
],
701+
},
702+
},
703+
]
704+
}
705+
706+
# Write the session to a temp file
707+
session_file = output_dir / "test_session.json"
708+
session_file.write_text(json.dumps(session_data))
709+
710+
# Generate HTML
711+
generate_html(session_file, output_dir)
712+
713+
# Read the index.html
714+
index_html = (output_dir / "index.html").read_text()
715+
716+
# The long text summary should appear in the index
717+
# This is the bug: currently it doesn't because the continuation
718+
# conversation is skipped entirely
719+
assert "All tasks completed successfully" in index_html, (
720+
"Long text from continuation conversation should appear in index"
721+
)
722+
assert "Redis JavaScript Module" in index_html
723+
724+
629725
class TestSessionJsonOption:
630726
"""Tests for the session command --json option."""
631727

0 commit comments

Comments
 (0)