Skip to content

Commit 5127302

Browse files
CadenElYash-Singh1
andauthored
feat(settings): add thread title instructions (#21882)
Co-authored-by: Yash Singh <[email protected]>
1 parent 1c8e79e commit 5127302

11 files changed

Lines changed: 105 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const make = Effect.gen(function* () {
115115
message: context.message,
116116
attachments: context.attachments,
117117
...(input.kind.type === "regenerate" ? { previousTitle: projection.thread.title } : {}),
118+
instructions: settings.threadTitleInstructions,
118119
modelSelection: settings.textGenerationModelSelection,
119120
});
120121
const generatedTitle = result.title.trim();

‎apps/server/src/textGeneration/ClaudeTextGeneration.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,25 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
270270
),
271271
);
272272

273+
it.effect("sends thread title instructions to the provider prompt", () =>
274+
withFakeClaudeEnv(
275+
{
276+
output: JSON.stringify({ structured_output: { title: "Reconnect failures" } }),
277+
stdinMustContain: "Additional instructions:\nUse two to four words.",
278+
},
279+
(textGeneration) =>
280+
textGeneration.generateThreadTitle({
281+
cwd: process.cwd(),
282+
message: "Investigate reconnect failures",
283+
instructions: "Use two to four words.",
284+
modelSelection: {
285+
instanceId: ProviderInstanceId.make("claudeAgent"),
286+
model: SYNTHETIC_CLAUDE_STANDARD_MODEL,
287+
},
288+
}),
289+
),
290+
);
291+
273292
it.effect("runs Claude text generation with the configured CLAUDE_CONFIG_DIR", () =>
274293
Effect.gen(function* () {
275294
const path = yield* Path.Path;

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { useScopedModelDisabledReason } from "./useScopedModelAvailability";
5454
import { useSettingsScope } from "./SettingsScopeContext";
5555
import { scopedIdleCompaction } from "./scopedSettings";
5656
import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";
57+
import { ThreadTitleInstructionsSettings } from "./ThreadTitleInstructionsSettings";
5758
import { useDesktopUpdateState } from "../../state/desktopUpdate";
5859
import {
5960
getCustomModelOptionsByInstance,
@@ -516,6 +517,9 @@ export function useSettingsRestore(onRestored?: () => void) {
516517
: []),
517518
...(settings.confirmQuit !== DEFAULT_UNIFIED_SETTINGS.confirmQuit ? ["Quit shortcut"] : []),
518519
...(isTextGenerationModelDirty ? ["Text generation model"] : []),
520+
...(settings.threadTitleInstructions !== DEFAULT_UNIFIED_SETTINGS.threadTitleInstructions
521+
? ["Thread title instructions"]
522+
: []),
519523
...getChangedBrowserSettingLabels(settings),
520524
...(settings.enableAgentBrowserAccess !== DEFAULT_UNIFIED_SETTINGS.enableAgentBrowserAccess
521525
? ["Agent browser access"]
@@ -625,6 +629,7 @@ export function useSettingsRestore(onRestored?: () => void) {
625629
confirmThreadUnpin: DEFAULT_UNIFIED_SETTINGS.confirmThreadUnpin,
626630
confirmQuit: DEFAULT_UNIFIED_SETTINGS.confirmQuit,
627631
textGenerationModelSelection: DEFAULT_UNIFIED_SETTINGS.textGenerationModelSelection,
632+
threadTitleInstructions: DEFAULT_UNIFIED_SETTINGS.threadTitleInstructions,
628633
fontFamilySans: DEFAULT_UNIFIED_SETTINGS.fontFamilySans,
629634
fontFamilyComposer: DEFAULT_UNIFIED_SETTINGS.fontFamilyComposer,
630635
fontFamilyCode: DEFAULT_UNIFIED_SETTINGS.fontFamilyCode,
@@ -1905,6 +1910,7 @@ export function GeneralSettingsPanel() {
19051910
)
19061911
}
19071912
/>
1913+
<ThreadTitleInstructionsSettings />
19081914
</SettingsSection>
19091915

19101916
<SettingsSection id="about" title="About">
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { useRef } from "react";
2+
3+
import { Textarea } from "../ui/textarea";
4+
import { SettingsRow, SettingResetButton } from "./settingsLayout";
5+
import { useSettingsScope } from "./SettingsScopeContext";
6+
import { searchableSetting } from "./settingsSearch";
7+
import {
8+
useScopedSettings,
9+
useScopedSettingsMixed,
10+
useUpdateScopedSettings,
11+
} from "./useScopedSettings";
12+
13+
export function ThreadTitleInstructionsSettings() {
14+
const settings = useScopedSettings();
15+
const { targets } = useSettingsScope();
16+
const scopeKey = targets.map((target) => `${target.environmentId}:${target.projectId}`).join(",");
17+
const edited = useRef(false);
18+
const updateSettings = useUpdateScopedSettings();
19+
const mixed = useScopedSettingsMixed(["threadTitleInstructions"]);
20+
21+
return (
22+
<SettingsRow
23+
serverScoped
24+
settingKeys={["threadTitleInstructions"]}
25+
{...searchableSetting("thread-title-instructions")}
26+
description="Appended to the prompt for new and regenerated thread titles."
27+
resetAction={
28+
mixed || settings.threadTitleInstructions !== "" ? (
29+
<SettingResetButton
30+
label="thread title instructions"
31+
onClick={() => updateSettings({ threadTitleInstructions: "" })}
32+
/>
33+
) : null
34+
}
35+
>
36+
<div className="mt-3 max-w-2xl pb-3.5">
37+
<Textarea
38+
key={`${scopeKey}:${mixed}:${settings.threadTitleInstructions}`}
39+
aria-label="Thread title instructions"
40+
onChange={() => {
41+
edited.current = true;
42+
}}
43+
rows={4}
44+
defaultValue={mixed ? "" : settings.threadTitleInstructions}
45+
placeholder={
46+
mixed
47+
? "Mixed. Enter instructions to apply to all selected targets."
48+
: "Keep titles to a few words. Lead with the main subject."
49+
}
50+
onBlur={(event) => {
51+
const value = event.target.value.trim();
52+
if (edited.current && (mixed || value !== settings.threadTitleInstructions))
53+
updateSettings({ threadTitleInstructions: value });
54+
edited.current = false;
55+
}}
56+
/>
57+
</div>
58+
</SettingsRow>
59+
);
60+
}

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ export const SETTINGS_SEARCH_ITEMS = [
524524
scope: "project-defaults",
525525
searchTerms: ["generated thread titles source control content default provider"],
526526
},
527+
{
528+
id: "thread-title-instructions",
529+
title: "Thread title instructions",
530+
to: "/settings/general",
531+
scope: "project-defaults",
532+
searchTerms: ["generated thread titles prompt custom style naming rename regenerate"],
533+
},
527534
{
528535
id: "app-version",
529536
title: "Version",

‎docs/user/thread-sidebar.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ To generate a fresh title from the conversation, open a thread's menu and choose
107107
**Regenerate title**. The action is unavailable while title generation is in progress
108108
or when the connected environment needs a server update.
109109

110+
To change how titles are written, add **Thread title instructions** in **Settings → General →
111+
Text generation**, such as a length limit or an identifier to put first. They apply to new and
112+
regenerated titles. Select a project to give it its own instructions.
113+
110114
Agents connected through T3 Code can use the same server-owned metadata workflow to
111115
rename a thread, regenerate its title, or link and unlink a pull request. These changes
112116
appear on web, desktop, and mobile without requiring the originating browser to remain

‎packages/contracts/src/settings.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ export const PROJECT_SCOPED_SERVER_SETTING_KEYS = [
979979
"enableAgentBrowserAccess",
980980
"enableAgentDeviceAccess",
981981
"textGenerationModelSelection",
982+
"threadTitleInstructions",
982983
"sourceControlWriterModelSelection",
983984
"reviewGuideModelSelection",
984985
"reviewGuideInstructions",
@@ -1022,6 +1023,7 @@ export const ProjectSettingsOverrides = Schema.Struct({
10221023
enableAgentBrowserAccess: Schema.optionalKey(Schema.Boolean),
10231024
enableAgentDeviceAccess: Schema.optionalKey(Schema.Boolean),
10241025
textGenerationModelSelection: Schema.optionalKey(ModelSelection),
1026+
threadTitleInstructions: Schema.optionalKey(TrimmedString),
10251027
sourceControlWriterModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
10261028
reviewGuideModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
10271029
reviewGuideInstructions: Schema.optionalKey(TrimmedString),
@@ -1265,6 +1267,7 @@ export const ServerSettings = Schema.Struct({
12651267
}),
12661268
),
12671269
),
1270+
threadTitleInstructions: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
12681271
branchNamingMode: BranchNamingMode.pipe(
12691272
Schema.withDecodingDefault(Effect.succeed("static" as const)),
12701273
),
@@ -1587,6 +1590,7 @@ export const ServerSettingsPatch = Schema.Struct({
15871590
worktreeSubmodules: Schema.optionalKey(Schema.NullOr(WorktreeSubmodules)),
15881591
addProjectBaseDirectory: Schema.optionalKey(TrimmedString),
15891592
textGenerationModelSelection: Schema.optionalKey(ModelSelectionPatch),
1593+
threadTitleInstructions: Schema.optionalKey(TrimmedString),
15901594
branchNamingMode: Schema.optionalKey(BranchNamingMode),
15911595
branchNamePrefix: Schema.optionalKey(TrimmedString),
15921596
branchNameInstructions: Schema.optionalKey(TrimmedString),

‎packages/provider-core/src/server/textGeneration.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface ThreadTitleGenerationInput {
6161
message: string;
6262
previousTitle?: string | undefined;
6363
attachments?: ReadonlyArray<ChatAttachment> | undefined;
64+
instructions?: string | undefined;
6465
modelSelection: ModelSelection;
6566
}
6667

‎packages/provider-core/src/server/textGenerationOperations.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export function fromRunner(name: string, run: Runner): ProviderTextGeneration {
149149
previousTitle: input.previousTitle,
150150
linkedContext: input.linkedContext,
151151
attachments: input.attachments,
152+
instructions: input.instructions,
152153
}),
153154
});
154155
return {

‎packages/provider-core/src/server/textGenerationPolicy.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const TextGenerationPolicy = Schema.Struct({
1313
commitInstructions: Schema.optional(Schema.String),
1414
changeRequestInstructions: Schema.optional(Schema.String),
1515
branchInstructions: Schema.optional(Schema.String),
16-
threadTitleInstructions: Schema.optional(Schema.String),
1716
inferRepositoryConventions: Schema.Boolean,
1817
});
1918
export type TextGenerationPolicy = typeof TextGenerationPolicy.Type;

0 commit comments

Comments
 (0)