Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(chat): skip mention-only lines in shared server titles

pseudoyua1f980b03af5
diff --git a/server/internal/chattitle/title.go b/server/internal/chattitle/title.go
index e5a1d0f821..a05405ca11 100644
--- a/server/internal/chattitle/title.go
+++ b/server/internal/chattitle/title.go
@@ -13,16 +13,27 @@ var (
markdownMarks = regexp.MustCompile("[#*`>~_]")
markdownLink = regexp.MustCompile(`!?\[([^\]]*)\]\([^)]*\)`)
titleSpace = regexp.MustCompile(`[[:space:]]+`)
+ // A line of nothing but mention links, such as the page a message was
+ // sent from, which clients put ahead of what the user wrote.
+ mentionsOnly = regexp.MustCompile(`^(?:\[(?:\\.|[^\]\\])*\]\(mention://[^)]*\)\s*)+$`)
)
// Derive is the single deterministic title policy for a Chat's first message,
// shared by first-party clients (which create sessions untitled) and channels:
-// first non-empty line, Markdown stripped, whitespace collapsed, capped at 30
+// first non-empty line that is not only mentions (or the first non-empty line
+// when every line is), Markdown stripped, whitespace collapsed, capped at 30
// code points with a single ellipsis.
func Derive(body string) string {
line := ""
for _, candidate := range strings.Split(body, "\n") {
- if strings.TrimSpace(candidate) != "" {
+ trimmed := strings.TrimSpace(candidate)
+ if trimmed == "" {
+ continue
+ }
+ if line == "" {
+ line = candidate
+ }
+ if !mentionsOnly.MatchString(trimmed) {
line = candidate
break
}
diff --git a/server/internal/chattitle/title_test.go b/server/internal/chattitle/title_test.go
new file mode 100644
index 0000000000..11ea0889f3
--- /dev/null
+++ b/server/internal/chattitle/title_test.go
@@ -0,0 +1,23 @@
+package chattitle
+
+import "testing"
+
+// The page a message is sent from goes ahead of it as a line of mention
+// links. Taken as the first line, that link was the whole title ("DEV-43").
+func TestDeriveSkipsALineOfMentions(t *testing.T) {
+ tests := []struct{ input, want string }{
+ {"[DEV-43](mention://issue/issue-1)\n\nWhy is this failing?", "Why is this failing?"},
+ {"[Q3 \\[beta\\]](mention://project/p-1) [DEV-43](mention://issue/issue-1)\nCompare these", "Compare these"},
+ // A message of only mentions is named after them.
+ {"[DEV-43](mention://issue/issue-1)", "DEV-43"},
+ // A line that says something beside its mention stays the title.
+ {"[DEV-43](mention://issue/issue-1) is blocked\nwhy?", "DEV-43 is blocked"},
+ // Ordinary links are not mentions.
+ {"[docs](https://example.com)\nsecond line", "docs"},
+ }
+ for _, tc := range tests {
+ if got := Derive(tc.input); got != tc.want {
+ t.Errorf("Derive(%q) = %q, want %q", tc.input, got, tc.want)
+ }
+ }
+}