Compare commits

...
Author SHA1 Message Date
Julius Marminge cfa9fa566d Fix Electron dev env and streamline Git action toast
- Remove `ELECTRON_RUN_AS_NODE` before spawning `electronmon` in desktop dev script
- Replace detailed multi-step Git progress toast with a compact status message + optional Open PR action
2026-02-13 15:20:00 -08:00
Julius Marminge f4b1f43bd6 Move git action progress to toast and stop auto-opening PRs
- Keep the git action modal in selection mode while actions run in a dismissible progress toast
- Remove automatic `gh pr view --web` calls; only return PR metadata and open links on explicit user action
- Update server/web tests to assert no implicit PR browser open behavior
2026-02-13 15:07:17 -08:00
4 changed files with 146 additions and 137 deletions

No files matched your search

+4 -1
View File
@@ -15,10 +15,13 @@ await waitOn({
}); });
const command = process.platform === "win32" ? "electronmon.cmd" : "electronmon"; const command = process.platform === "win32" ? "electronmon.cmd" : "electronmon";
const childEnv = { ...process.env };
delete childEnv.ELECTRON_RUN_AS_NODE;
const child = spawn(command, ["dist-electron/main.js"], { const child = spawn(command, ["dist-electron/main.js"], {
stdio: "inherit", stdio: "inherit",
env: { env: {
...process.env, ...childEnv,
VITE_DEV_SERVER_URL: devServerUrl, VITE_DEV_SERVER_URL: devServerUrl,
}, },
}); });
+3 -4
View File
@@ -343,7 +343,7 @@ describe("GitManager", () => {
expect(result.push.status).toBe("skipped_up_to_date"); expect(result.push.status).toBe("skipped_up_to_date");
}); });
it("opens existing PR for commit/push/pr action", async () => { it("returns existing PR metadata for commit/push/pr action", async () => {
const repoDir = makeTempDir("t3code-git-manager-"); const repoDir = makeTempDir("t3code-git-manager-");
await initRepo(repoDir); await initRepo(repoDir);
await runGit(repoDir, ["checkout", "-b", "feature/existing-pr"]); await runGit(repoDir, ["checkout", "-b", "feature/existing-pr"]);
@@ -376,9 +376,7 @@ describe("GitManager", () => {
expect(result.pr.status).toBe("opened_existing"); expect(result.pr.status).toBe("opened_existing");
expect(result.pr.number).toBe(42); expect(result.pr.number).toBe(42);
expect( expect(ghCalls.some((call) => call.startsWith("pr view "))).toBe(false);
ghCalls.some((call) => call.startsWith("pr view feature/existing-pr --web")),
).toBe(true);
}); });
it("creates PR when one does not already exist", async () => { it("creates PR when one does not already exist", async () => {
@@ -422,6 +420,7 @@ describe("GitManager", () => {
expect( expect(
ghCalls.some((call) => call.includes("pr create --base main --head feature-create-pr")), ghCalls.some((call) => call.includes("pr create --base main --head feature-create-pr")),
).toBe(true); ).toBe(true);
expect(ghCalls.some((call) => call.startsWith("pr view "))).toBe(false);
}); });
it("rejects push/pr actions from detached HEAD", async () => { it("rejects push/pr actions from detached HEAD", async () => {
-10
View File
@@ -325,7 +325,6 @@ export class GitManager {
const existing = await this.findOpenPr(cwd, branch); const existing = await this.findOpenPr(cwd, branch);
if (existing) { if (existing) {
await this.openPrInBrowser(cwd, branch);
return { return {
status: "opened_existing", status: "opened_existing",
url: existing.url, url: existing.url,
@@ -381,7 +380,6 @@ export class GitManager {
} }
const created = await this.findOpenPr(cwd, branch); const created = await this.findOpenPr(cwd, branch);
await this.openPrInBrowser(cwd, branch);
if (!created) { if (!created) {
return { return {
@@ -402,14 +400,6 @@ export class GitManager {
}; };
} }
private async openPrInBrowser(cwd: string, branch: string): Promise<void> {
try {
await this.runGh(cwd, ["pr", "view", branch, "--web"]);
} catch {
// Opening the browser is best-effort.
}
}
private async findOpenPr( private async findOpenPr(
cwd: string, cwd: string,
branch: string, branch: string,
+139 -122
View File
@@ -8,11 +8,9 @@ import { queryOptions, useMutation, useQuery, useQueryClient } from "@tanstack/r
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { import {
CheckIcon, CheckIcon,
CircleIcon,
CloudUploadIcon, CloudUploadIcon,
GitCommitIcon, GitCommitIcon,
Loader2Icon, Loader2Icon,
MinusIcon,
XIcon, XIcon,
} from "lucide-react"; } from "lucide-react";
import { GitHubIcon } from "./Icons"; import { GitHubIcon } from "./Icons";
@@ -64,6 +62,13 @@ function GitActionIcon(props: { icon: GitActionIconName; disabled: boolean }) {
return <GitHubIcon className={`h-5 w-5 shrink-0 ${toneClass}`} />; return <GitHubIcon className={`h-5 w-5 shrink-0 ${toneClass}`} />;
} }
function runningStepMessage(stepId: GitProgressStep["id"]): string {
if (stepId === "generate") return "Generating commit message...";
if (stepId === "commit") return "Committing changes...";
if (stepId === "push") return "Pushing branch...";
return "Preparing pull request...";
}
function gitActionModalTitle(): string { function gitActionModalTitle(): string {
return "Commit your changes"; return "Commit your changes";
} }
@@ -249,6 +254,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
const [gitModalProgress, setGitModalProgress] = useState<GitProgressStep[]>([]); const [gitModalProgress, setGitModalProgress] = useState<GitProgressStep[]>([]);
const [gitModalError, setGitModalError] = useState<string | null>(null); const [gitModalError, setGitModalError] = useState<string | null>(null);
const [gitModalResult, setGitModalResult] = useState<GitRunStackedActionResult | null>(null); const [gitModalResult, setGitModalResult] = useState<GitRunStackedActionResult | null>(null);
const [isGitProgressToastVisible, setIsGitProgressToastVisible] = useState(false);
const gitMenuRef = useRef<HTMLDivElement>(null); const gitMenuRef = useRef<HTMLDivElement>(null);
const { data: gitStatus = null, error: gitStatusError } = useQuery( const { data: gitStatus = null, error: gitStatusError } = useQuery(
@@ -291,10 +297,27 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
[gitModalActionOptions, gitModalSelectedAction], [gitModalActionOptions, gitModalSelectedAction],
); );
const visibleGitActionError = gitActionError ?? gitStatusError?.message; const visibleGitActionError = gitActionError ?? gitStatusError?.message;
const gitModalOpenPrUrl = gitModalResult?.pr.url ?? gitStatus?.openPr?.url ?? null; const gitProgressToastOpenPrUrl = gitModalResult?.pr.url ?? gitStatus?.openPr?.url ?? null;
const gitModalHasProgress = gitModalProgress.length > 0; const showGitProgressToast =
const gitModalSelectionMode = !gitModalHasProgress && gitModalResult === null; isGitProgressToastVisible &&
const gitModalSteps = gitModalProgress; (isGitModalActionRunning ||
gitModalProgress.length > 0 ||
gitModalError !== null ||
gitModalResult !== null);
const activeGitProgressStep = useMemo(
() => gitModalProgress.find((step) => step.status === "running") ?? null,
[gitModalProgress],
);
const gitProgressToastStatus = isGitModalActionRunning
? "running"
: gitModalError
? "failed"
: "done";
const gitProgressToastMessage = isGitModalActionRunning
? runningStepMessage(activeGitProgressStep?.id ?? "commit")
: gitModalError
? "Git action failed."
: "Done.";
const refreshGitStatus = useCallback(async () => { const refreshGitStatus = useCallback(async () => {
if (!api || !gitCwd) return; if (!api || !gitCwd) return;
@@ -307,6 +330,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
setIsGitModalOpen(true); setIsGitModalOpen(true);
setGitModalSelectedAction("commit"); setGitModalSelectedAction("commit");
setGitModalCommitMessage(""); setGitModalCommitMessage("");
setIsGitProgressToastVisible(false);
setGitModalProgress([]); setGitModalProgress([]);
setGitModalError(null); setGitModalError(null);
setGitModalResult(null); setGitModalResult(null);
@@ -318,9 +342,6 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
setIsGitModalOpen(false); setIsGitModalOpen(false);
setGitModalSelectedAction("commit"); setGitModalSelectedAction("commit");
setGitModalCommitMessage(""); setGitModalCommitMessage("");
setGitModalProgress([]);
setGitModalError(null);
setGitModalResult(null);
}, [isGitActionRunning]); }, [isGitActionRunning]);
const runGitActionImmediately = useCallback( const runGitActionImmediately = useCallback(
@@ -349,28 +370,39 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
}); });
}, [api, gitStatus?.openPr?.url]); }, [api, gitStatus?.openPr?.url]);
const openPrFromModal = useCallback(() => { const openPrFromToast = useCallback(() => {
if (!api) { if (!api) {
setGitModalError("Link opening is unavailable."); setGitModalError("Link opening is unavailable.");
return; return;
} }
const prUrl = gitModalOpenPrUrl; const prUrl = gitProgressToastOpenPrUrl;
if (!prUrl) return; if (!prUrl) return;
void api.shell.openExternal(prUrl).catch((error) => { void api.shell.openExternal(prUrl).catch((error) => {
setGitModalError(error instanceof Error ? error.message : "Unable to open PR link."); setGitModalError(error instanceof Error ? error.message : "Unable to open PR link.");
}); });
}, [api, gitModalOpenPrUrl]); }, [api, gitProgressToastOpenPrUrl]);
const dismissGitProgressToast = useCallback(() => {
if (isGitModalActionRunning) return;
setIsGitProgressToastVisible(false);
setGitModalProgress([]);
setGitModalError(null);
setGitModalResult(null);
}, [isGitModalActionRunning]);
const runGitAction = useCallback(async () => { const runGitAction = useCallback(async () => {
if (!api || !gitCwd || !isGitModalOpen) return; if (!api || !gitCwd) return;
if (!selectedGitModalActionOption || selectedGitModalActionOption.disabled) return; if (!selectedGitModalActionOption || selectedGitModalActionOption.disabled) return;
const actionCwd = gitCwd; const actionCwd = gitCwd;
const action = selectedGitModalActionOption.action; const action = selectedGitModalActionOption.action;
const commitMessage = gitModalCommitMessage.trim(); const commitMessage = gitModalCommitMessage.trim();
const includeGeneratedCommitMessage = commitMessage.length === 0; const includeGeneratedCommitMessage = commitMessage.length === 0;
setIsGitMenuOpen(false);
setIsGitModalOpen(false);
setIsGitProgressToastVisible(true);
setIsGitModalActionRunning(true); setIsGitModalActionRunning(true);
setGitModalError(null); setGitModalError(null);
setGitActionError(null); setGitActionError(null);
@@ -488,7 +520,6 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
api, api,
gitCwd, gitCwd,
gitModalCommitMessage, gitModalCommitMessage,
isGitModalOpen,
refreshGitStatus, refreshGitStatus,
selectedGitModalActionOption, selectedGitModalActionOption,
]); ]);
@@ -497,6 +528,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
setGitActionError(null); setGitActionError(null);
setGitModalError(null); setGitModalError(null);
setIsGitModalOpen(false); setIsGitModalOpen(false);
setIsGitProgressToastVisible(false);
setGitModalSelectedAction("commit"); setGitModalSelectedAction("commit");
setGitModalCommitMessage(""); setGitModalCommitMessage("");
setGitModalProgress([]); setGitModalProgress([]);
@@ -690,92 +722,57 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
placeholder="Leave blank to autogenerate a commit message" placeholder="Leave blank to autogenerate a commit message"
value={gitModalCommitMessage} value={gitModalCommitMessage}
onChange={(event) => setGitModalCommitMessage(event.target.value)} onChange={(event) => setGitModalCommitMessage(event.target.value)}
disabled={!gitModalSelectionMode || isGitActionRunning} disabled={isGitActionRunning}
/> />
</div> </div>
<div className="mt-6"> <div className="mt-6">
<p className="text-sm font-medium text-foreground">Next steps</p> <p className="text-sm font-medium text-foreground">Next steps</p>
<div className="mt-2 overflow-hidden rounded-2xl border border-border"> <div className="mt-2 overflow-hidden rounded-2xl border border-border">
{gitModalSelectionMode && {gitModalActionOptions.map((option, index) => {
gitModalActionOptions.map((option, index) => { const borderClass =
const borderClass = index < gitModalActionOptions.length - 1 ? "border-b border-border/70" : "";
index < gitModalActionOptions.length - 1 ? "border-b border-border/70" : ""; const selected = option.action === gitModalSelectedAction && !option.disabled;
const selected = option.action === gitModalSelectedAction && !option.disabled; const disabled = option.disabled || isGitActionRunning;
const disabled = option.disabled || isGitActionRunning;
return ( return (
<button <button
key={option.action} key={option.action}
type="button" type="button"
className={`flex w-full items-start gap-3 px-4 py-3 text-left transition-colors duration-150 ${borderClass} ${ className={`flex w-full items-start gap-3 px-4 py-3 text-left transition-colors duration-150 ${borderClass} ${
selected selected
? "bg-accent/55" ? "bg-accent/55"
: disabled : disabled
? "bg-card/25" ? "bg-card/25"
: "bg-card/45 hover:bg-accent/35" : "bg-card/45 hover:bg-accent/35"
} disabled:cursor-not-allowed`} } disabled:cursor-not-allowed`}
disabled={disabled} disabled={disabled}
onClick={() => { onClick={() => {
setGitModalSelectedAction(option.action); setGitModalSelectedAction(option.action);
}} }}
> >
<span className="mt-0.5"> <span className="mt-0.5">
<GitActionIcon icon={option.icon} disabled={option.disabled} /> <GitActionIcon icon={option.icon} disabled={option.disabled} />
</span> </span>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p
className={`text-sm ${disabled ? "text-muted-foreground/60" : "text-foreground"}`}
>
{option.label}
</p>
{option.detail && (
<p <p
className={`text-sm ${disabled ? "text-muted-foreground/60" : "text-foreground"}`} className={`mt-0.5 text-xs ${disabled ? "text-muted-foreground/55" : "text-muted-foreground/70"}`}
> >
{option.label} {option.detail}
</p> </p>
{option.detail && ( )}
<p
className={`mt-0.5 text-xs ${disabled ? "text-muted-foreground/55" : "text-muted-foreground/70"}`}
>
{option.detail}
</p>
)}
</div>
{selected && !disabled ? (
<CheckIcon className="mt-0.5 h-4 w-4 shrink-0 text-foreground" />
) : null}
</button>
);
})}
{!gitModalSelectionMode &&
gitModalSteps.map((step, index) => {
const borderClass =
index < gitModalSteps.length - 1 ? "border-b border-border/70" : "";
return (
<div
key={step.id}
className={`flex items-start gap-3 bg-card/45 px-4 py-3 ${borderClass}`}
>
<span className="mt-0.5">
{step.status === "running" ? (
<Loader2Icon className="h-4 w-4 animate-spin text-foreground" />
) : step.status === "completed" ? (
<CheckIcon className="h-4 w-4 text-emerald-600 dark:text-emerald-300" />
) : step.status === "skipped" ? (
<MinusIcon className="h-4 w-4 text-muted-foreground/70" />
) : step.status === "failed" ? (
<XIcon className="h-4 w-4 text-rose-500 dark:text-rose-300" />
) : (
<CircleIcon className="h-4 w-4 text-muted-foreground/60" />
)}
</span>
<div className="min-w-0">
<p className="text-sm text-foreground">{step.label}</p>
{step.status === "failed" && step.detail && (
<p className="mt-0.5 text-xs text-rose-500 dark:text-rose-300">
{step.detail}
</p>
)}
</div>
</div> </div>
); {selected && !disabled ? (
})} <CheckIcon className="mt-0.5 h-4 w-4 shrink-0 text-foreground" />
) : null}
</button>
);
})}
</div> </div>
</div> </div>
{(gitModalError ?? visibleGitActionError) && ( {(gitModalError ?? visibleGitActionError) && (
@@ -784,48 +781,68 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
</div> </div>
)} )}
<div className="mt-6 flex justify-end gap-2"> <div className="mt-6 flex justify-end gap-2">
{gitModalResult && gitModalOpenPrUrl && (
<button
type="button"
className="rounded-xl border border-border px-4 py-2 text-sm text-foreground transition-colors duration-150 hover:bg-accent disabled:cursor-not-allowed disabled:opacity-60"
onClick={openPrFromModal}
disabled={isGitActionRunning}
>
Open PR
</button>
)}
<button <button
type="button" type="button"
className={ className="rounded-xl border border-border px-4 py-2 text-sm text-foreground transition-colors duration-150 hover:bg-accent disabled:cursor-not-allowed disabled:opacity-60"
gitModalResult
? "rounded-xl bg-foreground px-4 py-2 text-sm font-medium text-background transition-colors duration-150 hover:bg-foreground/90 disabled:cursor-not-allowed disabled:opacity-60"
: "rounded-xl border border-border px-4 py-2 text-sm text-foreground transition-colors duration-150 hover:bg-accent disabled:cursor-not-allowed disabled:opacity-60"
}
onClick={closeGitActionModal} onClick={closeGitActionModal}
disabled={isGitActionRunning} disabled={isGitActionRunning}
> >
{gitModalResult ? "Done" : "Cancel"} Cancel
</button>
<button
type="button"
className="rounded-xl bg-foreground px-4 py-2 text-sm font-medium text-background transition-colors duration-150 hover:bg-foreground/90 disabled:cursor-not-allowed disabled:opacity-60"
onClick={() => {
void runGitAction();
}}
disabled={isGitActionRunning || !selectedGitModalActionOption}
>
{runActionLabel(gitModalSelectedAction)}
</button> </button>
{!gitModalResult && (
<button
type="button"
className="rounded-xl bg-foreground px-4 py-2 text-sm font-medium text-background transition-colors duration-150 hover:bg-foreground/90 disabled:cursor-not-allowed disabled:opacity-60"
onClick={() => {
void runGitAction();
}}
disabled={isGitActionRunning || !selectedGitModalActionOption}
>
{isGitActionRunning
? "Running..."
: gitModalSelectionMode
? "Continue"
: runActionLabel(gitModalSelectedAction)}
</button>
)}
</div> </div>
</div> </div>
</div> </div>
)} )}
{showGitProgressToast && (
<div
className="fixed bottom-4 right-4 z-[90]"
role="status"
aria-live="polite"
>
<div className="flex max-w-[calc(100vw-2rem)] items-center gap-2 rounded-xl border border-border bg-popover/95 px-3 py-2 shadow-xl backdrop-blur">
<span className="shrink-0">
{gitProgressToastStatus === "running" ? (
<Loader2Icon className="h-4 w-4 animate-spin text-foreground" />
) : gitProgressToastStatus === "failed" ? (
<XIcon className="h-4 w-4 text-rose-500 dark:text-rose-300" />
) : (
<CheckIcon className="h-4 w-4 text-emerald-600 dark:text-emerald-300" />
)}
</span>
<span className="min-w-0 truncate text-sm text-foreground">{gitProgressToastMessage}</span>
{!isGitModalActionRunning && gitModalResult && gitProgressToastOpenPrUrl && (
<button
type="button"
className="rounded-md bg-foreground px-2.5 py-1 text-xs font-medium text-background transition-colors duration-150 hover:bg-foreground/90 disabled:cursor-not-allowed disabled:opacity-60"
onClick={openPrFromToast}
disabled={isGitModalActionRunning}
>
Open PR
</button>
)}
<button
type="button"
className="rounded p-1 text-muted-foreground/60 transition-colors duration-150 hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
onClick={dismissGitProgressToast}
disabled={isGitModalActionRunning}
aria-label="Dismiss git action progress toast"
>
<XIcon className="h-4 w-4" />
</button>
</div>
</div>
)}
</> </>
); );
} }