Accumulate OpenCode settings restarts behind Apply & Restart

Defer OpenCode reloads after settings mutations, track pending changes,
and expose a top-right Apply & Restart OpenCode action with a counter so
sessions stay available until the user explicitly applies.

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-08-03 06:56:38 +00:00
co-authored by Serhii Dziupin
parent 775da6e9f4
commit 57819dd164
31 changed files with 869 additions and 167 deletions
@@ -20,7 +20,7 @@ import {
} from '@/lib/responseStyle';
import type { DesktopSettings } from '@/lib/desktop';
import { runtimeFetch } from '@/lib/runtime-fetch';
import { reloadOpenCodeConfiguration } from '@/stores/useAgentsStore';
import { noteDeferredRestartFromPayload, recordDeferredOpenCodeRestart } from '@/lib/opencode/deferredRestart';
import { SettingsPageLayout } from '@/components/sections/shared/SettingsPageLayout';
import {
SettingsSection,
@@ -242,13 +242,18 @@ export const BehaviorPage: React.FC = () => {
throw new Error(await readApiError(response, t('settings.behavior.page.toast.saveFailed')));
}
const payload = await response.json().catch(() => null);
if (!noteDeferredRestartFromPayload(payload, 'behavior', { id: 'agents-md' })) {
recordDeferredOpenCodeRestart('behavior', { id: 'agents-md' });
}
await saveBehaviorSetting({
globalBehaviorPrompt: content,
}, t('settings.behavior.page.toast.saveFailed'));
setPrompt(content);
setInitialPrompt(content);
toast.success(t('settings.behavior.page.toast.saved'));
toast.success(t('settings.view.pendingRestart.saved'));
} catch (error) {
console.error('Failed to save behavior:', error);
const message = error instanceof Error ? error.message : t('settings.behavior.page.toast.saveFailed');
@@ -266,19 +271,8 @@ export const BehaviorPage: React.FC = () => {
t('settings.behavior.page.toast.saveFailed'),
);
setInitialOptimizeSystemPrompt(optimizeSystemPrompt);
} catch (error) {
const message = error instanceof Error ? error.message : t('settings.behavior.page.toast.saveFailed');
toast.error(message);
setIsApplyingPromptOptimization(false);
return;
}
try {
await reloadOpenCodeConfiguration({
message: t('settings.behavior.page.systemPromptOptimization.restarting'),
mode: 'projects',
scopes: ['all'],
});
recordDeferredOpenCodeRestart('behavior', { id: 'optimize-system-prompt' });
toast.success(t('settings.view.pendingRestart.saved'));
} catch (error) {
const message = error instanceof Error ? error.message : t('settings.behavior.page.toast.saveFailed');
toast.error(message);
@@ -317,7 +311,7 @@ export const BehaviorPage: React.FC = () => {
>
{isApplyingPromptOptimization
? t('settings.common.actions.saving')
: t('settings.openchamber.opencodeCli.actions.saveAndReload')}
: t('settings.common.actions.saveChanges')}
</Button>
</SettingsSection>
)}