The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 09:45 UTC
fix(provider-core): thread title instructions override the generic title limits (#37565)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
fast-fourier-transfem | yuridkowskian catgirlmbinator committed
Nov 16, 2026 at 05:44 UTC
760f9cbe64e3409a7ebcc1ec16debe31a61e9f2b
6 files changed
+51
-11
apps/server/src/textGeneration/ClaudeTextGeneration.test.ts
+1
-1
@@ -188,7 +188,7 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
188
withFakeClaudeEnv(
189
{
190
output: JSON.stringify({ structured_output: { title: "Reconnect failures" } }),
191
- stdinMustContain: "Additional instructions:\nUse two to four words.",
191
+ stdinMustContain: "Title instructions from the user:\nUse two to four words.",
192
},
193
(textGeneration) =>
194
textGeneration.generateThreadTitle({
evals/thread-titles/README.md
+1
-1
@@ -17,4 +17,4 @@ pnpm thread-titles --model <codex model> --out runs/titles-new --baseline runs/t
17
18
## Add a case
19
20
-Add an entry to `cases.ts` with an `id`, a `source`, the thread `messages`, the `previousTitle`, an optional `projectTitle`, and a `rubric` that says what a good title names.
20
+Add an entry to `cases.ts` with an `id`, a `source`, the thread `messages`, the `previousTitle`, an optional `projectTitle`, optional `instructions` (the Thread title instructions setting), and a `rubric` that says what a good title names.
evals/thread-titles/cases.ts
+16
@@ -152,12 +152,28 @@ export const threadTitleEvaluationCases = [
152
],
153
rubric: "Name the default config on init. Leave out Hyperdrive, the project name.",
154
},
155
+ {
156
+ id: "custom-title-scheme",
157
+ source: "https://github.com/pingdotgg/t3code/pull/37565",
158
+ request: "Relay chat to the lead agent, titled with the user's naming scheme.",
159
+ previousTitle: "Relay chat to lead agent",
160
+ instructions: 'Title every thread "Owner: what it does (model effort)".',
161
+ messages: [
162
+ {
163
+ role: "user",
164
+ text: "Make the relay forward every chat message to the lead agent so reviewers can see questions from subagents.",
165
+ },
166
+ ],
167
+ rubric:
168
+ 'Use the user\'s "Owner: what it does (model effort)" shape with all three parts, even past the default 8-word, 40-character limit. A bare short title fails.',
169
+ },
170
] satisfies ReadonlyArray<{
171
id: string;
172
source: string;
173
request: string;
174
projectTitle?: string;
175
previousTitle: string;
176
+ instructions?: string;
177
messages: ReadonlyArray<ThreadTitleMessage>;
178
rubric: string;
179
}>;
evals/thread-titles/run.ts
+1
@@ -103,6 +103,7 @@ await Effect.runPromise(
103
cwd,
104
message,
105
...("projectTitle" in fixture ? { projectTitle: fixture.projectTitle } : {}),
106
+ ...("instructions" in fixture ? { instructions: fixture.instructions } : {}),
107
previousTitle: values.initial ? undefined : fixture.previousTitle,
108
attachments,
109
linkedContext,
packages/provider-core/src/server/textGenerationPrompts.test.ts
+7
-1
@@ -18,14 +18,20 @@ describe("normalizeCliError", () => {
18
});
19
20
describe("buildThreadTitlePrompt", () => {
21
- it("names the project to leave out of initial and regenerated titles", () => {
21
+ it("names the project to leave out and puts the user's instructions above the limits", () => {
22
for (const previousTitle of [undefined, "Hyperdrive Config Crash"]) {
23
const { prompt } = buildThreadTitlePrompt({
24
message: "hyperdrive init crashes without a config",
25
previousTitle,
26
projectTitle: "Hyperdrive",
27
+ instructions: "Prefix every title with the team name.",
28
});
29
expect(prompt).toContain('Never include the project name ("Hyperdrive")');
30
+ expect(prompt).not.toContain("fewer than 40 characters");
31
+ expect(prompt).toContain("Title instructions from the user:\nPrefix every title");
32
}
33
+ expect(buildThreadTitlePrompt({ message: "Fix login", instructions: " " }).prompt).toContain(
34
+ "3-8 words, fewer than 40 characters.",
35
+ );
36
});
37
});
packages/provider-core/src/server/textGenerationPrompts.ts
+25
-8
@@ -9,9 +9,12 @@ import type { TextGenerationPolicy } from "@t3tools/provider-core/server/textGen
9
10
const EARLIER_CONTENT_TRUNCATION_MARKER = "[Earlier content truncated]\n\n";
11
12
-function policyInstruction(instruction: string | undefined): ReadonlyArray<string> {
12
+function policyInstruction(
13
+ instruction: string | undefined,
14
+ heading = "Additional instructions:",
15
+): ReadonlyArray<string> {
16
const trimmed = instruction?.trim();
14
- return trimmed ? ["", "Additional instructions:", limitSection(trimmed, 20_000)] : [];
17
+ return trimmed ? ["", heading, limitSection(trimmed, 20_000)] : [];
18
}
19
20
export interface CommitMessagePromptInput {
@@ -375,8 +378,17 @@ function avoidRule(projectTitle: string | undefined, others: string): string {
378
: `- Avoid project names already visible in the UI, ${others}.`;
379
}
380
381
+function lengthRule(hasInstructions: boolean): string {
382
+ return hasInstructions
383
+ ? "- Follow the user's title instructions at the end of this prompt. Where they conflict with these rules, including on length and format, they win."
384
+ : "- 3-8 words, fewer than 40 characters.";
385
+}
386
+
387
// Keep shared editorial rules in these two prompts in sync.
379
-function initialThreadTitlePrompt(projectTitle: string | undefined): string {
388
+function initialThreadTitlePrompt(
389
+ projectTitle: string | undefined,
390
+ hasInstructions: boolean,
391
+): string {
392
return `Generate a title that will help the user recognize this T3 Code thread weeks later.
393
Return JSON with keys title and needsRefinement.
394
Set needsRefinement to true only if the subject is still unknown, such as an unresolved link, "fix this", or an unexplained attachment. Otherwise set it to false.
@@ -389,7 +401,7 @@ Before answering, silently reduce the request to:
401
Title the subject and outcome. Discard incidental instructions.
402
403
Editorial rules:
392
-- 3-8 words, fewer than 40 characters.
404
+${lengthRule(hasInstructions)}
405
- Use a compact noun phrase or clear action phrase.
406
- Capture the umbrella goal when the request lists several symptoms or steps.
407
- When asked about thread behavior, never include the referenced titles' topics. "[Fix login] why didn't this thread start?" means "Thread Startup Failure". Use linked topics only for requests about that work.
@@ -409,6 +421,7 @@ ${avoidRule(projectTitle, "quotes, labels, filler, and trailing punctuation")}
421
function regenerateThreadTitlePrompt(
422
previousTitle: string,
423
projectTitle: string | undefined,
424
+ hasInstructions: boolean,
425
): string {
426
return `Regenerate the title for an existing T3 Code thread so the user can recognize it weeks later.
427
The previous title was ${JSON.stringify(previousTitle)}.
@@ -421,7 +434,7 @@ Determine the title in this order:
434
4. Title the durable subject and desired outcome, not the current workflow state.
435
436
Editorial rules:
424
-- 3-8 words, fewer than 40 characters.
437
+${lengthRule(hasInstructions)}
438
- Use a compact noun phrase or clear action phrase.
439
- Preserve the umbrella subject when later messages focus on one finding, provider, platform, or implementation detail.
440
- When asked about thread behavior, never include the referenced titles' topics. "[Fix login] why didn't this thread start?" means "Thread Startup Failure". Use linked topics only for requests about that work.
@@ -467,7 +480,10 @@ ${limitTitleMessage(forkSource.history, 8_000)}`;
480
}
481
482
function threadTitlePromptSuffix(input: ThreadTitlePromptInput): string {
470
- const additionalInstructions = policyInstruction(input.instructions);
483
+ const additionalInstructions = policyInstruction(
484
+ input.instructions,
485
+ "Title instructions from the user:",
486
+ );
487
const attachmentLines = (input.attachments ?? []).map(
488
(attachment) => `- ${attachment.name} (${attachment.mimeType}, ${attachment.sizeBytes} bytes)`,
489
);
@@ -485,16 +501,17 @@ function threadTitlePromptSuffix(input: ThreadTitlePromptInput): string {
501
}
502
503
export function buildThreadTitlePrompt(input: ThreadTitlePromptInput) {
504
+ const hasInstructions = Boolean(input.instructions?.trim());
505
let prompt: string;
506
if (input.previousTitle === undefined) {
507
const message = limitTitleMessage(input.message, 8_000);
508
const label = input.forkSource === undefined ? "User message" : "User message after the fork";
492
- prompt = `${initialThreadTitlePrompt(input.projectTitle)}${forkSourceSection(input.forkSource)}\n\n${label}:\n${message}${threadTitlePromptSuffix(input)}`;
509
+ prompt = `${initialThreadTitlePrompt(input.projectTitle, hasInstructions)}${forkSourceSection(input.forkSource)}\n\n${label}:\n${message}${threadTitlePromptSuffix(input)}`;
510
} else {
511
const message = preserveMessageEnd(input.message);
512
const label =
513
input.forkSource === undefined ? "Thread contents" : "Thread contents after the fork";
497
- prompt = `${regenerateThreadTitlePrompt(input.previousTitle, input.projectTitle)}${forkSourceSection(input.forkSource)}\n\n${label}:\n${message}${threadTitlePromptSuffix(input)}`;
514
+ prompt = `${regenerateThreadTitlePrompt(input.previousTitle, input.projectTitle, hasInstructions)}${forkSourceSection(input.forkSource)}\n\n${label}:\n${message}${threadTitlePromptSuffix(input)}`;
515
}
516
const outputSchema = Schema.Struct({
517
title: Schema.String,