Skip to content

Commit f123168

Browse files
authored
🤖 fix: sync creation preferences on workspace handoff (#633)
- copy project-scoped mode/thinking preferences into the new workspace immediately after creation - keep workspace providers unchanged so runtime view picks up the persisted values naturally
1 parent 1c45bc3 commit f123168

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/browser/components/ChatInput/useCreationWorkspace.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
11
import { useState, useEffect, useCallback } from "react";
22
import type { FrontendWorkspaceMetadata } from "@/common/types/workspace";
33
import type { RuntimeConfig, RuntimeMode } from "@/common/types/runtime";
4+
import type { UIMode } from "@/common/types/mode";
5+
import type { ThinkingLevel } from "@/common/types/thinking";
46
import { parseRuntimeString } from "@/browser/utils/chatCommands";
57
import { useDraftWorkspaceSettings } from "@/browser/hooks/useDraftWorkspaceSettings";
8+
import { readPersistedState, updatePersistedState } from "@/browser/hooks/usePersistedState";
69
import { useSendMessageOptions } from "@/browser/hooks/useSendMessageOptions";
7-
import { getProjectScopeId } from "@/common/constants/storage";
10+
import { getModeKey, getProjectScopeId, getThinkingLevelKey } from "@/common/constants/storage";
811
import { extractErrorMessage } from "./utils";
912

1013
interface UseCreationWorkspaceOptions {
1114
projectPath: string;
1215
onWorkspaceCreated: (metadata: FrontendWorkspaceMetadata) => void;
1316
}
1417

18+
function syncCreationPreferences(projectPath: string, workspaceId: string): void {
19+
const projectScopeId = getProjectScopeId(projectPath);
20+
21+
const projectMode = readPersistedState<UIMode | null>(getModeKey(projectScopeId), null);
22+
if (projectMode) {
23+
updatePersistedState(getModeKey(workspaceId), projectMode);
24+
}
25+
26+
const projectThinking = readPersistedState<ThinkingLevel | null>(
27+
getThinkingLevelKey(projectScopeId),
28+
null
29+
);
30+
if (projectThinking) {
31+
updatePersistedState(getThinkingLevelKey(workspaceId), projectThinking);
32+
}
33+
}
34+
1535
interface UseCreationWorkspaceReturn {
1636
branches: string[];
1737
trunkBranch: string;
@@ -97,6 +117,7 @@ export function useCreationWorkspace({
97117

98118
// Check if this is a workspace creation result (has metadata field)
99119
if ("metadata" in result && result.metadata) {
120+
syncCreationPreferences(projectPath, result.metadata.id);
100121
// Settings are already persisted via useDraftWorkspaceSettings
101122
// Notify parent to switch workspace (clears input via parent unmount)
102123
onWorkspaceCreated(result.metadata);

0 commit comments

Comments
 (0)