Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src-tauri/src/bin/codex_monitor_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,14 @@ impl DaemonState {
if diff.trim().is_empty() {
return Err("No changes to generate commit message for".to_string());
}
Ok(codex_aux_core::build_commit_message_prompt(&diff))
let commit_message_prompt = {
let settings = self.app_settings.lock().await;
settings.commit_message_prompt.clone()
};
Ok(codex_aux_core::build_commit_message_prompt(
&diff,
&commit_message_prompt,
))
}

async fn generate_commit_message(&self, workspace_id: String) -> Result<String, String> {
Expand All @@ -1122,7 +1129,14 @@ impl DaemonState {
if diff.trim().is_empty() {
return Err("No changes to generate commit message for".to_string());
}
let prompt = codex_aux_core::build_commit_message_prompt(&diff);
let commit_message_prompt = {
let settings = self.app_settings.lock().await;
settings.commit_message_prompt.clone()
};
let prompt = codex_aux_core::build_commit_message_prompt(
&diff,
&commit_message_prompt,
);
let response = codex_aux_core::run_background_prompt_core(
&self.sessions,
workspace_id,
Expand Down
15 changes: 14 additions & 1 deletion src-tauri/src/codex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,14 @@ pub(crate) async fn get_commit_message_prompt(
return Err("No changes to generate commit message for".to_string());
}

let commit_message_prompt = {
let settings = state.app_settings.lock().await;
settings.commit_message_prompt.clone()
};

Ok(crate::shared::codex_aux_core::build_commit_message_prompt(
&diff,
&commit_message_prompt,
))
}

Expand Down Expand Up @@ -632,7 +638,14 @@ pub(crate) async fn generate_commit_message(
return Err("No changes to generate commit message for".to_string());
}

let prompt = crate::shared::codex_aux_core::build_commit_message_prompt(&diff);
let commit_message_prompt = {
let settings = state.app_settings.lock().await;
settings.commit_message_prompt.clone()
};
let prompt = crate::shared::codex_aux_core::build_commit_message_prompt(
&diff,
&commit_message_prompt,
);
let response = crate::shared::codex_aux_core::run_background_prompt_core(
&state.sessions,
workspace_id,
Expand Down
19 changes: 14 additions & 5 deletions src-tauri/src/shared/codex_aux_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ use crate::backend::app_server::{
use crate::shared::process_core::tokio_command;
use crate::types::AppSettings;

pub(crate) fn build_commit_message_prompt(diff: &str) -> String {
format!(
"Generate a concise git commit message for the following changes. \
const DEFAULT_COMMIT_MESSAGE_PROMPT: &str = "Generate a concise git commit message for the following changes. \
Follow conventional commit format (e.g., feat:, fix:, refactor:, docs:, etc.). \
Keep the summary line under 72 characters. \
Only output the commit message, nothing else.\n\n\
Changes:\n{diff}"
)
Changes:\n{diff}";

pub(crate) fn build_commit_message_prompt(diff: &str, template: &str) -> String {
let base = if template.trim().is_empty() {
DEFAULT_COMMIT_MESSAGE_PROMPT
} else {
template
};
if base.contains("{diff}") {
base.replace("{diff}", diff)
} else {
format!("{base}\n\nChanges:\n{diff}")
}
}

pub(crate) fn build_run_metadata_prompt(cleaned_prompt: &str) -> String {
Expand Down
16 changes: 16 additions & 0 deletions src-tauri/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,11 @@ pub(crate) struct AppSettings {
rename = "gitDiffIgnoreWhitespaceChanges"
)]
pub(crate) git_diff_ignore_whitespace_changes: bool,
#[serde(
default = "default_commit_message_prompt",
rename = "commitMessagePrompt"
)]
pub(crate) commit_message_prompt: String,
#[serde(
default = "default_system_notifications_enabled",
rename = "systemNotificationsEnabled"
Expand Down Expand Up @@ -924,6 +929,15 @@ fn default_git_diff_ignore_whitespace_changes() -> bool {
false
}

fn default_commit_message_prompt() -> String {
"Generate a concise git commit message for the following changes. \
Follow conventional commit format (e.g., feat:, fix:, refactor:, docs:, etc.). \
Keep the summary line under 72 characters. \
Only output the commit message, nothing else.\n\n\
Changes:\n{diff}"
.to_string()
}

fn default_experimental_collab_enabled() -> bool {
false
}
Expand Down Expand Up @@ -1169,6 +1183,7 @@ impl Default for AppSettings {
system_notifications_enabled: true,
preload_git_diffs: default_preload_git_diffs(),
git_diff_ignore_whitespace_changes: default_git_diff_ignore_whitespace_changes(),
commit_message_prompt: default_commit_message_prompt(),
experimental_collab_enabled: false,
collaboration_modes_enabled: true,
steer_enabled: true,
Expand Down Expand Up @@ -1329,6 +1344,7 @@ mod tests {
assert!(settings.system_notifications_enabled);
assert!(settings.preload_git_diffs);
assert!(!settings.git_diff_ignore_whitespace_changes);
assert!(settings.commit_message_prompt.contains("{diff}"));
assert!(settings.collaboration_modes_enabled);
assert!(settings.steer_enabled);
assert!(settings.unified_exec_enabled);
Expand Down
2 changes: 2 additions & 0 deletions src/features/settings/components/SettingsView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import type { ComponentProps } from "react";
import { describe, expect, it, vi } from "vitest";
import type { AppSettings, WorkspaceInfo } from "../../../types";
import { DEFAULT_COMMIT_MESSAGE_PROMPT } from "../../../utils/commitMessagePrompt";
import { SettingsView } from "./SettingsView";

vi.mock("@tauri-apps/plugin-dialog", () => ({
Expand Down Expand Up @@ -68,6 +69,7 @@ const baseSettings: AppSettings = {
systemNotificationsEnabled: true,
preloadGitDiffs: true,
gitDiffIgnoreWhitespaceChanges: false,
commitMessagePrompt: DEFAULT_COMMIT_MESSAGE_PROMPT,
experimentalCollabEnabled: false,
collaborationModesEnabled: true,
steerEnabled: true,
Expand Down
55 changes: 55 additions & 0 deletions src/features/settings/components/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
clampCodeFontSize,
normalizeFontFamily,
} from "../../../utils/fonts";
import { DEFAULT_COMMIT_MESSAGE_PROMPT } from "../../../utils/commitMessagePrompt";
import { useGlobalAgentsMd } from "../hooks/useGlobalAgentsMd";
import { useGlobalCodexConfigToml } from "../hooks/useGlobalCodexConfigToml";
import { useSettingsOpenAppDrafts } from "../hooks/useSettingsOpenAppDrafts";
Expand Down Expand Up @@ -208,6 +209,10 @@ export function SettingsView({
);
const [orbitAccessClientSecretRefDraft, setOrbitAccessClientSecretRefDraft] =
useState(appSettings.orbitAccessClientSecretRef ?? "");
const [commitMessagePromptDraft, setCommitMessagePromptDraft] = useState(
appSettings.commitMessagePrompt,
);
const [commitMessagePromptSaving, setCommitMessagePromptSaving] = useState(false);
const [orbitStatusText, setOrbitStatusText] = useState<string | null>(null);
const [orbitAuthCode, setOrbitAuthCode] = useState<string | null>(null);
const [orbitVerificationUrl, setOrbitVerificationUrl] = useState<string | null>(
Expand Down Expand Up @@ -419,6 +424,10 @@ export function SettingsView({
setOrbitAccessClientSecretRefDraft(appSettings.orbitAccessClientSecretRef ?? "");
}, [appSettings.orbitAccessClientSecretRef]);

useEffect(() => {
setCommitMessagePromptDraft(appSettings.commitMessagePrompt);
}, [appSettings.commitMessagePrompt]);

useEffect(() => {
setScaleDraft(`${Math.round(clampUiScale(appSettings.uiScale) * 100)}%`);
}, [appSettings.uiScale]);
Expand Down Expand Up @@ -447,6 +456,46 @@ export function SettingsView({
}
}, []);

const commitMessagePromptDirty =
commitMessagePromptDraft !== appSettings.commitMessagePrompt;

const handleSaveCommitMessagePrompt = useCallback(async () => {
if (commitMessagePromptSaving || !commitMessagePromptDirty) {
return;
}
setCommitMessagePromptSaving(true);
try {
await onUpdateAppSettings({
...appSettings,
commitMessagePrompt: commitMessagePromptDraft,
});
} finally {
setCommitMessagePromptSaving(false);
}
}, [
appSettings,
commitMessagePromptDirty,
commitMessagePromptDraft,
commitMessagePromptSaving,
onUpdateAppSettings,
]);

const handleResetCommitMessagePrompt = useCallback(async () => {
if (commitMessagePromptSaving) {
return;
}
setCommitMessagePromptDraft(DEFAULT_COMMIT_MESSAGE_PROMPT);
setCommitMessagePromptSaving(true);
try {
await onUpdateAppSettings({
...appSettings,
commitMessagePrompt: DEFAULT_COMMIT_MESSAGE_PROMPT,
});
} finally {
setCommitMessagePromptSaving(false);
}
}, [appSettings, commitMessagePromptSaving, onUpdateAppSettings]);

useEffect(() => {
setCodexBinOverrideDrafts((prev) =>
buildWorkspaceOverrideDrafts(
Expand Down Expand Up @@ -1431,6 +1480,12 @@ export function SettingsView({
<SettingsGitSection
appSettings={appSettings}
onUpdateAppSettings={onUpdateAppSettings}
commitMessagePromptDraft={commitMessagePromptDraft}
commitMessagePromptDirty={commitMessagePromptDirty}
commitMessagePromptSaving={commitMessagePromptSaving}
onSetCommitMessagePromptDraft={setCommitMessagePromptDraft}
onSaveCommitMessagePrompt={handleSaveCommitMessagePrompt}
onResetCommitMessagePrompt={handleResetCommitMessagePrompt}
/>
)}
{activeSection === "server" && (
Expand Down
48 changes: 48 additions & 0 deletions src/features/settings/components/sections/SettingsGitSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import type { AppSettings } from "../../../../types";
type SettingsGitSectionProps = {
appSettings: AppSettings;
onUpdateAppSettings: (next: AppSettings) => Promise<void>;
commitMessagePromptDraft: string;
commitMessagePromptDirty: boolean;
commitMessagePromptSaving: boolean;
onSetCommitMessagePromptDraft: (value: string) => void;
onSaveCommitMessagePrompt: () => Promise<void>;
onResetCommitMessagePrompt: () => Promise<void>;
};

export function SettingsGitSection({
appSettings,
onUpdateAppSettings,
commitMessagePromptDraft,
commitMessagePromptDirty,
commitMessagePromptSaving,
onSetCommitMessagePromptDraft,
onSaveCommitMessagePrompt,
onResetCommitMessagePrompt,
}: SettingsGitSectionProps) {
return (
<section className="settings-section">
Expand Down Expand Up @@ -55,6 +67,42 @@ export function SettingsGitSection({
<span className="settings-toggle-knob" />
</button>
</div>
<div className="settings-field">
<div className="settings-field-label">Commit message prompt</div>
<div className="settings-help">
Used when generating commit messages. Include <code>{"{diff}"}</code> to insert the
git diff.
</div>
<textarea
className="settings-agents-textarea"
value={commitMessagePromptDraft}
onChange={(event) => onSetCommitMessagePromptDraft(event.target.value)}
spellCheck={false}
disabled={commitMessagePromptSaving}
/>
<div className="settings-field-actions">
<button
type="button"
className="ghost settings-button-compact"
onClick={() => {
void onResetCommitMessagePrompt();
}}
disabled={commitMessagePromptSaving || !commitMessagePromptDirty}
>
Reset
</button>
<button
type="button"
className="primary settings-button-compact"
onClick={() => {
void onSaveCommitMessagePrompt();
}}
disabled={commitMessagePromptSaving || !commitMessagePromptDirty}
>
{commitMessagePromptSaving ? "Saving..." : "Save"}
</button>
</div>
</div>
</section>
);
}
7 changes: 7 additions & 0 deletions src/features/settings/hooks/useAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { normalizeOpenAppTargets } from "../../app/utils/openApp";
import { getDefaultInterruptShortcut, isMacPlatform } from "../../../utils/shortcuts";
import { isMobilePlatform } from "../../../utils/platformPaths";
import { DEFAULT_COMMIT_MESSAGE_PROMPT } from "../../../utils/commitMessagePrompt";

const allowedThemes = new Set(["system", "light", "dark", "dim"]);
const allowedPersonality = new Set(["friendly", "pragmatic"]);
Expand Down Expand Up @@ -72,6 +73,7 @@ function buildDefaultSettings(): AppSettings {
systemNotificationsEnabled: true,
preloadGitDiffs: true,
gitDiffIgnoreWhitespaceChanges: false,
commitMessagePrompt: DEFAULT_COMMIT_MESSAGE_PROMPT,
experimentalCollabEnabled: false,
collaborationModesEnabled: true,
steerEnabled: true,
Expand Down Expand Up @@ -118,6 +120,10 @@ function normalizeAppSettings(settings: AppSettings): AppSettings {
: hasStoredSelection
? storedOpenAppId
: normalizedTargets[0]?.id ?? DEFAULT_OPEN_APP_ID;
const commitMessagePrompt =
settings.commitMessagePrompt && settings.commitMessagePrompt.trim().length > 0
? settings.commitMessagePrompt
: DEFAULT_COMMIT_MESSAGE_PROMPT;
return {
...settings,
codexBin: settings.codexBin?.trim() ? settings.codexBin.trim() : null,
Expand All @@ -138,6 +144,7 @@ function normalizeAppSettings(settings: AppSettings): AppSettings {
: "friendly",
reviewDeliveryMode:
settings.reviewDeliveryMode === "detached" ? "detached" : "inline",
commitMessagePrompt,
openAppTargets: normalizedTargets,
selectedOpenAppId,
};
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export type AppSettings = {
systemNotificationsEnabled: boolean;
preloadGitDiffs: boolean;
gitDiffIgnoreWhitespaceChanges: boolean;
commitMessagePrompt: string;
experimentalCollabEnabled: boolean;
collaborationModesEnabled: boolean;
steerEnabled: boolean;
Expand Down
4 changes: 4 additions & 0 deletions src/utils/commitMessagePrompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const DEFAULT_COMMIT_MESSAGE_PROMPT = `Generate a concise git commit message for the following changes. Follow conventional commit format (e.g., feat:, fix:, refactor:, docs:, etc.). Keep the summary line under 72 characters. Only output the commit message, nothing else.

Changes:
{diff}`;