From fe6cb72677971e33ca7bd8b3823df0658702363b Mon Sep 17 00:00:00 2001 From: Matthew Diamant Date: Thu, 27 Feb 2025 16:48:58 -0800 Subject: [PATCH] feat(desktop-ui): View and edit .goosehints file (#1431) --- ui/desktop/src/components/BottomMenu.tsx | 5 + .../src/components/ConfigureGooseHints.tsx | 158 ++++++++++++++++++ ui/desktop/src/main.ts | 35 ++++ ui/desktop/src/preload.ts | 4 + 4 files changed, 202 insertions(+) create mode 100644 ui/desktop/src/components/ConfigureGooseHints.tsx diff --git a/ui/desktop/src/components/BottomMenu.tsx b/ui/desktop/src/components/BottomMenu.tsx index bc8e1132..8d92e787 100644 --- a/ui/desktop/src/components/BottomMenu.tsx +++ b/ui/desktop/src/components/BottomMenu.tsx @@ -5,6 +5,7 @@ import { Sliders } from 'lucide-react'; import { ModelRadioList } from './settings/models/ModelRadioList'; import { Document, ChevronUp, ChevronDown } from './icons'; import type { View } from '../ChatWindow'; +import { ConfigureGooseHints } from './ConfigureGooseHints'; export default function BottomMenu({ hasMessages, @@ -76,6 +77,10 @@ export default function BottomMenu({ +
+ +
+ {/* Model Selector Dropdown - Only in development */}
( +
+ +
{children}
+
+
+); + +const ModalHeader = () => ( +
+
+

Configure .goosehints

+
+
+); + +const ModalHelpText = () => ( +
+

+ .goosehints is a text file used to provide additional context about your project and improve + the communication with Goose. +

+

You'll need to restart your session for .goosehints updates to take effect.

+

+ See{' '} + {' '} + for more information. +

+
+); + +const ModalError = ({ error }) => ( +
+
Error reading .goosehints file: {JSON.stringify(error)}
+
+); + +const ModalFileInfo = ({ filePath, found }) => ( +
+ {found ? ( +
+ .goosehints file found at: {filePath} +
+ ) : ( +
Creating new .goosehints file at: {filePath}
+ )} +
+); + +const ModalButtons = ({ onSubmit, onCancel }) => ( +
+ + +
+); + +const getGoosehintsFile = async (filePath) => await window.electron.readFile(filePath); + +type GoosehintsModalProps = { + directory: string; + setIsGoosehintsModalOpen: (isOpen: boolean) => void; +}; +const GoosehintsModal = ({ directory, setIsGoosehintsModalOpen }: GoosehintsModalProps) => { + const goosehintsFilePath = `${directory}/.goosehints`; + const [goosehintsFile, setGoosehintsFile] = useState(null); + const [goosehintsFileFound, setGoosehintsFileFound] = useState(false); + const [goosehintsFileReadError, setGoosehintsFileReadError] = useState(null); + + useEffect(() => { + const fetchGoosehintsFile = async () => { + try { + const { file, error, found } = await getGoosehintsFile(goosehintsFilePath); + setGoosehintsFile(file); + setGoosehintsFileFound(found); + setGoosehintsFileReadError(error); + } catch (error) { + console.error('Error fetching .goosehints file:', error); + } + }; + if (directory) fetchGoosehintsFile(); + }, [directory, goosehintsFilePath]); + + const writeFile = async () => { + await window.electron.writeFile(goosehintsFilePath, goosehintsFile); + setIsGoosehintsModalOpen(false); + }; + + return ( + + + +
+ {goosehintsFileReadError ? ( + + ) : ( +
+ +