diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index b9b06ac1a6..2046b472d1 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -300,7 +300,9 @@ const ComposerCommandMenu = memo(function ComposerCommandMenu(props: { { - props.onHighlightedItemChange(typeof highlightedValue === "string" ? highlightedValue : null); + props.onHighlightedItemChange( + typeof highlightedValue === "string" ? highlightedValue : null, + ); }} >
@@ -670,9 +672,7 @@ export default function ChatView() { }); const targetCwd = options?.cwd ?? gitCwd ?? activeProject.cwd; const baseTerminalId = - activeThread.activeTerminalId || - activeThread.terminalIds[0] || - DEFAULT_THREAD_TERMINAL_ID; + activeThread.activeTerminalId || activeThread.terminalIds[0] || DEFAULT_THREAD_TERMINAL_ID; const isBaseTerminalBusy = activeThread.runningTerminalIds.includes(baseTerminalId); const wantsNewTerminal = Boolean(options?.preferNewTerminal) || isBaseTerminalBusy; const shouldCreateNewTerminal = @@ -739,6 +739,63 @@ export default function ChatView() { }, [activeProject, activeThread, activeThreadId, api, dispatch, gitCwd], ); + const persistScriptsUpdate = useCallback( + async ( + project: NonNullable, + nativeApi: NativeApi, + nextScripts: ProjectScript[], + scriptCommandId: string, + input: NewProjectScriptInput, + ) => { + let scriptsPersisted = false; + try { + const updated = await nativeApi.projects.updateScripts({ + id: project.id, + scripts: nextScripts, + }); + scriptsPersisted = true; + + if (input.keybinding) { + const keybindingUpdate = await nativeApi.server.upsertKeybinding({ + key: input.keybinding, + command: commandForProjectScript(scriptCommandId), + }); + queryClient.setQueryData( + serverQueryKeys.config(), + (current: { cwd: string; keybindings: ResolvedKeybindingsConfig } | undefined) => + current + ? { ...current, keybindings: keybindingUpdate.keybindings } + : { + cwd: project.cwd, + keybindings: keybindingUpdate.keybindings, + }, + ); + } + + dispatch({ + type: "SET_PROJECT_SCRIPTS", + projectId: updated.project.id, + scripts: updated.project.scripts, + }); + } catch (error) { + if (scriptsPersisted) { + await nativeApi.projects + .updateScripts({ + id: project.id, + scripts: project.scripts, + }) + .catch(() => undefined); + } + dispatch({ + type: "SET_PROJECT_SCRIPTS", + projectId: project.id, + scripts: project.scripts, + }); + throw error; + } + }, + [dispatch, queryClient], + ); const saveProjectScript = useCallback( async (input: NewProjectScriptInput) => { if (!activeProject) return; @@ -769,54 +826,9 @@ export default function ChatView() { }); if (!isElectron || !api) return; - let scriptsPersisted = false; - try { - const updated = await api.projects.updateScripts({ - id: activeProject.id, - scripts: nextScripts, - }); - scriptsPersisted = true; - - if (input.keybinding) { - const keybindingUpdate = await api.server.upsertKeybinding({ - key: input.keybinding, - command: commandForProjectScript(nextId), - }); - queryClient.setQueryData( - serverQueryKeys.config(), - (current: { cwd: string; keybindings: ResolvedKeybindingsConfig } | undefined) => - current - ? { ...current, keybindings: keybindingUpdate.keybindings } - : { - cwd: activeProject.cwd, - keybindings: keybindingUpdate.keybindings, - }, - ); - } - - dispatch({ - type: "SET_PROJECT_SCRIPTS", - projectId: updated.project.id, - scripts: updated.project.scripts, - }); - } catch (error) { - if (scriptsPersisted) { - await api.projects - .updateScripts({ - id: activeProject.id, - scripts: activeProject.scripts, - }) - .catch(() => undefined); - } - dispatch({ - type: "SET_PROJECT_SCRIPTS", - projectId: activeProject.id, - scripts: activeProject.scripts, - }); - throw error; - } + await persistScriptsUpdate(activeProject, api, nextScripts, nextId, input); }, - [activeProject, api, dispatch, queryClient], + [activeProject, api, dispatch, persistScriptsUpdate], ); const updateProjectScript = useCallback( async (scriptId: string, input: NewProjectScriptInput) => { @@ -848,54 +860,9 @@ export default function ChatView() { }); if (!isElectron || !api) return; - let scriptsPersisted = false; - try { - const updated = await api.projects.updateScripts({ - id: activeProject.id, - scripts: nextScripts, - }); - scriptsPersisted = true; - - if (input.keybinding) { - const keybindingUpdate = await api.server.upsertKeybinding({ - key: input.keybinding, - command: commandForProjectScript(scriptId), - }); - queryClient.setQueryData( - serverQueryKeys.config(), - (current: { cwd: string; keybindings: ResolvedKeybindingsConfig } | undefined) => - current - ? { ...current, keybindings: keybindingUpdate.keybindings } - : { - cwd: activeProject.cwd, - keybindings: keybindingUpdate.keybindings, - }, - ); - } - - dispatch({ - type: "SET_PROJECT_SCRIPTS", - projectId: updated.project.id, - scripts: updated.project.scripts, - }); - } catch (error) { - if (scriptsPersisted) { - await api.projects - .updateScripts({ - id: activeProject.id, - scripts: activeProject.scripts, - }) - .catch(() => undefined); - } - dispatch({ - type: "SET_PROJECT_SCRIPTS", - projectId: activeProject.id, - scripts: activeProject.scripts, - }); - throw error; - } + await persistScriptsUpdate(activeProject, api, nextScripts, scriptId, input); }, - [activeProject, api, dispatch, queryClient], + [activeProject, api, dispatch, persistScriptsUpdate], ); const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => { diff --git a/apps/web/src/components/ProjectScriptsControl.tsx b/apps/web/src/components/ProjectScriptsControl.tsx index dd523fce58..163b552ac3 100644 --- a/apps/web/src/components/ProjectScriptsControl.tsx +++ b/apps/web/src/components/ProjectScriptsControl.tsx @@ -292,7 +292,7 @@ export default function ProjectScriptsControl({ > - {script.runOnWorktreeCreate ? `${script.name}` : script.name} + {script.runOnWorktreeCreate ? `${script.name} (setup)` : script.name} {shortcutLabel && (