Skip to content
Open
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
36 changes: 36 additions & 0 deletions extensions/python/monologue_start/_60_rename_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,42 @@ async def change_name(self):
# update name
if new_name:
new_name = " ".join(str(new_name).split())
# P028: Guard against JSON-looking names (utility model echoes)
stripped = new_name.lstrip()
if stripped and stripped[0] in "{[":
import json as _json
extracted = None
# Step 1: Try to parse JSON and extract headline (best quality)
try:
parsed = _json.loads(stripped)
headline = parsed.get("headline")
if isinstance(headline, str) and headline.strip():
extracted = headline.strip()
else:
thoughts = parsed.get("thoughts")
if isinstance(thoughts, list) and thoughts:
first = thoughts[0]
if isinstance(first, str) and first.strip():
extracted = first.strip()
except (_json.JSONDecodeError, ValueError, AttributeError):
pass
# Step 2: Fall back to first user message topic
if not extracted:
try:
msgs = self.agent.history.output()
for msg in msgs:
if not msg.ai and msg.content:
content = str(msg.content)
first_line = content.split(chr(10))[0].split(".")[0].strip()
if first_line:
extracted = first_line[:40]
if len(first_line) > 40:
extracted += "..."
break
except Exception:
pass
# Step 3: Last resort
new_name = extracted or "Conversation"
if len(new_name) > 40:
new_name = new_name[:40] + "..."
if not new_name:
Expand Down