TypeScript
feat(settings): add thread title instructions (#21882)
Caden Elrod51273020db32
diff --git a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.tsindex bf242696c59..bf47c68297e 100644--- a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts+++ b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts@@ -115,6 +115,7 @@ const make = Effect.gen(function* () {message: context.message,attachments: context.attachments,...(input.kind.type === "regenerate" ? { previousTitle: projection.thread.title } : {}),+ instructions: settings.threadTitleInstructions,modelSelection: settings.textGenerationModelSelection,});const generatedTitle = result.title.trim();diff --git a/apps/server/src/textGeneration/ClaudeTextGeneration.test.ts b/apps/server/src/textGeneration/ClaudeTextGeneration.test.tsindex 7a12b47b2f9..3ea0502f83b 100644--- a/apps/server/src/textGeneration/ClaudeTextGeneration.test.ts+++ b/apps/server/src/textGeneration/ClaudeTextGeneration.test.ts@@ -270,6 +270,25 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {),);+ it.effect("sends thread title instructions to the provider prompt", () =>+ withFakeClaudeEnv(+ {+ output: JSON.stringify({ structured_output: { title: "Reconnect failures" } }),+ stdinMustContain: "Additional instructions:\nUse two to four words.",+ },+ (textGeneration) =>+ textGeneration.generateThreadTitle({+ cwd: process.cwd(),+ message: "Investigate reconnect failures",+ instructions: "Use two to four words.",+ modelSelection: {+ instanceId: ProviderInstanceId.make("claudeAgent"),+ model: SYNTHETIC_CLAUDE_STANDARD_MODEL,+ },+ }),+ ),+ );+it.effect("runs Claude text generation with the configured CLAUDE_CONFIG_DIR", () =>Effect.gen(function* () {const path = yield* Path.Path;diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsxindex c733fae9353..ec1e510ad16 100644--- a/apps/web/src/components/settings/SettingsPanels.tsx+++ b/apps/web/src/components/settings/SettingsPanels.tsx@@ -54,6 +54,7 @@ import { useScopedModelDisabledReason } from "./useScopedModelAvailability";import { useSettingsScope } from "./SettingsScopeContext";import { scopedIdleCompaction } from "./scopedSettings";import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";+import { ThreadTitleInstructionsSettings } from "./ThreadTitleInstructionsSettings";import { useDesktopUpdateState } from "../../state/desktopUpdate";import {getCustomModelOptionsByInstance,@@ -516,6 +517,9 @@ export function useSettingsRestore(onRestored?: () => void) {: []),...(settings.confirmQuit !== DEFAULT_UNIFIED_SETTINGS.confirmQuit ? ["Quit shortcut"] : []),...(isTextGenerationModelDirty ? ["Text generation model"] : []),+ ...(settings.threadTitleInstructions !== DEFAULT_UNIFIED_SETTINGS.threadTitleInstructions+ ? ["Thread title instructions"]+ : []),...getChangedBrowserSettingLabels(settings),...(settings.enableAgentBrowserAccess !== DEFAULT_UNIFIED_SETTINGS.enableAgentBrowserAccess? ["Agent browser access"]@@ -625,6 +629,7 @@ export function useSettingsRestore(onRestored?: () => void) {confirmThreadUnpin: DEFAULT_UNIFIED_SETTINGS.confirmThreadUnpin,confirmQuit: DEFAULT_UNIFIED_SETTINGS.confirmQuit,textGenerationModelSelection: DEFAULT_UNIFIED_SETTINGS.textGenerationModelSelection,+ threadTitleInstructions: DEFAULT_UNIFIED_SETTINGS.threadTitleInstructions,fontFamilySans: DEFAULT_UNIFIED_SETTINGS.fontFamilySans,fontFamilyComposer: DEFAULT_UNIFIED_SETTINGS.fontFamilyComposer,fontFamilyCode: DEFAULT_UNIFIED_SETTINGS.fontFamilyCode,@@ -1905,6 +1910,7 @@ export function GeneralSettingsPanel() {)}/>+ <ThreadTitleInstructionsSettings /></SettingsSection><SettingsSection id="about" title="About">diff --git a/apps/web/src/components/settings/ThreadTitleInstructionsSettings.tsx b/apps/web/src/components/settings/ThreadTitleInstructionsSettings.tsxnew file mode 100644index 00000000000..08797e2391d--- /dev/null+++ b/apps/web/src/components/settings/ThreadTitleInstructionsSettings.tsx@@ -0,0 +1,60 @@+import { useRef } from "react";++import { Textarea } from "../ui/textarea";+import { SettingsRow, SettingResetButton } from "./settingsLayout";+import { useSettingsScope } from "./SettingsScopeContext";+import { searchableSetting } from "./settingsSearch";+import {+ useScopedSettings,+ useScopedSettingsMixed,+ useUpdateScopedSettings,+} from "./useScopedSettings";++export function ThreadTitleInstructionsSettings() {+ const settings = useScopedSettings();+ const { targets } = useSettingsScope();+ const scopeKey = targets.map((target) => `${target.environmentId}:${target.projectId}`).join(",");+ const edited = useRef(false);+ const updateSettings = useUpdateScopedSettings();+ const mixed = useScopedSettingsMixed(["threadTitleInstructions"]);++ return (+ <SettingsRow+ serverScoped+ settingKeys={["threadTitleInstructions"]}+ {...searchableSetting("thread-title-instructions")}+ description="Appended to the prompt for new and regenerated thread titles."+ resetAction={+ mixed || settings.threadTitleInstructions !== "" ? (+ <SettingResetButton+ label="thread title instructions"+ onClick={() => updateSettings({ threadTitleInstructions: "" })}+ />+ ) : null+ }+ >+ <div className="mt-3 max-w-2xl pb-3.5">+ <Textarea+ key={`${scopeKey}:${mixed}:${settings.threadTitleInstructions}`}+ aria-label="Thread title instructions"+ onChange={() => {+ edited.current = true;+ }}+ rows={4}+ defaultValue={mixed ? "" : settings.threadTitleInstructions}+ placeholder={+ mixed+ ? "Mixed. Enter instructions to apply to all selected targets."+ : "Keep titles to a few words. Lead with the main subject."+ }+ onBlur={(event) => {+ const value = event.target.value.trim();+ if (edited.current && (mixed || value !== settings.threadTitleInstructions))+ updateSettings({ threadTitleInstructions: value });+ edited.current = false;+ }}+ />+ </div>+ </SettingsRow>+ );+}diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.tsindex c7c5f26ae90..f509af43a8d 100644--- a/apps/web/src/components/settings/settingsSearch.ts+++ b/apps/web/src/components/settings/settingsSearch.ts@@ -524,6 +524,13 @@ export const SETTINGS_SEARCH_ITEMS = [scope: "project-defaults",searchTerms: ["generated thread titles source control content default provider"],},+ {+ id: "thread-title-instructions",+ title: "Thread title instructions",+ to: "/settings/general",+ scope: "project-defaults",+ searchTerms: ["generated thread titles prompt custom style naming rename regenerate"],+ },{id: "app-version",title: "Version",diff --git a/docs/user/thread-sidebar.md b/docs/user/thread-sidebar.mdindex c64e95ec529..c2c02ca5be6 100644--- a/docs/user/thread-sidebar.md+++ b/docs/user/thread-sidebar.md@@ -107,6 +107,10 @@ To generate a fresh title from the conversation, open a thread's menu and choose**Regenerate title**. The action is unavailable while title generation is in progressor when the connected environment needs a server update.+To change how titles are written, add **Thread title instructions** in **Settings → General →+Text generation**, such as a length limit or an identifier to put first. They apply to new and+regenerated titles. Select a project to give it its own instructions.+Agents connected through T3 Code can use the same server-owned metadata workflow torename a thread, regenerate its title, or link and unlink a pull request. These changesappear on web, desktop, and mobile without requiring the originating browser to remaindiff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.tsindex fbe4d945cff..4d55e0e038f 100644--- a/packages/contracts/src/settings.ts+++ b/packages/contracts/src/settings.ts@@ -979,6 +979,7 @@ export const PROJECT_SCOPED_SERVER_SETTING_KEYS = ["enableAgentBrowserAccess","enableAgentDeviceAccess","textGenerationModelSelection",+ "threadTitleInstructions","sourceControlWriterModelSelection","reviewGuideModelSelection","reviewGuideInstructions",@@ -1022,6 +1023,7 @@ export const ProjectSettingsOverrides = Schema.Struct({enableAgentBrowserAccess: Schema.optionalKey(Schema.Boolean),enableAgentDeviceAccess: Schema.optionalKey(Schema.Boolean),textGenerationModelSelection: Schema.optionalKey(ModelSelection),+ threadTitleInstructions: Schema.optionalKey(TrimmedString),sourceControlWriterModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),reviewGuideModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),reviewGuideInstructions: Schema.optionalKey(TrimmedString),@@ -1265,6 +1267,7 @@ export const ServerSettings = Schema.Struct({}),),),+ threadTitleInstructions: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),branchNamingMode: BranchNamingMode.pipe(Schema.withDecodingDefault(Effect.succeed("static" as const)),),@@ -1587,6 +1590,7 @@ export const ServerSettingsPatch = Schema.Struct({worktreeSubmodules: Schema.optionalKey(Schema.NullOr(WorktreeSubmodules)),addProjectBaseDirectory: Schema.optionalKey(TrimmedString),textGenerationModelSelection: Schema.optionalKey(ModelSelectionPatch),+ threadTitleInstructions: Schema.optionalKey(TrimmedString),branchNamingMode: Schema.optionalKey(BranchNamingMode),branchNamePrefix: Schema.optionalKey(TrimmedString),branchNameInstructions: Schema.optionalKey(TrimmedString),diff --git a/packages/provider-core/src/server/textGeneration.ts b/packages/provider-core/src/server/textGeneration.tsindex 936a4c328b1..69436f41587 100644--- a/packages/provider-core/src/server/textGeneration.ts+++ b/packages/provider-core/src/server/textGeneration.ts@@ -61,6 +61,7 @@ export interface ThreadTitleGenerationInput {message: string;previousTitle?: string | undefined;attachments?: ReadonlyArray<ChatAttachment> | undefined;+ instructions?: string | undefined;modelSelection: ModelSelection;}diff --git a/packages/provider-core/src/server/textGenerationOperations.ts b/packages/provider-core/src/server/textGenerationOperations.tsindex 8036abb7839..4d4a21a2c65 100644--- a/packages/provider-core/src/server/textGenerationOperations.ts+++ b/packages/provider-core/src/server/textGenerationOperations.ts@@ -149,6 +149,7 @@ export function fromRunner(name: string, run: Runner): ProviderTextGeneration {previousTitle: input.previousTitle,linkedContext: input.linkedContext,attachments: input.attachments,+ instructions: input.instructions,}),});return {diff --git a/packages/provider-core/src/server/textGenerationPolicy.ts b/packages/provider-core/src/server/textGenerationPolicy.tsindex 422927373d3..1d244a635a7 100644--- a/packages/provider-core/src/server/textGenerationPolicy.ts+++ b/packages/provider-core/src/server/textGenerationPolicy.ts@@ -13,7 +13,6 @@ export const TextGenerationPolicy = Schema.Struct({commitInstructions: Schema.optional(Schema.String),changeRequestInstructions: Schema.optional(Schema.String),branchInstructions: Schema.optional(Schema.String),- threadTitleInstructions: Schema.optional(Schema.String),inferRepositoryConventions: Schema.Boolean,});export type TextGenerationPolicy = typeof TextGenerationPolicy.Type;diff --git a/packages/provider-core/src/server/textGenerationPrompts.ts b/packages/provider-core/src/server/textGenerationPrompts.tsindex 4cab8d1b9a2..fa002a60a51 100644--- a/packages/provider-core/src/server/textGenerationPrompts.ts+++ b/packages/provider-core/src/server/textGenerationPrompts.ts@@ -351,7 +351,7 @@ export interface ThreadTitlePromptInput {message: string;previousTitle?: string | undefined;attachments?: ReadonlyArray<ChatAttachment> | undefined;- policy?: TextGenerationPolicy | undefined;+ instructions?: string | undefined;}// Keep shared editorial rules in these two prompts in sync.@@ -430,7 +430,7 @@ function preserveMessageEnd(message: string): string {}function threadTitlePromptSuffix(input: ThreadTitlePromptInput): string {- const additionalInstructions = policyInstruction(input.policy?.threadTitleInstructions);+ const additionalInstructions = policyInstruction(input.instructions);const attachmentLines = (input.attachments ?? []).map((attachment) => `- ${attachment.name} (${attachment.mimeType}, ${attachment.sizeBytes} bytes)`,);