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
28 changes: 20 additions & 8 deletions desktop/backend/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,11 @@ func (s *AntigravityService) UpdateProfile(ctx context.Context, req UpdateAntigr
return result, err
}

func (s *AntigravityService) SaveCurrent(ctx context.Context) (antigravity.AntigravityProfileSaveResult, error) {
result, err := s.application.Antigravity().SaveActiveProfile(ctx)
func (s *AntigravityService) SaveCurrent(ctx context.Context, expectedProfileID string) (antigravity.AntigravityProfileSaveResult, error) {
if expectedProfileID == "" {
return antigravity.AntigravityProfileSaveResult{}, apperror.New(apperror.ProfileChanged, "selected Profile is missing")
}
result, err := s.application.Antigravity().SaveActiveProfileFor(ctx, expectedProfileID)
s.notifyMutationResult(DesktopChangeAntigravityProfileChanged, "antigravity.saveCurrent", agyconfig.ProviderID, result.Summary.Profile.ID, result.OperationID, err)
return result, err
}
Expand Down Expand Up @@ -606,8 +609,11 @@ func (s *ClaudeCodeService) UpdateProfile(ctx context.Context, req UpdateClaudeC
return result, err
}

func (s *ClaudeCodeService) SaveCurrent(ctx context.Context, confirmShared bool) (claudecode.ClaudeCodeProfileSaveResult, error) {
result, err := s.application.ClaudeCode().SaveActiveProfile(ctx, claudecode.SaveActiveClaudeCodeProfileRequest{ConfirmShared: confirmShared})
func (s *ClaudeCodeService) SaveCurrent(ctx context.Context, expectedProfileID string, confirmShared bool) (claudecode.ClaudeCodeProfileSaveResult, error) {
if expectedProfileID == "" {
return claudecode.ClaudeCodeProfileSaveResult{}, apperror.New(apperror.ProfileChanged, "selected Profile is missing")
}
result, err := s.application.ClaudeCode().SaveActiveProfile(ctx, claudecode.SaveActiveClaudeCodeProfileRequest{ExpectedProfileID: expectedProfileID, ConfirmShared: confirmShared})
s.notifyMutationResult(DesktopChangeClaudeCodeProfileChanged, "claude-code.saveCurrent", claudecodeconfig.ProviderID, result.Summary.Profile.ID, result.OperationID, err)
return result, err
}
Expand Down Expand Up @@ -697,8 +703,11 @@ func (s *CodexService) ForkProfile(ctx context.Context, req ForkCodexProfileRequ
return result, err
}

func (s *CodexService) SaveActiveProfileState(ctx context.Context) (codex.CodexProfileStateSaveResult, error) {
result, err := s.application.Codex().SaveActiveProfileState(ctx)
func (s *CodexService) SaveActiveProfileState(ctx context.Context, expectedProfileID string, expectedCredentialReferences, expectedConfigReferences int) (codex.CodexProfileStateSaveResult, error) {
if expectedProfileID == "" {
return codex.CodexProfileStateSaveResult{}, apperror.New(apperror.ProfileChanged, "selected Profile is missing")
}
result, err := s.application.Codex().SaveActiveProfileStateFor(ctx, expectedProfileID, expectedCredentialReferences, expectedConfigReferences)
s.notifyMutationResult(DesktopChangeCodexProfileChanged, "codex.saveActiveProfileState", codexconfig.ProviderID, result.ProfileID, result.OperationID, err)
return result, err
}
Expand Down Expand Up @@ -832,8 +841,11 @@ func (s *GrokBuildService) ForkProfile(ctx context.Context, req ForkGrokBuildPro
return result, err
}

func (s *GrokBuildService) SaveActiveProfileState(ctx context.Context) (grokbuild.ProfileStateSaveResult, error) {
result, err := s.application.GrokBuild().SaveActiveProfileState(ctx)
func (s *GrokBuildService) SaveActiveProfileState(ctx context.Context, expectedProfileID string, expectedCredentialReferences, expectedConfigReferences int) (grokbuild.ProfileStateSaveResult, error) {
if expectedProfileID == "" {
return grokbuild.ProfileStateSaveResult{}, apperror.New(apperror.ProfileChanged, "selected Profile is missing")
}
result, err := s.application.GrokBuild().SaveActiveProfileStateFor(ctx, expectedProfileID, expectedCredentialReferences, expectedConfigReferences)
s.notifyMutationResult(DesktopChangeGrokBuildProfileChanged, "grok-build.saveActiveProfileState", grokconfig.ProviderID, result.ProfileID, result.OperationID, err)
return result, err
}
Expand Down
20 changes: 19 additions & 1 deletion desktop/backend/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,24 @@ func assertDesktopServiceErrorCode(t *testing.T, err error, code apperror.Code)
}
}

func TestDesktopSaveCurrentRejectsMissingSelectedProfile(t *testing.T) {
ctx := context.Background()
tests := []struct {
name string
save func() error
}{
{"Antigravity", func() error { _, err := (&AntigravityService{}).SaveCurrent(ctx, ""); return err }},
{"Claude Code", func() error { _, err := (&ClaudeCodeService{}).SaveCurrent(ctx, "", false); return err }},
{"Codex", func() error { _, err := (&CodexService{}).SaveActiveProfileState(ctx, "", 0, 0); return err }},
{"Grok Build", func() error { _, err := (&GrokBuildService{}).SaveActiveProfileState(ctx, "", 0, 0); return err }},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
assertDesktopServiceErrorCode(t, test.save(), apperror.ProfileChanged)
})
}
}

func TestAntigravityServiceCreatesSafeDashboardProfile(t *testing.T) {
keyring.MockInit()
t.Cleanup(keyring.MockInit)
Expand Down Expand Up @@ -1030,7 +1048,7 @@ func TestCodexSaveActiveProfileStateReadsCurrentFilesBehindDesktopBoundary(t *te
}

writeDesktopCodexFiles(t, codexDir, `model = "gpt-5.1-codex"`+"\n", `{"tokens":{"account_id":"updated","access_token":"changed"}}`)
if _, err := services.Codex.SaveActiveProfileState(ctx); err != nil {
if _, err := services.Codex.SaveActiveProfileState(ctx, "work", 1, 1); err != nil {
t.Fatalf("expected save-current to read current Codex files, got %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export function ReadProfileQuota(profileID: string): $CancellablePromise<antigra
return $Call.ByID(2657873016, profileID);
}

export function SaveCurrent(): $CancellablePromise<antigravity$0.AntigravityProfileSaveResult> {
return $Call.ByID(1314540511);
export function SaveCurrent(expectedProfileID: string): $CancellablePromise<antigravity$0.AntigravityProfileSaveResult> {
return $Call.ByID(1314540511, expectedProfileID);
}

export function ShowProfile(profileID: string): $CancellablePromise<antigravity$0.AntigravityProfileDetail> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export function ListProfiles(): $CancellablePromise<claudecode$0.ClaudeCodeProfi
return $Call.ByID(2487267564);
}

export function SaveCurrent(confirmShared: boolean): $CancellablePromise<claudecode$0.ClaudeCodeProfileSaveResult> {
return $Call.ByID(1016544372, confirmShared);
export function SaveCurrent(expectedProfileID: string, confirmShared: boolean): $CancellablePromise<claudecode$0.ClaudeCodeProfileSaveResult> {
return $Call.ByID(1016544372, expectedProfileID, confirmShared);
}

export function ShowProfile(profileID: string): $CancellablePromise<claudecode$0.ClaudeCodeProfileDetail> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export function ReadProfileQuota(profileID: string): $CancellablePromise<codex$0
return $Call.ByID(2588960257, profileID);
}

export function SaveActiveProfileState(): $CancellablePromise<codex$0.CodexProfileStateSaveResult> {
return $Call.ByID(2732837523);
export function SaveActiveProfileState(expectedProfileID: string, expectedCredentialReferences: number, expectedConfigReferences: number): $CancellablePromise<codex$0.CodexProfileStateSaveResult> {
return $Call.ByID(2732837523, expectedProfileID, expectedCredentialReferences, expectedConfigReferences);
}

export function SetProfileConfig(req: $models.UpdateCodexProfileConfigSetRequest): $CancellablePromise<codex$0.CodexProfileDetail> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function ReadProfileQuota(profileID: string): $CancellablePromise<grokbui
return $Call.ByID(1290892715, profileID);
}

export function SaveActiveProfileState(): $CancellablePromise<grokbuild$0.ProfileStateSaveResult> {
return $Call.ByID(1134372713);
export function SaveActiveProfileState(expectedProfileID: string, expectedCredentialReferences: number, expectedConfigReferences: number): $CancellablePromise<grokbuild$0.ProfileStateSaveResult> {
return $Call.ByID(1134372713, expectedProfileID, expectedCredentialReferences, expectedConfigReferences);
}

export function SetProfileConfig(req: $models.UpdateGrokBuildProfileConfigSetRequest): $CancellablePromise<grokbuild$0.ProfileDetail> {
Expand Down
20 changes: 16 additions & 4 deletions desktop/frontend/src/features/profiles/AntigravityProfiles.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import PencilIcon from "@lucide/svelte/icons/pencil";
import PlusIcon from "@lucide/svelte/icons/plus";
import RefreshCwIcon from "@lucide/svelte/icons/refresh-cw";
import SaveIcon from "@lucide/svelte/icons/save";
import Trash2Icon from "@lucide/svelte/icons/trash-2";
import TriangleAlertIcon from "@lucide/svelte/icons/triangle-alert";

Expand Down Expand Up @@ -109,6 +110,7 @@
let editName = $state("");
let editDescription = $state("");
let saveCurrentOpen = $state(false);
let saveCurrentProfileID = $state("");
let saveCurrentReferenceCount = $state(1);
let deleteOpen = $state(false);
let deleteTarget = $state<ProfileDeleteTarget | null>(null);
Expand Down Expand Up @@ -244,7 +246,8 @@
showNotice(translate("profileDelete.deletedTitle"), translate("profileDelete.deletedDescription"));
}

function openSaveCurrent(referenceCount: number) {
function openSaveCurrent(profileID: string, referenceCount: number) {
saveCurrentProfileID = profileID;
saveCurrentReferenceCount = Math.max(1, referenceCount);
saveCurrentOpen = true;
}
Expand All @@ -270,7 +273,16 @@
async function saveCurrent() {
await runAction("antigravity-save-current", async () => {
if (!isSourceReady(await refreshDetect())) return;
const result = await track("antigravity-save-current", AntigravityService.SaveCurrent());
let result;
try {
result = await track("antigravity-save-current", AntigravityService.SaveCurrent(saveCurrentProfileID));
} catch (error) {
if (isDesktopErrorCode(error, "PROFILE_CHANGED")) {
saveCurrentOpen = false;
await refreshProfiles();
}
throw error;
}
saveCurrentOpen = false;
await Promise.all([refreshProfiles(), detail ? loadDetail(detail.summary.profile.id) : Promise.resolve()]);
showWarnings(result.warnings);
Expand Down Expand Up @@ -533,7 +545,7 @@
<DropdownMenu.Content align="end">
<DropdownMenu.Group>
<DropdownMenu.Item onSelect={() => push(`/antigravity/profiles/${encodeURIComponent(summary.profile.id)}`)}><EyeIcon />{$_("actions.details")}</DropdownMenu.Item>
{#if summary.active}<DropdownMenu.Item disabled={!sourceReady || !!busyAction} onSelect={() => openSaveCurrent(summary.credential_reference_count)}><RefreshCwIcon />{$_("antigravity.actions.updateCurrent")}</DropdownMenu.Item>{/if}
{#if summary.active}<DropdownMenu.Item disabled={!sourceReady || !!busyAction} onSelect={() => openSaveCurrent(summary.profile.id, summary.credential_reference_count)}><SaveIcon />{$_("antigravity.actions.updateCurrent")}</DropdownMenu.Item>{/if}
<DropdownMenu.Item variant="destructive" disabled={!!busyAction} onSelect={() => openProfileDelete({ id: summary.profile.id, name: summary.profile.name || $_("profile.unnamed") })}><Trash2Icon />{$_("actions.deleteProfile")}</DropdownMenu.Item>
</DropdownMenu.Group>
</DropdownMenu.Content>
Expand Down Expand Up @@ -640,7 +652,7 @@
</DropdownMenu.Group>
</DropdownMenu.Content>
</DropdownMenu.Root>
{#if detail.summary.active}<Button variant="outline" disabled={!sourceReady || !!busyAction} onclick={() => openSaveCurrent(detail!.summary.credential_reference_count)}>{$_("antigravity.actions.updateCurrent")}</Button>{/if}
{#if detail.summary.active}<Button variant="outline" disabled={!sourceReady || !!busyAction} onclick={() => openSaveCurrent(detail!.summary.profile.id, detail!.summary.credential_reference_count)}>{$_("antigravity.actions.updateCurrent")}</Button>{/if}
<Button disabled={!switchReady || (detail.summary.active && !activeLoginMissing) || !!busyAction || useBuilding || useApplying} onclick={() => openUse({ id: detail!.summary.profile.id, name: detail!.summary.profile.name || $_("profile.unnamed") })}>{$_("actions.useProfile")}</Button>
</Card.Footer>
</Card.Root>
Expand Down
19 changes: 15 additions & 4 deletions desktop/frontend/src/features/profiles/ClaudeCodeProfiles.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import PencilIcon from "@lucide/svelte/icons/pencil";
import PlusIcon from "@lucide/svelte/icons/plus";
import RefreshCwIcon from "@lucide/svelte/icons/refresh-cw";
import SaveIcon from "@lucide/svelte/icons/save";
import Trash2Icon from "@lucide/svelte/icons/trash-2";
import TriangleAlertIcon from "@lucide/svelte/icons/triangle-alert";

Expand Down Expand Up @@ -82,6 +83,7 @@
let editName = $state("");
let editDescription = $state("");
let saveCurrentOpen = $state(false);
let saveCurrentProfileID = $state("");
let saveCurrentReferenceCount = $state(1);
let deleteOpen = $state(false);
let deleteTarget = $state<ProfileDeleteTarget | null>(null);
Expand Down Expand Up @@ -206,15 +208,24 @@
});
}

function openSaveCurrent(referenceCount: number) {
function openSaveCurrent(profileID: string, referenceCount: number) {
saveCurrentProfileID = profileID;
saveCurrentReferenceCount = Math.max(1, referenceCount);
saveCurrentOpen = true;
}

async function saveCurrent() {
await runAction("claude-code-save-current", async () => {
if (!isSourceReady(await refreshDetect())) return;
await track("claude-code-save-current", ClaudeCodeService.SaveCurrent(saveCurrentReferenceCount > 1));
try {
await track("claude-code-save-current", ClaudeCodeService.SaveCurrent(saveCurrentProfileID, saveCurrentReferenceCount > 1));
} catch (error) {
if (isDesktopErrorCode(error, "PROFILE_CHANGED")) {
saveCurrentOpen = false;
await refreshProfiles();
}
throw error;
}
saveCurrentOpen = false;
await Promise.all([refreshProfiles(), detail ? loadDetail(detail.summary.profile.id) : Promise.resolve()]);
showNotice(translate("claudeCode.notice.savedTitle"), translate("claudeCode.notice.savedDescription"));
Expand Down Expand Up @@ -344,7 +355,7 @@
<div class="flex items-center gap-3"><button class="min-w-0 flex-1 truncate text-left font-medium hover:underline" onclick={() => push(`/claude-code/profiles/${encodeURIComponent(summary.profile.id)}`)}>{summary.profile.name || summary.profile.id}</button>
{#if summary.active}<StatusBadge tone="current"><CheckIcon />{$_("status.current")}</StatusBadge>{/if}<StatusBadge tone={summary.credential_status === "valid" ? "success" : "warning"}>{$_(`claudeCode.status.${summary.credential_status}`)}</StatusBadge>
{#if !summary.active}<Button size="sm" disabled={!providerReady || !!busyAction} onclick={() => openUse({ id: summary.profile.id, name: summary.profile.name || summary.profile.id })}>{$_("actions.useProfile")}</Button>{/if}
<DropdownMenu.Root><DropdownMenu.Trigger>{#snippet child({ props })}<Button {...props} variant="outline" size="icon-sm" disabled={!!busyAction} aria-label={$_("actions.more")}><MoreHorizontalIcon /></Button>{/snippet}</DropdownMenu.Trigger><DropdownMenu.Content align="end"><DropdownMenu.Group><DropdownMenu.Item onSelect={() => push(`/claude-code/profiles/${encodeURIComponent(summary.profile.id)}`)}><EyeIcon />{$_("actions.details")}</DropdownMenu.Item><DropdownMenu.Item variant="destructive" onSelect={() => openProfileDelete({ id: summary.profile.id, name: summary.profile.name || summary.profile.id })}><Trash2Icon />{$_("actions.deleteProfile")}</DropdownMenu.Item></DropdownMenu.Group></DropdownMenu.Content></DropdownMenu.Root>
<DropdownMenu.Root><DropdownMenu.Trigger>{#snippet child({ props })}<Button {...props} variant="outline" size="icon-sm" disabled={!!busyAction} aria-label={$_("actions.more")}><MoreHorizontalIcon /></Button>{/snippet}</DropdownMenu.Trigger><DropdownMenu.Content align="end"><DropdownMenu.Group><DropdownMenu.Item onSelect={() => push(`/claude-code/profiles/${encodeURIComponent(summary.profile.id)}`)}><EyeIcon />{$_("actions.details")}</DropdownMenu.Item>{#if summary.active}<DropdownMenu.Item disabled={!sourceReady || !!busyAction} onSelect={() => openSaveCurrent(summary.profile.id, summary.credential_reference_count)}><SaveIcon />{$_("claudeCode.actions.updateCurrent")}</DropdownMenu.Item>{/if}<DropdownMenu.Item variant="destructive" onSelect={() => openProfileDelete({ id: summary.profile.id, name: summary.profile.name || summary.profile.id })}><Trash2Icon />{$_("actions.deleteProfile")}</DropdownMenu.Item></DropdownMenu.Group></DropdownMenu.Content></DropdownMenu.Root>
</div><div class="text-sm text-muted-foreground">{$_("claudeCode.detail.expiry")}: {formatExpiry(summary.expires_at_unix_ms)}</div>
{#if summary.warnings?.length}<Alert.Root><TriangleAlertIcon /><Alert.Description>{$_("claudeCode.notice.profileWarning")}</Alert.Description></Alert.Root>{/if}
</div>{#if index < profiles.length - 1}<Separator />{/if}
Expand All @@ -369,7 +380,7 @@
<Card.Root><Card.Header><Card.Title>{detail.summary.profile.name || detail.summary.profile.id}</Card.Title><Card.Description>{detail.summary.profile.description || $_("profile.noDescription")}</Card.Description>{#if detail.summary.active}<Card.Action><Badge>{$_("status.current")}</Badge></Card.Action>{/if}</Card.Header>
<Card.Content><dl class="grid gap-4 text-sm sm:grid-cols-2"><div><dt class="text-muted-foreground">{$_("profilePages.form.profileID")}</dt><dd class="font-mono">{detail.summary.profile.id}</dd></div><div><dt class="text-muted-foreground">{$_("claudeCode.detail.status")}</dt><dd>{$_(`claudeCode.status.${detail.summary.credential_status}`)}</dd></div><div><dt class="text-muted-foreground">{$_("claudeCode.detail.expiry")}</dt><dd>{formatExpiry(detail.summary.expires_at_unix_ms)}</dd></div><div><dt class="text-muted-foreground">{$_("claudeCode.detail.references")}</dt><dd>{detail.summary.credential_reference_count}</dd></div></dl>
{#if detail.summary.warnings?.length}<Alert.Root class="mt-4"><TriangleAlertIcon /><Alert.Description>{$_("claudeCode.notice.profileWarning")}</Alert.Description></Alert.Root>{/if}</Card.Content>
<Card.Footer class="justify-end gap-2"><DropdownMenu.Root><DropdownMenu.Trigger>{#snippet child({ props })}<Button {...props} variant="outline" size="icon-sm" disabled={!!busyAction} aria-label={$_("actions.more")}><MoreHorizontalIcon /></Button>{/snippet}</DropdownMenu.Trigger><DropdownMenu.Content align="end"><DropdownMenu.Group><DropdownMenu.Item onSelect={openEdit}><PencilIcon />{$_("actions.editDetails")}</DropdownMenu.Item><DropdownMenu.Item variant="destructive" onSelect={() => openProfileDelete({ id: detail!.summary.profile.id, name: detail!.summary.profile.name || detail!.summary.profile.id })}><Trash2Icon />{$_("actions.deleteProfile")}</DropdownMenu.Item></DropdownMenu.Group></DropdownMenu.Content></DropdownMenu.Root>{#if detail.summary.active}<Button variant="outline" disabled={!sourceReady || !!busyAction} onclick={() => openSaveCurrent(detail!.summary.credential_reference_count)}><RefreshCwIcon />{$_("claudeCode.actions.updateCurrent")}</Button>{/if}<Button disabled={!providerReady || detail.summary.active || !!busyAction} onclick={() => openUse({ id: detail!.summary.profile.id, name: detail!.summary.profile.name || detail!.summary.profile.id })}>{$_("actions.useProfile")}</Button></Card.Footer>
<Card.Footer class="justify-end gap-2"><DropdownMenu.Root><DropdownMenu.Trigger>{#snippet child({ props })}<Button {...props} variant="outline" size="icon-sm" disabled={!!busyAction} aria-label={$_("actions.more")}><MoreHorizontalIcon /></Button>{/snippet}</DropdownMenu.Trigger><DropdownMenu.Content align="end"><DropdownMenu.Group><DropdownMenu.Item onSelect={openEdit}><PencilIcon />{$_("actions.editDetails")}</DropdownMenu.Item><DropdownMenu.Item variant="destructive" onSelect={() => openProfileDelete({ id: detail!.summary.profile.id, name: detail!.summary.profile.name || detail!.summary.profile.id })}><Trash2Icon />{$_("actions.deleteProfile")}</DropdownMenu.Item></DropdownMenu.Group></DropdownMenu.Content></DropdownMenu.Root>{#if detail.summary.active}<Button variant="outline" disabled={!sourceReady || !!busyAction} onclick={() => openSaveCurrent(detail!.summary.profile.id, detail!.summary.credential_reference_count)}><RefreshCwIcon />{$_("claudeCode.actions.updateCurrent")}</Button>{/if}<Button disabled={!providerReady || detail.summary.active || !!busyAction} onclick={() => openUse({ id: detail!.summary.profile.id, name: detail!.summary.profile.name || detail!.summary.profile.id })}>{$_("actions.useProfile")}</Button></Card.Footer>
</Card.Root>
</div>
{/if}
Expand Down
Loading
Loading