fix(agent-threads): hide prompt reference directives in thread titles

Add a shared visiblePromptText helper and strip reference tokens,
image-generator directives, and model-selection lines from agent thread
summaries and the assistant panel header, so titles show the user's
actual prompt instead of internal directives. Covered by a server test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-08 01:55:08 +08:00
parent 2ede253b39
commit f23c847e13
4 changed files with 72 additions and 14 deletions
@@ -824,6 +824,7 @@ func isNonAgentConversationMessage(message design.Message) bool {
}
func agentThreadSummaryText(content string) string {
content = stripPromptReferenceDirectives(content)
lines := strings.Split(content, "\n")
kept := make([]string, 0, len(lines))
for _, line := range lines {
@@ -837,7 +838,7 @@ func agentThreadSummaryText(content string) string {
if text := strings.TrimSpace(strings.Join(kept, " ")); text != "" {
return text
}
return strings.TrimSpace(content)
return ""
}
func projectScopedToAgentThread(project design.Project, threadID string) design.Project {
@@ -4530,7 +4531,7 @@ func hasUserPromptTextInAgentMessages(messages []design.AgentChatMessage) bool {
if strings.EqualFold(strings.TrimSpace(content.TextSource), "settings") {
continue
}
text := stripPromptReferenceDirectiveLines(stripImageGeneratorDirectiveLines(content.Text))
text := stripPromptReferenceDirectives(stripImageGeneratorDirectiveLines(content.Text))
if design.NormalizePrompt(text) != "" {
return true
}
@@ -4551,12 +4552,14 @@ func stripImageGeneratorDirectiveLines(text string) string {
return strings.TrimSpace(strings.Join(filtered, "\n"))
}
func stripPromptReferenceDirectiveLines(text string) string {
func stripPromptReferenceDirectives(text string) string {
text = promptImageTokenPattern.ReplaceAllString(text, "")
text = promptImageDirectivePattern.ReplaceAllString(text, "")
lines := strings.Split(text, "\n")
filtered := make([]string, 0, len(lines))
for _, line := range lines {
trimmed := strings.TrimSpace(strings.ReplaceAll(line, "\u00a0", " "))
if isPromptReferenceDirectiveLine(trimmed) {
if trimmed == "" || isPromptReferenceDirectiveLine(trimmed) {
continue
}
filtered = append(filtered, line)