Skip to content
Closed
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
24 changes: 24 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_git_pull_request_prompt",
rename = "gitPullRequestPrompt"
)]
pub(crate) git_pull_request_prompt: String,
#[serde(
default = "default_system_notifications_enabled",
rename = "systemNotificationsEnabled"
Expand Down Expand Up @@ -924,6 +929,20 @@ fn default_git_diff_ignore_whitespace_changes() -> bool {
false
}

fn default_git_pull_request_prompt() -> String {
[
"You are reviewing a GitHub pull request.",
"PR: #{{number}} {{title}}",
"URL: {{url}}",
"Author: @{{author}}",
"Branches: {{baseRef}} <- {{headRef}}",
"Updated: {{updatedAt}}{{draftState}}{{descriptionSection}}",
"",
"Diff: {{diffSummary}}{{questionSection}}",
]
.join("\n")
}

fn default_experimental_collab_enabled() -> bool {
false
}
Expand Down Expand Up @@ -1169,6 +1188,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(),
git_pull_request_prompt: default_git_pull_request_prompt(),
experimental_collab_enabled: false,
collaboration_modes_enabled: true,
steer_enabled: true,
Expand Down Expand Up @@ -1329,6 +1349,10 @@ mod tests {
assert!(settings.system_notifications_enabled);
assert!(settings.preload_git_diffs);
assert!(!settings.git_diff_ignore_whitespace_changes);
assert_eq!(
settings.git_pull_request_prompt,
default_git_pull_request_prompt()
);
assert!(settings.collaboration_modes_enabled);
assert!(settings.steer_enabled);
assert!(settings.unified_exec_enabled);
Expand Down
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,7 @@ function MainApp() {
activeWorkspace,
selectedPullRequest,
gitPullRequestDiffs,
gitPullRequestPromptTemplate: appSettings.gitPullRequestPrompt,
filePanelMode,
gitPanelMode,
centerMode,
Expand Down
3 changes: 3 additions & 0 deletions src/features/git/hooks/usePullRequestComposer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const makeOptions = (overrides: Partial<Parameters<typeof usePullRequestComposer
activeWorkspace: connectedWorkspace,
selectedPullRequest: null,
gitPullRequestDiffs: diffs,
gitPullRequestPromptTemplate: "Default template",
filePanelMode: "git" as const,
gitPanelMode: "prs" as const,
centerMode: "diff" as const,
Expand Down Expand Up @@ -141,6 +142,7 @@ describe("usePullRequestComposer", () => {
pullRequest,
diffs,
"Question?",
"Default template",
);
expect(options.startThreadForWorkspace).toHaveBeenCalledWith(
disconnectedWorkspace.id,
Expand Down Expand Up @@ -193,6 +195,7 @@ describe("usePullRequestComposer", () => {
pullRequest,
diffs,
"/src-tauri/something",
"Default template",
);
expect(options.startThreadForWorkspace).toHaveBeenCalledWith(
connectedWorkspace.id,
Expand Down
4 changes: 4 additions & 0 deletions src/features/git/hooks/usePullRequestComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type UsePullRequestComposerOptions = {
activeWorkspace: WorkspaceInfo | null;
selectedPullRequest: GitHubPullRequest | null;
gitPullRequestDiffs: GitHubPullRequestDiff[];
gitPullRequestPromptTemplate: string;
filePanelMode: "git" | "files" | "prompts";
gitPanelMode: "diff" | "log" | "issues" | "prs";
centerMode: "chat" | "diff";
Expand Down Expand Up @@ -40,6 +41,7 @@ export function usePullRequestComposer({
activeWorkspace,
selectedPullRequest,
gitPullRequestDiffs,
gitPullRequestPromptTemplate,
filePanelMode,
gitPanelMode,
centerMode,
Expand Down Expand Up @@ -120,6 +122,7 @@ export function usePullRequestComposer({
selectedPullRequest,
gitPullRequestDiffs,
trimmed,
gitPullRequestPromptTemplate,
);
const threadId = await startThreadForWorkspace(activeWorkspace.id, {
activate: false,
Expand All @@ -135,6 +138,7 @@ export function usePullRequestComposer({
clearActiveImages,
connectWorkspace,
gitPullRequestDiffs,
gitPullRequestPromptTemplate,
handleSend,
selectedPullRequest,
sendUserMessageToThread,
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_PULL_REQUEST_PROMPT_TEMPLATE } from "../../../utils/pullRequestPrompt";
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,
gitPullRequestPrompt: DEFAULT_PULL_REQUEST_PROMPT_TEMPLATE,
experimentalCollabEnabled: false,
collaborationModesEnabled: true,
steerEnabled: true,
Expand Down
54 changes: 54 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_PULL_REQUEST_PROMPT_TEMPLATE } from "../../../utils/pullRequestPrompt";
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 [gitPullRequestPromptDraft, setGitPullRequestPromptDraft] = useState(
appSettings.gitPullRequestPrompt,
);
const [gitPullRequestPromptSaving, setGitPullRequestPromptSaving] = 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(() => {
setGitPullRequestPromptDraft(appSettings.gitPullRequestPrompt);
}, [appSettings.gitPullRequestPrompt]);

useEffect(() => {
setScaleDraft(`${Math.round(clampUiScale(appSettings.uiScale) * 100)}%`);
}, [appSettings.uiScale]);
Expand Down Expand Up @@ -528,6 +537,8 @@ export function SettingsView({
const codexDirty =
nextCodexBin !== (appSettings.codexBin ?? null) ||
nextCodexArgs !== (appSettings.codexArgs ?? null);
const gitPullRequestPromptDirty =
gitPullRequestPromptDraft !== appSettings.gitPullRequestPrompt;

const trimmedScale = scaleDraft.trim();
const parsedPercent = trimmedScale
Expand All @@ -548,6 +559,43 @@ export function SettingsView({
}
};

const handleSaveGitPullRequestPrompt = useCallback(async () => {
if (!gitPullRequestPromptDirty) {
return;
}
const nextValue = gitPullRequestPromptDraft.trim()
? gitPullRequestPromptDraft
: DEFAULT_PULL_REQUEST_PROMPT_TEMPLATE;
setGitPullRequestPromptSaving(true);
setGitPullRequestPromptDraft(nextValue);
try {
await onUpdateAppSettings({
...appSettings,
gitPullRequestPrompt: nextValue,
});
} finally {
setGitPullRequestPromptSaving(false);
}
}, [
appSettings,
gitPullRequestPromptDirty,
gitPullRequestPromptDraft,
onUpdateAppSettings,
]);

const handleResetGitPullRequestPrompt = useCallback(async () => {
setGitPullRequestPromptSaving(true);
setGitPullRequestPromptDraft(DEFAULT_PULL_REQUEST_PROMPT_TEMPLATE);
try {
await onUpdateAppSettings({
...appSettings,
gitPullRequestPrompt: DEFAULT_PULL_REQUEST_PROMPT_TEMPLATE,
});
} finally {
setGitPullRequestPromptSaving(false);
}
}, [appSettings, onUpdateAppSettings]);

const updateRemoteBackendSettings = useCallback(
async ({
host,
Expand Down Expand Up @@ -1431,6 +1479,12 @@ export function SettingsView({
<SettingsGitSection
appSettings={appSettings}
onUpdateAppSettings={onUpdateAppSettings}
gitPullRequestPromptDraft={gitPullRequestPromptDraft}
gitPullRequestPromptDirty={gitPullRequestPromptDirty}
gitPullRequestPromptSaving={gitPullRequestPromptSaving}
onSetGitPullRequestPromptDraft={setGitPullRequestPromptDraft}
onSaveGitPullRequestPrompt={handleSaveGitPullRequestPrompt}
onResetGitPullRequestPrompt={handleResetGitPullRequestPrompt}
/>
)}
{activeSection === "server" && (
Expand Down
55 changes: 54 additions & 1 deletion src/features/settings/components/sections/SettingsGitSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ import type { AppSettings } from "../../../../types";
type SettingsGitSectionProps = {
appSettings: AppSettings;
onUpdateAppSettings: (next: AppSettings) => Promise<void>;
gitPullRequestPromptDraft: string;
gitPullRequestPromptDirty: boolean;
gitPullRequestPromptSaving: boolean;
onSetGitPullRequestPromptDraft: (next: string) => void;
onSaveGitPullRequestPrompt: () => Promise<void>;
onResetGitPullRequestPrompt: () => Promise<void>;
};

export function SettingsGitSection({
appSettings,
onUpdateAppSettings,
gitPullRequestPromptDraft,
gitPullRequestPromptDirty,
gitPullRequestPromptSaving,
onSetGitPullRequestPromptDraft,
onSaveGitPullRequestPrompt,
onResetGitPullRequestPrompt,
}: SettingsGitSectionProps) {
return (
<section className="settings-section">
<div className="settings-section-title">Git</div>
<div className="settings-section-subtitle">
Manage how diffs are loaded in the Git sidebar.
Manage how diffs are loaded and pull request prompts are composed.
</div>
<div className="settings-toggle-row">
<div>
Expand Down Expand Up @@ -55,6 +67,47 @@ export function SettingsGitSection({
<span className="settings-toggle-knob" />
</button>
</div>
<div className="settings-field">
<label className="settings-field-label" htmlFor="git-pr-prompt">
Pull request prompt
</label>
<div className="settings-help">
Template used when asking questions about GitHub pull requests. Available tokens:{" "}
<code>{"{{number}}"}</code>, <code>{"{{title}}"}</code>,{" "}
<code>{"{{url}}"}</code>, <code>{"{{author}}"}</code>,{" "}
<code>{"{{baseRef}}"}</code>, <code>{"{{headRef}}"}</code>,{" "}
<code>{"{{updatedAt}}"}</code>, <code>{"{{draftState}}"}</code>,{" "}
<code>{"{{descriptionSection}}"}</code>, <code>{"{{diffSummary}}"}</code>,{" "}
<code>{"{{questionSection}}"}</code>.
</div>
<textarea
id="git-pr-prompt"
className="settings-agents-textarea"
value={gitPullRequestPromptDraft}
onChange={(event) => onSetGitPullRequestPromptDraft(event.target.value)}
placeholder="Describe the pull request context for Codex…"
spellCheck={false}
disabled={gitPullRequestPromptSaving}
/>
<div className="settings-field-actions">
<button
type="button"
className="ghost settings-button-compact"
onClick={() => void onResetGitPullRequestPrompt()}
disabled={gitPullRequestPromptSaving}
>
Reset
</button>
<button
type="button"
className="primary settings-button-compact"
onClick={() => void onSaveGitPullRequestPrompt()}
disabled={gitPullRequestPromptSaving || !gitPullRequestPromptDirty}
>
{gitPullRequestPromptSaving ? "Saving..." : "Save"}
</button>
</div>
</div>
</section>
);
}
5 changes: 5 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_PULL_REQUEST_PROMPT_TEMPLATE } from "../../../utils/pullRequestPrompt";

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,
gitPullRequestPrompt: DEFAULT_PULL_REQUEST_PROMPT_TEMPLATE,
experimentalCollabEnabled: false,
collaborationModesEnabled: true,
steerEnabled: true,
Expand Down Expand Up @@ -133,6 +135,9 @@ function normalizeAppSettings(settings: AppSettings): AppSettings {
DEFAULT_CODE_FONT_FAMILY,
),
codeFontSize: clampCodeFontSize(settings.codeFontSize),
gitPullRequestPrompt: settings.gitPullRequestPrompt?.trim()
? settings.gitPullRequestPrompt
: DEFAULT_PULL_REQUEST_PROMPT_TEMPLATE,
personality: allowedPersonality.has(settings.personality)
? settings.personality
: "friendly",
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;
gitPullRequestPrompt: string;
experimentalCollabEnabled: boolean;
collaborationModesEnabled: boolean;
steerEnabled: boolean;
Expand Down
Loading
Loading