Skip to content

Commit

Permalink
add in built in extensions and fix loading (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneale authored Jan 23, 2025
1 parent dc26530 commit 6b7ef17
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
11 changes: 8 additions & 3 deletions ui/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ export default function App() {
window.electron.on('fatal-error', handleFatalError);

// Load stored extension configs when the app starts
loadStoredExtensionConfigs().catch((error) => {
console.error('Failed to load stored extension configs:', error);
});
// delay this by a few seconds
setTimeout(() => {
window.electron.logInfo('App.tsx: Loading stored extension configs');
loadStoredExtensionConfigs().catch((error) => {
console.error('Failed to load stored extension configs:', error);
window.electron.logInfo('App.tsx: Failed to load stored extension configs ' + error);
});
}, 5000);

return () => {
window.electron.off('fatal-error', handleFatalError);
Expand Down
48 changes: 47 additions & 1 deletion ui/desktop/src/components/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,59 @@ const DEFAULT_SETTINGS: SettingsType = {
extensions: [],
};

const BUILT_IN_EXTENSIONS = [
{
id: 'jetbrains',
name: 'Jetbrains',
type: 'stdio',
cmd: 'goosed',
args: ['mcp', 'jetbrains'],
description: 'Integration with any Jetbrains IDE',
enabled: false,
env_keys: [],
},
{
id: 'nondeveloper',
name: 'Non-Developer assistant',
type: 'stdio',
cmd: 'goosed',
args: ['mcp', 'nondeveloper'],
description: "General assisant tools that don't require you to be a developer or engineer.",
enabled: false,
env_keys: [],
},
{
id: 'memory',
name: 'Memory',
type: 'stdio',
cmd: 'goosed',
args: ['mcp', 'memory'],
description: 'Teach goose your preferences as you go.',
enabled: false,
env_keys: [],
},
];

export default function Settings() {
const navigate = useNavigate();
const location = useLocation();

const [settings, setSettings] = React.useState<SettingsType>(() => {
const saved = localStorage.getItem('user_settings');
return saved ? JSON.parse(saved) : DEFAULT_SETTINGS;
window.electron.logInfo('Settings: ' + saved);
let currentSettings = saved ? JSON.parse(saved) : DEFAULT_SETTINGS;

// Ensure built-in extensions are included if not already present
BUILT_IN_EXTENSIONS.forEach((builtIn) => {
const exists = currentSettings.extensions.some(
(ext: FullExtensionConfig) => ext.id === builtIn.id
);
if (!exists) {
currentSettings.extensions.push(builtIn);
}
});

return currentSettings;
});

const [extensionBeingConfigured, setExtensionBeingConfigured] =
Expand Down
14 changes: 11 additions & 3 deletions ui/desktop/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,26 @@ export const loadStoredExtensionConfigs = async (): Promise<void> => {
try {
const userSettingsStr = localStorage.getItem('user_settings');

//console.log('Loading stored extension configs from user_settings', userSettingsStr);

if (userSettingsStr) {
const userSettings = JSON.parse(userSettingsStr);
const enabledExtensions = userSettings.extensions.filter((ext: any) => ext.enabled);
//console.log('Enabled extensions:', enabledExtensions);

for (const ext of enabledExtensions) {
// Convert extension format back to ExtensionConfig
console.log('Loading extension:', ext);

const config: ExtensionConfig = {
type: 'stdio', // Assuming all stored extensions are stdio type for now
cmd: ext.command,
args: [],
env_keys: ext.environmentVariables?.map((env: any) => env.name) || [],
cmd: ext.cmd,
args: ext.args || [],
env_keys: ext.env_keys || [],
};

console.log('ext config', config);

await extendGoosed(config);
}

Expand Down Expand Up @@ -101,6 +108,7 @@ export const replaceWithShims = async (cmd: string): Promise<string> => {

// Extend Goosed with a new system configuration
export const extendGoosed = async (config: ExtensionConfig) => {
console.log('extendGoosed', config);
// allowlist the CMD for stdio type
if (config.type === 'stdio') {
const allowedCMDs = ['goosed', 'npx', 'uvx'];
Expand Down

0 comments on commit 6b7ef17

Please sign in to comment.