Skip to content

Commit 79e32e2

Browse files
committed
fix(mobile): image threads use readable titles
1 parent 339179f commit 79e32e2

4 files changed

Lines changed: 101 additions & 36 deletions

File tree

‎apps/mobile/src/lib/projectThreadStartTurn.test.ts‎

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,57 @@ import {
1414
} from "./projectThreadStartTurn";
1515

1616
describe("project thread title", () => {
17+
it.each([
18+
["![pasted-image.png](t3-context://v1/image/image-1)", "Image: pasted-image.png"],
19+
["![pasted-image.png](t3-context://v1/image/image-1) Fix the spacing", "Fix the spacing"],
20+
["Fix [src/app.ts](t3-context://v1/mention/source)", "Fix src/app.ts"],
21+
["x".repeat(80), `${"x".repeat(69)}...`],
22+
])("uses readable draft and queued titles for %s", (text, title) => {
23+
expect(deriveThreadTitleFromPrompt(text)).toBe(title);
24+
});
25+
1726
it("keeps ordinary titles and the empty-prompt fallback", () => {
1827
expect(deriveThreadTitleFromPrompt(" Fix\n the parser ")).toBe("Fix the parser");
1928
expect(deriveThreadTitleFromPrompt(" \n ")).toBe("New thread");
2029
});
2130

22-
it("derives attachment-only titles from prepared image metadata", () => {
23-
const uploadedAttachments = [
24-
{
25-
type: "image" as const,
26-
id: "prepared-photo",
27-
name: "photo.png",
28-
mimeType: "image/png",
29-
sizeBytes: 3,
30-
},
31-
];
32-
const input = buildProjectThreadStartTurnInput({
33-
projectId: ProjectId.make("project"),
34-
projectCwd: "/workspace",
35-
threadId: "image-thread",
36-
commandId: "image-command",
37-
messageId: "image-message",
38-
createdAt: "2026-09-04T00:00:00Z",
39-
text: "",
40-
uploadedAttachments,
41-
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
42-
runtimeMode: "full-access",
43-
interactionMode: "default",
44-
workspaceMode: "local",
45-
branch: null,
46-
worktreePath: null,
47-
startFromOrigin: false,
48-
worktreeBranchName: "unused",
49-
});
31+
it.each(["", "![photo.png](t3-context://v1/image/photo)"])(
32+
"derives attachment-only titles from prepared image metadata for %s",
33+
(text) => {
34+
const uploadedAttachments = [
35+
{
36+
type: "image" as const,
37+
id: "prepared-photo",
38+
name: "photo.png",
39+
mimeType: "image/png",
40+
sizeBytes: 3,
41+
},
42+
];
43+
const input = buildProjectThreadStartTurnInput({
44+
projectId: ProjectId.make("project"),
45+
projectCwd: "/workspace",
46+
threadId: "image-thread",
47+
commandId: "image-command",
48+
messageId: "image-message",
49+
createdAt: "2026-09-04T00:00:00Z",
50+
text,
51+
uploadedAttachments,
52+
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
53+
runtimeMode: "full-access",
54+
interactionMode: "default",
55+
workspaceMode: "local",
56+
branch: null,
57+
worktreePath: null,
58+
startFromOrigin: false,
59+
worktreeBranchName: "unused",
60+
});
5061

51-
expect(input.titleSeed).toBe("Image: photo.png");
52-
expect(input.bootstrap.createThread.title).toBe(input.titleSeed);
53-
expect(input.message.attachments).toEqual(uploadedAttachments);
54-
});
62+
expect(input.titleSeed).toBe("Image: photo.png");
63+
expect(input.bootstrap.createThread.title).toBe(input.titleSeed);
64+
expect(input.message.attachments).toEqual(uploadedAttachments);
65+
expect(input.message.text).toBe(text);
66+
},
67+
);
5568

5669
it.each([
5770
{

‎apps/mobile/src/lib/projectThreadStartTurn.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import {
99
type ProviderInteractionMode,
1010
type RuntimeMode,
1111
} from "@t3tools/contracts";
12-
import { deriveThreadTitleSeed } from "@t3tools/client-runtime/operations";
13-
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
12+
import {
13+
deriveThreadTitleSeed,
14+
threadTitleTextFromPrompt,
15+
} from "@t3tools/client-runtime/operations";
1416

1517
import type { UploadedMobileAttachment } from "./attachmentUpload";
1618

@@ -87,7 +89,7 @@ export function buildProjectThreadStartTurnInput(spec: ProjectThreadStartTurnSpe
8789
}
8890

8991
export function deriveThreadTitleFromPrompt(value: string): string {
90-
const trimmed = assistantCitationsToPlainText(value).trim();
92+
const trimmed = threadTitleTextFromPrompt(value);
9193
if (trimmed.length === 0) {
9294
return "New thread";
9395
}

‎packages/client-runtime/src/operations/threadTitle.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,40 @@ import { describe, expect, it } from "@effect/vitest";
33
import { deriveThreadTitleSeed } from "./threadTitle.ts";
44

55
describe("deriveThreadTitleSeed", () => {
6+
const image = "![pasted-image.png](t3-context://v1/image/aadd9cc6-1234-5678-9012-abcdef123456)";
7+
8+
it.each([{ attachments: [] }, { attachments: [{ name: "pasted-image.png" }] }])(
9+
"uses a readable image-only title with attachments $attachments",
10+
({ attachments }) => {
11+
expect(deriveThreadTitleSeed({ text: image, attachments })).toBe("Image: pasted-image.png");
12+
},
13+
);
14+
15+
it.each([`${image}\nFix the spacing`, `Fix ${image} the spacing`])(
16+
"prefers prose around image references: %s",
17+
(text) => {
18+
expect(deriveThreadTitleSeed({ text, attachments: [] })).toBe("Fix the spacing");
19+
},
20+
);
21+
22+
it("uses the first image label for several images", () => {
23+
expect(
24+
deriveThreadTitleSeed({
25+
text: `${image}\n![other.png](t3-context://v1/image/other)`,
26+
attachments: [],
27+
}),
28+
).toBe("Image: pasted-image.png");
29+
});
30+
31+
it("keeps context labels without exposing their internal URLs", () => {
32+
expect(
33+
deriveThreadTitleSeed({
34+
text: `${image} Fix [src/app.ts](t3-context://v1/mention/source) using [Build output](t3-context://v1/terminal/build)`,
35+
attachments: [],
36+
}),
37+
).toBe("Fix src/app.ts using Build output");
38+
});
39+
640
it("prefers normalized message text", () => {
741
expect(
842
deriveThreadTitleSeed({

‎packages/client-runtime/src/operations/threadTitle.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
2+
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
23
import { truncate } from "@t3tools/shared/String";
34

45
export interface ThreadTitleSeedInput {
@@ -11,8 +12,23 @@ function normalizeTitleSeed(value: string): string {
1112
return assistantCitationsToPlainText(value).trim().replace(/\s+/gu, " ");
1213
}
1314

15+
/** Prefer the request over image chips; image-only prompts still get a readable title. */
16+
export function threadTitleTextFromPrompt(value: string): string {
17+
let imageLabel: string | undefined;
18+
const prose = replaceComposerContextReferences(value, (reference) => {
19+
if (reference.kind === "image") {
20+
imageLabel ??= reference.label;
21+
return "";
22+
}
23+
return reference.label;
24+
});
25+
return (
26+
normalizeTitleSeed(prose) || (imageLabel ? `Image: ${normalizeTitleSeed(imageLabel)}` : "")
27+
);
28+
}
29+
1430
export function deriveThreadTitleSeed(input: ThreadTitleSeedInput): string {
15-
const text = normalizeTitleSeed(input.text);
31+
const text = threadTitleTextFromPrompt(input.text);
1632
if (text.length > 0) {
1733
return truncate(text);
1834
}

0 commit comments

Comments
 (0)