diff --git a/src/renderer/src/components/new-workspace/AutoRenameBranchHint.tsx b/src/renderer/src/components/new-workspace/AutoRenameBranchHint.tsx index c7127f83d..a5f7ed3e4 100644 --- a/src/renderer/src/components/new-workspace/AutoRenameBranchHint.tsx +++ b/src/renderer/src/components/new-workspace/AutoRenameBranchHint.tsx @@ -19,8 +19,8 @@ export default function AutoRenameBranchHint(): React.JSX.Element { const closeModal = useAppStore((s) => s.closeModal) const handleOpenSettings = React.useCallback((): void => { - // Why: the setting lives in the Git pane; closing the composer first keeps - // the settings page from rendering behind the modal. + // Why: the toggle lives in the Git settings page (Git AI Author pane); + // closing the composer first keeps it from rendering behind the modal. closeModal() openSettingsTarget({ pane: 'git', repoId: null }) openSettingsPage() diff --git a/src/renderer/src/components/settings/AutoRenameBranchFromWorkSetting.tsx b/src/renderer/src/components/settings/AutoRenameBranchFromWorkSetting.tsx deleted file mode 100644 index dd747ddbb..000000000 --- a/src/renderer/src/components/settings/AutoRenameBranchFromWorkSetting.tsx +++ /dev/null @@ -1,419 +0,0 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from 'react' -import { ChevronDown } from 'lucide-react' -import type { GlobalSettings } from '../../../../shared/types' -import type { - SourceControlAiModelChoice, - SourceControlAiSettingsPatch, - SourceControlAiSettings -} from '../../../../shared/source-control-ai-types' -import { - clearSourceControlAiModelChoiceForHost, - normalizeSourceControlAiSettings, - readSourceControlAiModelChoiceForHost, - selectSourceControlAiModelChoiceForHost -} from '../../../../shared/source-control-ai' -import { - getCommitMessageAgentCapability, - isCustomAgentId, - resolveCommitMessageAgentChoice, - type CommitMessageAgentCapability, - type CommitMessageModelCapability -} from '../../../../shared/commit-message-agent-spec' -import { - getCommitMessageModelDiscoveryHostKeyForScope, - LOCAL_COMMIT_MESSAGE_HOST_KEY -} from '../../../../shared/commit-message-host-key' -import { getConnectionId } from '@/lib/connection-context' -import { cn } from '@/lib/utils' -import { getRuntimeGitScope } from '../../runtime/runtime-git-client' -import { useAppStore } from '../../store' -import { useActiveWorktree } from '../../store/selectors' -import { Button } from '../ui/button' -import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible' -import { Label } from '../ui/label' -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select' -import { AUTO_RENAME_BRANCH_ADVANCED_SEARCH_ENTRIES } from './auto-rename-branch-search' -import { AutoRenameBranchPromptEditor } from './AutoRenameBranchPromptEditor' -import { SearchableSetting } from './SearchableSetting' -import { matchesSettingsSearch, normalizeSettingsSearchQuery } from './settings-search' - -type AutoRenameBranchFromWorkSettingProps = { - settings: GlobalSettings - updateSettings: (updates: Partial) => void | Promise - writeSourceControlAiSettings: (patch: SourceControlAiSettingsPatch) => Promise - forceVisible?: boolean - onBranchPromptDirtyChange?: (dirty: boolean) => void - branchPromptDiscardSignal?: number - settingsSearchQuery?: string -} - -const INHERIT_BRANCH_MODEL_VALUE = '__inherit_branch_model__' -export function shouldOpenAutoRenameBranchAdvanced(searchQuery: string): boolean { - return ( - normalizeSettingsSearchQuery(searchQuery) !== '' && - matchesSettingsSearch(searchQuery, AUTO_RENAME_BRANCH_ADVANCED_SEARCH_ENTRIES) - ) -} - -function readSourceControlSettings(settings: GlobalSettings): SourceControlAiSettings { - return normalizeSourceControlAiSettings(settings.sourceControlAi, settings.commitMessageAi) -} - -function mergeModelCapabilities( - fallbackModels: CommitMessageModelCapability[], - discoveredModels: CommitMessageModelCapability[] | undefined -): CommitMessageModelCapability[] { - const models: CommitMessageModelCapability[] = [] - const seen = new Set() - for (const model of [...(discoveredModels ?? []), ...fallbackModels]) { - if (!model.id || seen.has(model.id)) { - continue - } - seen.add(model.id) - models.push(model) - } - return models -} - -function getCapabilityWithDiscoveredModels( - config: SourceControlAiSettings, - capability: CommitMessageAgentCapability, - hostKey: string -): CommitMessageAgentCapability { - const discoveredModels = - config.discoveredModelsByAgentByHost?.[hostKey]?.[capability.id] ?? - (hostKey === LOCAL_COMMIT_MESSAGE_HOST_KEY - ? config.discoveredModelsByAgent?.[capability.id] - : undefined) - const models = mergeModelCapabilities(capability.models, discoveredModels) - const defaultModelId = models.some((model) => model.id === capability.defaultModelId) - ? capability.defaultModelId - : (models[0]?.id ?? capability.defaultModelId) - return { ...capability, models, defaultModelId } -} - -function resolveSelectedThinking( - config: SourceControlAiSettings, - model: CommitMessageModelCapability, - operationChoice: SourceControlAiModelChoice | undefined -): string | undefined { - if (!model.thinkingLevels) { - return undefined - } - const persisted = - operationChoice?.selectedThinkingByModel?.[model.id] ?? config.selectedThinkingByModel[model.id] - return model.thinkingLevels.some((level) => level.id === persisted) - ? persisted - : model.defaultThinkingLevel -} - -export function AutoRenameBranchFromWorkSetting({ - settings, - updateSettings, - writeSourceControlAiSettings, - forceVisible = false, - onBranchPromptDirtyChange, - branchPromptDiscardSignal, - settingsSearchQuery -}: AutoRenameBranchFromWorkSettingProps): React.JSX.Element { - const storeSearchQuery = useAppStore((state) => state.settingsSearchQuery) - const searchQuery = settingsSearchQuery ?? storeSearchQuery - const activeWorktree = useActiveWorktree() - const activeConnectionId = getConnectionId(activeWorktree?.id ?? null) - const discoveryHostKey = getCommitMessageModelDiscoveryHostKeyForScope( - activeWorktree?.id ? getRuntimeGitScope(settings, activeConnectionId) : activeConnectionId - ) - const config = readSourceControlSettings(settings) - const [optionsOpen, setOptionsOpen] = useState(false) - const advancedSearchOpen = shouldOpenAutoRenameBranchAdvanced(searchQuery) - const advancedOpen = optionsOpen || advancedSearchOpen - const persistedBranchNamePrompt = config.instructionsByOperation.branchName ?? '' - const persistedBranchNamePromptRef = useRef(persistedBranchNamePrompt) - persistedBranchNamePromptRef.current = persistedBranchNamePrompt - const [branchNamePromptDraft, setBranchNamePromptDraft] = useState(persistedBranchNamePrompt) - const [isSavingPrompt, setIsSavingPrompt] = useState(false) - const branchNamePromptDirty = branchNamePromptDraft !== persistedBranchNamePrompt - - useEffect(() => { - if (!branchNamePromptDirty) { - setBranchNamePromptDraft(persistedBranchNamePrompt) - } - }, [branchNamePromptDirty, persistedBranchNamePrompt]) - - useEffect(() => { - setBranchNamePromptDraft(persistedBranchNamePromptRef.current) - // Why: Settings owns the discard confirmation, but the draft lives here so - // the row can keep its prompt-specific save/discard affordances. - }, [branchPromptDiscardSignal]) - - useEffect(() => { - onBranchPromptDirtyChange?.(branchNamePromptDirty) - }, [branchNamePromptDirty, onBranchPromptDirtyChange]) - - const onBranchPromptDirtyChangeRef = useRef(onBranchPromptDirtyChange) - onBranchPromptDirtyChangeRef.current = onBranchPromptDirtyChange - const setSettingRootRef = useCallback((node: HTMLDivElement | null): void => { - if (node !== null) { - return - } - // Why: Settings owns the global unsaved-branch-prompt guard; reset it - // when this setting detaches without a passive cleanup-only Effect. - onBranchPromptDirtyChangeRef.current?.(false) - }, []) - - const resolvedAgentId = resolveCommitMessageAgentChoice( - config.agentId, - settings.defaultTuiAgent, - settings.disabledTuiAgents - ) - const activeAgentId = - resolvedAgentId && !isCustomAgentId(resolvedAgentId) ? resolvedAgentId : null - const activeCapability = useMemo(() => { - if (!activeAgentId) { - return undefined - } - const capability = getCommitMessageAgentCapability(activeAgentId) - return capability - ? getCapabilityWithDiscoveredModels(config, capability, discoveryHostKey) - : undefined - }, [activeAgentId, config, discoveryHostKey]) - const branchModelChoice = config.modelOverridesByOperation?.branchName - const branchModelOverrideId = activeCapability - ? readSourceControlAiModelChoiceForHost( - branchModelChoice, - discoveryHostKey, - activeCapability.id - ) - : undefined - const selectedBranchModel = branchModelOverrideId - ? activeCapability?.models.find((model) => model.id === branchModelOverrideId) - : undefined - const selectedBranchThinking = selectedBranchModel - ? resolveSelectedThinking(config, selectedBranchModel, branchModelChoice) - : undefined - - const onBranchModelChange = (modelId: string): void => { - if (!activeCapability) { - return - } - if (modelId === INHERIT_BRANCH_MODEL_VALUE) { - void writeSourceControlAiSettings((current) => { - const nextOverrides = { ...current.modelOverridesByOperation } - const nextChoice = clearSourceControlAiModelChoiceForHost( - nextOverrides.branchName, - discoveryHostKey, - activeCapability.id - ) - if (nextChoice) { - nextOverrides.branchName = nextChoice - } else { - delete nextOverrides.branchName - } - return { modelOverridesByOperation: nextOverrides } - }) - return - } - const model = activeCapability.models.find((candidate) => candidate.id === modelId) - if (!model) { - return - } - void writeSourceControlAiSettings((current) => { - const nextChoice = selectSourceControlAiModelChoiceForHost( - current.modelOverridesByOperation?.branchName, - discoveryHostKey, - activeCapability.id, - model.id - ) - if ( - model.thinkingLevels && - model.defaultThinkingLevel && - !nextChoice.selectedThinkingByModel?.[model.id] - ) { - nextChoice.selectedThinkingByModel = { - ...nextChoice.selectedThinkingByModel, - [model.id]: model.defaultThinkingLevel - } - } - return { - modelOverridesByOperation: { - ...current.modelOverridesByOperation, - branchName: nextChoice - } - } - }) - } - - const onBranchThinkingChange = (modelId: string, thinkingId: string): void => { - void writeSourceControlAiSettings((current) => ({ - modelOverridesByOperation: { - ...current.modelOverridesByOperation, - branchName: { - ...current.modelOverridesByOperation?.branchName, - selectedThinkingByModel: { - ...current.modelOverridesByOperation?.branchName?.selectedThinkingByModel, - [modelId]: thinkingId - } - } - } - })) - } - - const onSavePrompt = async (): Promise => { - if (!branchNamePromptDirty || isSavingPrompt) { - return - } - setIsSavingPrompt(true) - try { - await writeSourceControlAiSettings((current) => ({ - instructionsByOperation: { - ...current.instructionsByOperation, - branchName: branchNamePromptDraft - } - })) - } finally { - setIsSavingPrompt(false) - } - } - - const onDiscardPrompt = (): void => { - setBranchNamePromptDraft(persistedBranchNamePrompt) - } - - return ( - -
-
- -

- When a blank new workspace starts work, Orca uses the first task to rename the sidebar - title and unpublished generated branch (e.g. Nautilus). Workspaces created - from linked issues or pull requests are named up front from the same short identity. -

-
- -
- - - - - - -
- - -
-
- -

- Use a different model for branch name generation. -

-
- {activeCapability ? ( -
- - {selectedBranchModel?.thinkingLevels && selectedBranchThinking ? ( -
- Thinking - -
- ) : null} -
- ) : ( -

- Choose a Git AI Author agent that supports model selection. -

- )} -
-
-
-
-
- ) -} diff --git a/src/renderer/src/components/settings/AutoRenameBranchPromptEditor.tsx b/src/renderer/src/components/settings/AutoRenameBranchPromptEditor.tsx index 620dc4d08..2532691ff 100644 --- a/src/renderer/src/components/settings/AutoRenameBranchPromptEditor.tsx +++ b/src/renderer/src/components/settings/AutoRenameBranchPromptEditor.tsx @@ -26,9 +26,11 @@ export function AutoRenameBranchPromptEditor({ onSave }: AutoRenameBranchPromptEditorProps): React.JSX.Element { return ( -
+ // Why: py-2 matches the sibling rows so the editor doesn't hug the group's + // divide-y divider the way the model/prompt rows are spaced. +
- +

Appended to Orca's{' '} diff --git a/src/renderer/src/components/settings/CommitMessageAiPane.test.tsx b/src/renderer/src/components/settings/CommitMessageAiPane.test.tsx index 92bc0b285..bcf9439bd 100644 --- a/src/renderer/src/components/settings/CommitMessageAiPane.test.tsx +++ b/src/renderer/src/components/settings/CommitMessageAiPane.test.tsx @@ -50,7 +50,8 @@ describe('CommitMessageAiPane', () => { const state = createCommitMessageInstructionDraftState( { commitMessage: 'commit-a', - pullRequest: 'pr-a' + pullRequest: 'pr-a', + branchName: 'branch-a' }, 1 ) @@ -59,14 +60,16 @@ describe('CommitMessageAiPane', () => { state, { commitMessage: 'commit-b', - pullRequest: 'pr-a' + pullRequest: 'pr-a', + branchName: 'branch-b' }, 1 ) expect(resolved.draft).toEqual({ commitMessage: 'commit-b', - pullRequest: 'pr-a' + pullRequest: 'pr-a', + branchName: 'branch-b' }) }) @@ -74,7 +77,8 @@ describe('CommitMessageAiPane', () => { const state = createCommitMessageInstructionDraftState( { commitMessage: 'commit-a', - pullRequest: 'pr-a' + pullRequest: 'pr-a', + branchName: 'branch-a' }, 1 ) @@ -84,26 +88,30 @@ describe('CommitMessageAiPane', () => { state, { commitMessage: 'commit-b', - pullRequest: 'pr-b' + pullRequest: 'pr-b', + branchName: 'branch-b' }, 1 ) expect(withExternalChange.draft).toEqual({ commitMessage: 'local edit', - pullRequest: 'pr-b' + pullRequest: 'pr-b', + branchName: 'branch-b' }) const afterDiscard = resolveCommitMessageInstructionDraftState( withExternalChange, { commitMessage: 'commit-b', - pullRequest: 'pr-b' + pullRequest: 'pr-b', + branchName: 'branch-b' }, 2 ) expect(afterDiscard.draft).toEqual({ commitMessage: 'commit-b', - pullRequest: 'pr-b' + pullRequest: 'pr-b', + branchName: 'branch-b' }) }) @@ -115,9 +123,40 @@ describe('CommitMessageAiPane', () => { expect(markup).toContain('aria-checked="false"') expect(markup).not.toContain('Orca invokes this CLI') expect(markup).not.toContain('Thinking Effort') + // The auto-name toggle depends on Git AI Author, so it is hidden while off. + expect(markup).not.toContain('Auto-name new workspaces from first message') }) - it('renders model, thinking, and collapsed commit and PR customization for enabled preset agents', () => { + it('renders the auto-name toggle once Git AI Author is enabled', () => { + const markup = renderPane( + buildSettings({ + autoRenameBranchFromWork: true, + commitMessageAi: { + enabled: true, + agentId: 'codex', + selectedModelByAgent: { codex: 'gpt-5.5' }, + selectedThinkingByModel: { 'gpt-5.5': 'medium' }, + customPrompt: '', + customAgentCommand: '' + } + }) + ) + + expect(markup).toContain('Auto-name new workspaces from first message') + // Tuning lives in the Advanced -> Branch Names group, not on the toggle row. + expect(markup).toContain('Tune the model and prompt under Advanced') + }) + + it('surfaces the enable row when searching for auto-name while the feature is off', () => { + const markup = renderPane(buildSettings(), 'auto-name') + + // Why: the toggle can't render while disabled, so an auto-name search should + // still guide the user to the Enable Git AI Author row. + expect(markup).toContain('Enable Git AI Author') + expect(markup).not.toContain('Auto-name new workspaces from first message') + }) + + it('renders model, thinking, and collapsed advanced customization for enabled preset agents', () => { const markup = renderPane( buildSettings({ commitMessageAi: { @@ -135,13 +174,16 @@ describe('CommitMessageAiPane', () => { expect(markup).toContain('Orca invokes this CLI') expect(markup).toContain('Model') expect(markup).toContain('Thinking Effort') - expect(markup).toContain('Commit and PR customization') + expect(markup).toContain('Advanced') expect(markup).toContain('aria-expanded="false"') - expect(markup).not.toContain('Commit Messages') - expect(markup).not.toContain('Pull Requests') + // Match the group headings specifically: the auto-name toggle copy mentions + // "Branch Names", but the collapsed group heading must not be rendered. + expect(markup).not.toContain('>Commit Messages') + expect(markup).not.toContain('>Pull Requests') + expect(markup).not.toContain('>Branch Names') expect(markup).not.toContain('Use a different model for commit message generation.') expect(markup).not.toContain('Creation defaults') - expect(markup).not.toContain('Branch name model') + expect(markup).not.toContain('Use a different model for branch name generation.') expect(markup).not.toContain('Higher effort produces more careful messages') expect(markup).not.toContain('Use Conventional Commits.') expect(markup).not.toContain('Saved') @@ -153,10 +195,11 @@ describe('CommitMessageAiPane', () => { expect(markup).toContain('Git AI Author') expect(markup).toContain('Enable Git AI Author') expect(markup).toContain('aria-checked="false"') - expect(markup).not.toContain('Commit and PR customization') + expect(markup).not.toContain('aria-expanded="false"') + expect(markup).not.toContain('Branch Names') }) - it('opens commit and PR customization for matching settings search terms', () => { + it('opens advanced customization for matching settings search terms', () => { const markup = renderPane( buildSettings({ commitMessageAi: { @@ -174,9 +217,30 @@ describe('CommitMessageAiPane', () => { expect(markup).toContain('aria-expanded="true"') expect(markup).toContain('Commit Messages') expect(markup).toContain('Pull Requests') + expect(markup).toContain('Branch Names') expect(markup).toContain('Creation defaults') }) + it('shows the nested branch name model control for branch name model search', () => { + const markup = renderPane( + buildSettings({ + commitMessageAi: { + enabled: true, + agentId: 'codex', + selectedModelByAgent: { codex: 'gpt-5.5' }, + selectedThinkingByModel: { 'gpt-5.5': 'medium' }, + customPrompt: '', + customAgentCommand: '' + } + }), + 'branch name model' + ) + + expect(markup).toContain('aria-expanded="true"') + expect(markup).toContain('Branch Names') + expect(markup).toContain('Use a different model for branch name generation.') + }) + it('shows the nested commit model control for commit message model search', () => { const markup = renderPane( buildSettings({ diff --git a/src/renderer/src/components/settings/CommitMessageAiPane.tsx b/src/renderer/src/components/settings/CommitMessageAiPane.tsx index deb1812ca..2e884788b 100644 --- a/src/renderer/src/components/settings/CommitMessageAiPane.tsx +++ b/src/renderer/src/components/settings/CommitMessageAiPane.tsx @@ -43,6 +43,8 @@ import { } from '../../runtime/runtime-git-client' import { useAppStore } from '../../store' import { useActiveWorktree } from '../../store/selectors' +import { AutoRenameBranchPromptEditor } from './AutoRenameBranchPromptEditor' +import { AUTO_RENAME_BRANCH_PARENT_SEARCH_ENTRY } from './auto-rename-branch-search' import { SearchableSetting } from './SearchableSetting' import { COMMIT_MESSAGE_AI_PANE_SEARCH_ENTRIES } from './commit-message-ai-search' import { matchesSettingsSearch } from './settings-search' @@ -66,7 +68,7 @@ type ModelDiscoveryState = { type CommitMessageInstructionOperation = Extract< SourceControlAiOperation, - 'commitMessage' | 'pullRequest' + 'commitMessage' | 'pullRequest' | 'branchName' > type CommitMessageInstructionDraftValues = Record @@ -79,7 +81,8 @@ type CommitMessageInstructionDraftState = { const COMMIT_MESSAGE_INSTRUCTION_OPERATIONS: readonly CommitMessageInstructionOperation[] = [ 'commitMessage', - 'pullRequest' + 'pullRequest', + 'branchName' ] function cloneInstructionDraftValues( @@ -87,7 +90,8 @@ function cloneInstructionDraftValues( ): CommitMessageInstructionDraftValues { return { commitMessage: values.commitMessage, - pullRequest: values.pullRequest + pullRequest: values.pullRequest, + branchName: values.branchName } } @@ -301,9 +305,11 @@ export function CommitMessageAiPane({ const [outputOverridesOpen, setOutputOverridesOpen] = useState(false) const persistedCommitInstructions = config.instructionsByOperation.commitMessage ?? '' const persistedPullRequestInstructions = config.instructionsByOperation.pullRequest ?? '' + const persistedBranchNameInstructions = config.instructionsByOperation.branchName ?? '' const persistedInstructionDraftValues: CommitMessageInstructionDraftValues = { commitMessage: persistedCommitInstructions, - pullRequest: persistedPullRequestInstructions + pullRequest: persistedPullRequestInstructions, + branchName: persistedBranchNameInstructions } const [instructionDraftState, setInstructionDraftState] = useState(() => createCommitMessageInstructionDraftState( @@ -324,6 +330,7 @@ export function CommitMessageAiPane({ } const commitInstructionsDraft = resolvedInstructionDraftState.draft.commitMessage const pullRequestInstructionsDraft = resolvedInstructionDraftState.draft.pullRequest + const branchNameInstructionsDraft = resolvedInstructionDraftState.draft.branchName const updateInstructionDraft = ( operation: CommitMessageInstructionOperation, value: string @@ -346,11 +353,16 @@ export function CommitMessageAiPane({ const isCommitInstructionsDirty = commitInstructionsDraft !== persistedCommitInstructions const isPullRequestInstructionsDirty = pullRequestInstructionsDraft !== persistedPullRequestInstructions - const isCustomPromptDirty = isCommitInstructionsDirty || isPullRequestInstructionsDirty + const isBranchNameInstructionsDirty = + branchNameInstructionsDraft !== persistedBranchNameInstructions + const isCustomPromptDirty = + isCommitInstructionsDirty || isPullRequestInstructionsDirty || isBranchNameInstructionsDirty const commitPromptDraft = commitInstructionsDraft const pullRequestPromptDraft = pullRequestInstructionsDraft + const branchNamePromptDraft = branchNameInstructionsDraft const isCommitPromptDirty = isCommitInstructionsDirty const isPullRequestPromptDirty = isPullRequestInstructionsDirty + const isBranchNamePromptDirty = isBranchNameInstructionsDirty const isSavingPrompt = isSavingInstructions useEffect(() => { @@ -788,9 +800,12 @@ export function CommitMessageAiPane({ const onSavePrompt = async (operation: CommitMessageInstructionOperation): Promise => { const draft = resolvedInstructionDraftState.draft[operation] - const dirty = - operation === 'commitMessage' ? isCommitInstructionsDirty : isPullRequestInstructionsDirty - if (!dirty || isSavingInstructions) { + const dirtyByOperation: Record = { + commitMessage: isCommitInstructionsDirty, + pullRequest: isPullRequestInstructionsDirty, + branchName: isBranchNameInstructionsDirty + } + if (!dirtyByOperation[operation] || isSavingInstructions) { return } setIsSavingInstructions(true) @@ -1182,15 +1197,68 @@ export function CommitMessageAiPane({ ) } + // Why: auto-name fires automatically and runs through the same agent as the + // other operations, so it can't work unless Git AI Author is on — keep its + // toggle here (gated on config.enabled) rather than orphaned in Git settings. + if ( + config.enabled && + matchesSettingsSearch(searchQuery, AUTO_RENAME_BRANCH_PARENT_SEARCH_ENTRY) + ) { + sections.push( + +

+ +

+ When a blank new workspace starts work, Orca uses the first task to rename the sidebar + title and unpublished generated branch (e.g. Nautilus). Workspaces created + from linked issues or pull requests are named up front from the same short identity. + Tune the model and prompt under Advanced → Branch Names below. +

+
+ + + ) + } + const commitMessagesGroupEntry = { title: 'Commit Messages', description: 'Commit message generation settings.', keywords: ['commit', 'message', 'model', 'prompt', 'conventional commits'] } const commitAndPrCustomizationEntry = { - title: 'Commit and PR customization', - description: 'Configure behavior for commit message generation and PR creation.', - keywords: ['customization', 'advanced', 'commit', 'pull request', 'pr', 'model', 'prompt'] + title: 'Advanced', + description: + 'Override the model and prompt for commit messages, pull requests, and branch names.', + keywords: [ + 'customization', + 'advanced', + 'commit', + 'pull request', + 'pr', + 'branch', + 'name', + 'model', + 'prompt' + ] } const commitAndPrCustomizationMatches = config.enabled && matchesSettingsSearch(searchQuery, commitAndPrCustomizationEntry) @@ -1277,6 +1345,51 @@ export function CommitMessageAiPane({
) : null + const branchNamesGroupEntry = { + title: 'Branch Names', + description: 'Branch name generation settings for auto-named workspaces.', + keywords: ['branch', 'name', 'rename', 'model', 'prompt', 'slug', 'workspace'] + } + const branchNamesGroupMatches = + config.enabled && matchesSettingsSearch(searchQuery, branchNamesGroupEntry) + const branchNamePromptMatches = matchesSettingsSearch(searchQuery, { + title: 'Branch name prompt', + description: 'Additional prompt text appended only when generating branch names.', + keywords: ['prompt', 'instructions', 'built-in prompt', 'slug', 'kebab-case'] + }) + const branchNameChildren = [ + renderOperationModelControls( + 'branchName', + 'Model', + 'Use a different model for branch name generation.', + ['model', 'override', 'branch', 'name', 'branch name model', 'slug', 'thinking'], + branchNamesGroupMatches || commitAndPrCustomizationMatches + ), + (config.enabled || isBranchNamePromptDirty) && + (branchNamesGroupMatches || + commitAndPrCustomizationMatches || + isBranchNamePromptDirty || + branchNamePromptMatches) ? ( + updateInstructionDraft('branchName', value)} + onDiscard={() => onDiscardPrompt('branchName')} + onSave={() => void onSavePrompt('branchName')} + /> + ) : null + ].filter(Boolean) + + const branchNamesGroup = + branchNameChildren.length > 0 ? ( +
+

Branch Names

+
{branchNameChildren}
+
+ ) : null + const pullRequestsGroupEntry = { title: 'Pull Requests', description: 'Pull request authoring and creation settings.', @@ -1423,13 +1536,16 @@ export function CommitMessageAiPane({
) : null - const outputOverrideChildren = [commitMessagesGroup, pullRequestsGroup].filter(Boolean) + const outputOverrideChildren = [commitMessagesGroup, pullRequestsGroup, branchNamesGroup].filter( + Boolean + ) const outputOverridesSearchOpen = searchQuery.trim() !== '' && outputOverrideChildren.length > 0 const outputOverridesVisible = outputOverridesOpen || outputOverridesSearchOpen || isCommitPromptDirty || - isPullRequestPromptDirty + isPullRequestPromptDirty || + isBranchNamePromptDirty if (outputOverrideChildren.length > 0) { sections.push( @@ -1444,11 +1560,7 @@ export function CommitMessageAiPane({ diff --git a/src/renderer/src/components/settings/GitPane.test.ts b/src/renderer/src/components/settings/GitPane.test.ts index 26a36f634..f33094003 100644 --- a/src/renderer/src/components/settings/GitPane.test.ts +++ b/src/renderer/src/components/settings/GitPane.test.ts @@ -3,8 +3,7 @@ import { renderToStaticMarkup } from 'react-dom/server' import { describe, expect, it } from 'vitest' import { getDefaultSettings } from '../../../../shared/constants' import { useAppStore } from '../../store' -import { shouldOpenAutoRenameBranchAdvanced } from './AutoRenameBranchFromWorkSetting' -import { GitPane, shouldShowAutoRenameBranchSetting } from './GitPane' +import { GitPane } from './GitPane' function renderGitPane(searchQuery: string): string { useAppStore.setState({ settingsSearchQuery: searchQuery }) @@ -12,7 +11,6 @@ function renderGitPane(searchQuery: string): string { React.createElement(GitPane, { settings: getDefaultSettings('/tmp'), updateSettings: () => {}, - writeSourceControlAiSettings: async () => {}, displayedGitUsername: 'brennan', settingsSearchQuery: searchQuery }) @@ -20,37 +18,16 @@ function renderGitPane(searchQuery: string): string { } describe('GitPane', () => { - it('keeps the auto-rename branch setting visible while its prompt draft is dirty', () => { - expect(shouldShowAutoRenameBranchSetting('zz-no-match', true)).toBe(true) + it('still renders its own git settings (e.g. Branch Prefix) on a matching search', () => { + expect(renderGitPane('branch prefix')).toContain('Branch Prefix') }) - it('shows the auto-rename branch setting for advanced prompt and model searches', () => { - expect(shouldShowAutoRenameBranchSetting('instructions', false)).toBe(true) - expect(shouldShowAutoRenameBranchSetting('built-in prompt', false)).toBe(true) - expect(shouldShowAutoRenameBranchSetting('thinking', false)).toBe(true) - expect(shouldShowAutoRenameBranchSetting('override', false)).toBe(true) - }) - - it('hides the auto-rename branch setting when search misses and the prompt draft is clean', () => { - expect(shouldShowAutoRenameBranchSetting('zz-no-match', false)).toBe(false) - }) - - it('opens auto-rename advanced controls when search matches hidden prompt or model fields', () => { - expect(shouldOpenAutoRenameBranchAdvanced('prompt')).toBe(true) - expect(shouldOpenAutoRenameBranchAdvanced('model')).toBe(true) - expect(shouldOpenAutoRenameBranchAdvanced('instructions')).toBe(true) - expect(shouldOpenAutoRenameBranchAdvanced('built-in prompt')).toBe(true) - expect(shouldOpenAutoRenameBranchAdvanced('thinking')).toBe(true) - expect(shouldOpenAutoRenameBranchAdvanced('override')).toBe(true) - }) - - it('renders auto-rename advanced controls for advanced-only search terms', () => { - expect(renderGitPane('instructions')).toContain('Branch name prompt') - expect(renderGitPane('thinking')).toContain('Branch name model') - }) - - it('keeps auto-rename advanced controls collapsed without an advanced search match', () => { - expect(shouldOpenAutoRenameBranchAdvanced('')).toBe(false) - expect(shouldOpenAutoRenameBranchAdvanced('creature name')).toBe(false) + it('no longer renders the auto-name toggle or the relocated branch-name controls', () => { + // Why: the auto-name toggle moved to the Git AI Author pane (it depends on + // that feature), and its model/prompt tuning lives under Advanced -> Branch Names. + const markup = renderGitPane('rename') + expect(markup).not.toContain('Auto-name new workspaces from first message') + expect(markup).not.toContain('Branch name prompt') + expect(markup).not.toContain('Branch name model') }) }) diff --git a/src/renderer/src/components/settings/GitPane.tsx b/src/renderer/src/components/settings/GitPane.tsx index dab96fe01..448120ac4 100644 --- a/src/renderer/src/components/settings/GitPane.tsx +++ b/src/renderer/src/components/settings/GitPane.tsx @@ -1,5 +1,4 @@ import type { GlobalSettings } from '../../../../shared/types' -import type { SourceControlAiSettingsPatch } from '../../../../shared/source-control-ai-types' import { Input } from '../ui/input' import { Label } from '../ui/label' import { useAppStore } from '../../store' @@ -7,41 +6,21 @@ import { GIT_PANE_SEARCH_ENTRIES } from './git-search' import { SearchableSetting } from './SearchableSetting' import { matchesSettingsSearch } from './settings-search' import { GitHubRateLimitPanel } from '../github/github-rate-limit-display' -import { AutoRenameBranchFromWorkSetting } from './AutoRenameBranchFromWorkSetting' -import { AUTO_RENAME_BRANCH_SEARCH_ENTRIES } from './auto-rename-branch-search' import { GitLabRateLimitPanel } from '../gitlab/gitlab-rate-limit-display' export { GIT_PANE_SEARCH_ENTRIES } -export function shouldShowAutoRenameBranchSetting( - searchQuery: string, - hasUnsavedBranchPromptChanges: boolean -): boolean { - return ( - hasUnsavedBranchPromptChanges || - matchesSettingsSearch(searchQuery, AUTO_RENAME_BRANCH_SEARCH_ENTRIES) - ) -} - type GitPaneProps = { settings: GlobalSettings updateSettings: (updates: Partial) => void | Promise - writeSourceControlAiSettings: (patch: SourceControlAiSettingsPatch) => Promise displayedGitUsername: string - hasUnsavedBranchPromptChanges?: boolean - onBranchPromptDirtyChange?: (dirty: boolean) => void - branchPromptDiscardSignal?: number settingsSearchQuery?: string } export function GitPane({ settings, updateSettings, - writeSourceControlAiSettings, displayedGitUsername, - hasUnsavedBranchPromptChanges = false, - onBranchPromptDirtyChange, - branchPromptDiscardSignal, settingsSearchQuery }: GitPaneProps): React.JSX.Element { const storeSearchQuery = useAppStore((s) => s.settingsSearchQuery) @@ -162,18 +141,6 @@ export function GitPane({ ) : null, - shouldShowAutoRenameBranchSetting(searchQuery, hasUnsavedBranchPromptChanges) ? ( - - ) : null, matchesSettingsSearch(searchQuery, { title: 'GitHub API Budget', description: 'Current GitHub CLI REST, Search, and GraphQL rate limits.', diff --git a/src/renderer/src/components/settings/Settings.tsx b/src/renderer/src/components/settings/Settings.tsx index 5ab65112a..77d643a5f 100644 --- a/src/renderer/src/components/settings/Settings.tsx +++ b/src/renderer/src/components/settings/Settings.tsx @@ -239,7 +239,6 @@ function Settings(): React.JSX.Element { const [pendingNavRequestTick, setPendingNavRequestTick] = useState(0) const [quickCommandAddIntentSignal, setQuickCommandAddIntentSignal] = useState(0) const [hasUnsavedCommitPromptChanges, setHasUnsavedCommitPromptChanges] = useState(false) - const [hasUnsavedBranchPromptChanges, setHasUnsavedBranchPromptChanges] = useState(false) const [sourceControlAiPromptDiscardSignal, setSourceControlAiPromptDiscardSignal] = useState(0) const confirm = useConfirmationDialog() // Why: the hidden-experimental group is an unlock — Shift-clicking the @@ -258,8 +257,9 @@ function Settings(): React.JSX.Element { const shortcutsEscapeConfirmUntilRef = useRef(0) const sourceControlAiWriteQueueRef = useRef>(Promise.resolve()) - const hasUnsavedSourceControlAiPromptChanges = - hasUnsavedCommitPromptChanges || hasUnsavedBranchPromptChanges + // Why: the commit pane now owns every Git AI Author prompt draft (commit, PR, + // and branch name), so its single dirty signal covers all unsaved prompt edits. + const hasUnsavedSourceControlAiPromptChanges = hasUnsavedCommitPromptChanges const writeSourceControlAiSettings = useCallback( (patch: SourceControlAiSettingsPatch): Promise => { @@ -315,7 +315,6 @@ function Settings(): React.JSX.Element { if (shouldDiscard) { setSourceControlAiPromptDiscardSignal((signal) => signal + 1) setHasUnsavedCommitPromptChanges(false) - setHasUnsavedBranchPromptChanges(false) } return shouldDiscard }, [confirm, hasUnsavedSourceControlAiPromptChanges]) @@ -1040,11 +1039,7 @@ function Settings(): React.JSX.Element {