perf: reduce idle desktop load by gating plan-mode checks
- Add startup feature flag for plan mode from OPENCODE_EXPERIMENTAL* env vars. - Stop recurring app health polling and keep a one-time startup check. - Skip plan-mode synthetic parsing and plan tab/file work when flag is off.
This commit is contained in:
@@ -5,6 +5,7 @@ import { useShallow } from 'zustand/react/shallow';
|
||||
import { defaultCodeDark, defaultCodeLight } from '@/lib/codeTheme';
|
||||
import { MessageFreshnessDetector } from '@/lib/messageFreshness';
|
||||
import { useConfigStore } from '@/stores/useConfigStore';
|
||||
import { useFeatureFlagsStore } from '@/stores/useFeatureFlagsStore';
|
||||
import { useUIStore } from '@/stores/useUIStore';
|
||||
import { useContextStore } from '@/stores/contextStore';
|
||||
import { useStreamingStore } from '@/sync/streaming';
|
||||
@@ -214,6 +215,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
||||
const showStickyInlineHoverRow = isUser && !isMobile && stickyUserHeader && !useExternalUserActionsRow;
|
||||
|
||||
const sessionId = message.info.sessionID;
|
||||
const planModeEnabled = useFeatureFlagsStore((state) => state.planModeEnabled);
|
||||
|
||||
// Keep non-active-turn rows detached from context-store churn.
|
||||
const { currentContextAgent, savedSessionAgentSelection } = useContextStore(
|
||||
@@ -228,8 +230,8 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
||||
return message.parts;
|
||||
}
|
||||
|
||||
return normalizeUserDisplayParts(message.parts);
|
||||
}, [isUser, message.parts]);
|
||||
return normalizeUserDisplayParts(message.parts, { planModeEnabled });
|
||||
}, [isUser, message.parts, planModeEnabled]);
|
||||
|
||||
const previousUserMetadata = React.useMemo(() => {
|
||||
if (isUser || !previousMessage) {
|
||||
@@ -269,6 +271,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
||||
}, [isUser, previousMessage]);
|
||||
|
||||
const previousIsModeSwitchMessage = React.useMemo(() => {
|
||||
if (!planModeEnabled) return false;
|
||||
if (isUser || !previousMessage) return false;
|
||||
const parts = Array.isArray(previousMessage.parts) ? previousMessage.parts : [];
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
@@ -281,7 +284,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}, [isUser, previousMessage]);
|
||||
}, [isUser, planModeEnabled, previousMessage]);
|
||||
|
||||
const agentName = React.useMemo(() => {
|
||||
if (isUser) return undefined;
|
||||
|
||||
@@ -81,15 +81,16 @@ const buildGitHubAttachmentPart = (text: string): Part | null => {
|
||||
return null;
|
||||
};
|
||||
|
||||
const shouldKeepSyntheticUserText = (text: string): boolean => {
|
||||
const shouldKeepSyntheticUserText = (text: string, planModeEnabled: boolean): boolean => {
|
||||
const trimmed = text.trim();
|
||||
if (trimmed.startsWith('User has requested to enter plan mode')) return true;
|
||||
if (trimmed.startsWith('The plan at ')) return true;
|
||||
if (planModeEnabled && trimmed.startsWith('User has requested to enter plan mode')) return true;
|
||||
if (planModeEnabled && trimmed.startsWith('The plan at ')) return true;
|
||||
if (trimmed.startsWith('The following tool was executed by the user')) return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
export const normalizeUserDisplayParts = (parts: Part[]): Part[] => {
|
||||
export const normalizeUserDisplayParts = (parts: Part[], options?: { planModeEnabled?: boolean }): Part[] => {
|
||||
const planModeEnabled = options?.planModeEnabled === true;
|
||||
return parts
|
||||
.filter((part) => {
|
||||
const synthetic = (part as { synthetic?: boolean }).synthetic === true;
|
||||
@@ -101,7 +102,7 @@ export const normalizeUserDisplayParts = (parts: Part[]): Part[] => {
|
||||
}
|
||||
|
||||
const normalizedText = text.trimStart();
|
||||
return shouldKeepSyntheticUserText(text)
|
||||
return shouldKeepSyntheticUserText(text, planModeEnabled)
|
||||
|| normalizedText.startsWith(GITHUB_ISSUE_CONTEXT_PREFIX)
|
||||
|| normalizedText.startsWith(GITHUB_PR_CONTEXT_PREFIX);
|
||||
})
|
||||
|
||||
@@ -30,6 +30,7 @@ import { useFilesViewTabsStore } from '@/stores/useFilesViewTabsStore';
|
||||
import { useGitStore } from '@/stores/useGitStore';
|
||||
import { useGitHubPrStatusStore } from '@/stores/useGitHubPrStatusStore';
|
||||
import { useGlobalSessionsStore } from '@/stores/useGlobalSessionsStore';
|
||||
import { useFeatureFlagsStore } from '@/stores/useFeatureFlagsStore';
|
||||
|
||||
import { useGitHubAuthStore } from '@/stores/useGitHubAuthStore';
|
||||
import { useRuntimeAPIs } from '@/hooks/useRuntimeAPIs';
|
||||
@@ -807,7 +808,8 @@ export const Header: React.FC<HeaderProps> = ({
|
||||
|
||||
|
||||
const [planTabAvailable, setPlanTabAvailable] = React.useState(false);
|
||||
const showPlanTab = planTabAvailable;
|
||||
const planModeEnabled = useFeatureFlagsStore((state) => state.planModeEnabled);
|
||||
const showPlanTab = planModeEnabled && planTabAvailable;
|
||||
const lastPlanSessionKeyRef = React.useRef<string>('');
|
||||
|
||||
const handleGitHubAccountSwitch = React.useCallback(async (accountId: string) => {
|
||||
@@ -843,6 +845,14 @@ export const Header: React.FC<HeaderProps> = ({
|
||||
}, [isSwitchingGitHubAccount, runtimeApis.github, setGitHubAuthStatus]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!planModeEnabled) {
|
||||
setPlanTabAvailable(false);
|
||||
if (useUIStore.getState().activeMainTab === 'plan') {
|
||||
useUIStore.getState().setActiveMainTab('chat');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
const checkExists = async (directory: string, fileName: string): Promise<boolean> => {
|
||||
@@ -903,6 +913,7 @@ export const Header: React.FC<HeaderProps> = ({
|
||||
window.clearInterval(interval);
|
||||
};
|
||||
}, [
|
||||
planModeEnabled,
|
||||
sessionDirectory,
|
||||
currentSession?.slug,
|
||||
currentSession?.time?.created,
|
||||
|
||||
@@ -18,6 +18,7 @@ import { RiCheckLine, RiClipboardLine, RiFileCopy2Line } from '@remixicon/react'
|
||||
import { useSessionUIStore } from '@/sync/session-ui-store';
|
||||
import { useSessions } from '@/sync/sync-context';
|
||||
import { useDirectoryStore } from '@/stores/useDirectoryStore';
|
||||
import { useFeatureFlagsStore } from '@/stores/useFeatureFlagsStore';
|
||||
import { useRuntimeAPIs } from '@/hooks/useRuntimeAPIs';
|
||||
import { EditorView } from '@codemirror/view';
|
||||
import { copyTextToClipboard } from '@/lib/clipboard';
|
||||
@@ -84,6 +85,7 @@ export const PlanView: React.FC = () => {
|
||||
const currentSessionId = useSessionUIStore((state) => state.currentSessionId);
|
||||
const sessions = useSessions();
|
||||
const homeDirectory = useDirectoryStore((state) => state.homeDirectory);
|
||||
const planModeEnabled = useFeatureFlagsStore((state) => state.planModeEnabled);
|
||||
const runtimeApis = useRuntimeAPIs();
|
||||
useUIStore();
|
||||
const { isMobile } = useDeviceInfo();
|
||||
@@ -256,6 +258,13 @@ export const PlanView: React.FC = () => {
|
||||
}, [currentTheme, resolvedPath]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!planModeEnabled) {
|
||||
setResolvedPath(null);
|
||||
setContent('');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
const readText = async (path: string): Promise<string> => {
|
||||
@@ -339,7 +348,7 @@ export const PlanView: React.FC = () => {
|
||||
cancelled = true;
|
||||
window.clearInterval(interval);
|
||||
};
|
||||
}, [sessionDirectory, session?.slug, session?.time?.created, homeDirectory, runtimeApis.files]);
|
||||
}, [planModeEnabled, sessionDirectory, session?.slug, session?.time?.created, homeDirectory, runtimeApis.files]);
|
||||
|
||||
React.useEffect(() => {
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user