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:
@@ -44,6 +44,44 @@ func TestAgentThreadsOnlyListsAgentConversationThreads(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentThreadsSummaryHidesPromptReferenceDirectives(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repo := memory.NewProjectRepository()
|
||||
service := NewDesignService(repo, nil, nil, nil, nil)
|
||||
now := time.Now()
|
||||
project := design.Project{
|
||||
ID: "project-agent-reference-history",
|
||||
Title: "Agent history",
|
||||
Status: design.StatusReady,
|
||||
LastThreadID: "thread-agent",
|
||||
UpdatedAt: now,
|
||||
Messages: []design.Message{
|
||||
{
|
||||
ID: "agent-user",
|
||||
Role: "user",
|
||||
Type: "user",
|
||||
Content: "Reference image 1 (image): http://localhost:19000/canvas-assets/reference.png 灰裤子拆成单件衣服,为了后面电商配图。\nSelected model: GPT Image 2",
|
||||
ThreadID: "thread-agent",
|
||||
CreatedAt: now,
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := repo.Save(ctx, project); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
threads, err := service.AgentThreads(ctx, project.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(threads) != 1 {
|
||||
t.Fatalf("expected one agent thread, got %#v", threads)
|
||||
}
|
||||
if threads[0].Text != "灰裤子拆成单件衣服,为了后面电商配图。" {
|
||||
t.Fatalf("expected visible prompt text only, got %q", threads[0].Text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectScopedToAgentThreadKeepsOnlyCurrentConversationContext(t *testing.T) {
|
||||
now := time.Now()
|
||||
project := design.Project{
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user