Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions ui/desktop/src/goosed.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { spawn } from 'child_process';
import { spawn, ChildProcess } from 'child_process';
import { createServer } from 'net';
import os from 'node:os';
import path from 'node:path';
import { getBinaryPath } from './utils/binaryPath';
import log from './utils/logger';
import { ChildProcessByStdio } from 'node:child_process';
import { Readable, Buffer } from 'node:stream';
import { Buffer } from 'node:stream';
import { App } from 'electron';
import type { ProcessEnv } from 'node:process';

Expand Down Expand Up @@ -66,7 +65,7 @@ export const startGoosed = async (
app: App,
dir: string | null = null,
env: Partial<GooseProcessEnv> = {}
): Promise<[number, string, ChildProcessByStdio<null, Readable, Readable>]> => {
) => {
// we default to running goosed in home dir - if not specified
const homeDir = os.homedir();
const isWindows = process.platform === 'win32';
Expand Down Expand Up @@ -135,7 +134,7 @@ export const startGoosed = async (
const spawnOptions = {
cwd: dir,
env: processEnv,
stdio: ['ignore', 'pipe', 'pipe'] as ['ignore', 'pipe', 'pipe'],
stdio: ['ignore', 'pipe', 'pipe'] as const,
// Hide terminal window on Windows
windowsHide: true,
// Run detached on Windows only to avoid terminal windows
Expand All @@ -148,18 +147,18 @@ export const startGoosed = async (
log.info('Spawn options:', JSON.stringify(spawnOptions, null, 2));

// Spawn the goosed process
const goosedProcess = spawn(goosedPath, ['agent'], spawnOptions);
const goosedProcess: ChildProcess = spawn(goosedPath, ['agent'], spawnOptions);
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

// Only unref on Windows to allow it to run independently of the parent
if (isWindows) {
goosedProcess.unref();
goosedProcess.unref?.();
}

goosedProcess.stdout.on('data', (data: Buffer) => {
goosedProcess.stdout?.on('data', (data: Buffer) => {
log.info(`goosed stdout for port ${port} and dir ${dir}: ${data.toString()}`);
});

goosedProcess.stderr.on('data', (data: Buffer) => {
goosedProcess.stderr?.on('data', (data: Buffer) => {
log.error(`goosed stderr for port ${port} and dir ${dir}: ${data.toString()}`);
});

Expand All @@ -180,9 +179,9 @@ export const startGoosed = async (
try {
if (isWindows) {
// On Windows, use taskkill to forcefully terminate the process tree
spawn('taskkill', ['/pid', goosedProcess.pid.toString(), '/T', '/F']);
spawn('taskkill', ['/pid', goosedProcess.pid?.toString() || "0", '/T', '/F']);
} else {
goosedProcess.kill();
goosedProcess.kill?.();
}
} catch (error) {
log.error('Error while terminating goosed process:', error);
Expand All @@ -197,9 +196,9 @@ export const startGoosed = async (
try {
if (isWindows) {
// On Windows, use taskkill to forcefully terminate the process tree
spawn('taskkill', ['/pid', goosedProcess.pid.toString(), '/T', '/F']);
spawn('taskkill', ['/pid', goosedProcess.pid?.toString() || "0", '/T', '/F']);
} else {
goosedProcess.kill();
goosedProcess.kill?.();
}
} catch (error) {
log.error('Error while terminating goosed process:', error);
Expand Down
20 changes: 11 additions & 9 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ const createChat = async (
// Handle window closure
mainWindow.on('closed', () => {
windowMap.delete(windowId);
if (goosedProcess) {
if (goosedProcess && typeof goosedProcess === 'object' && 'kill' in goosedProcess) {
goosedProcess.kill();
}
});
Expand Down Expand Up @@ -651,7 +651,7 @@ const buildRecentFilesMenu = () => {
const openDirectoryDialog = async (replaceWindow: boolean = false) => {
const result = await dialog.showOpenDialog({
properties: ['openFile', 'openDirectory'],
});
}) as { canceled: boolean; filePaths: string[] };

if (!result.canceled && result.filePaths.length > 0) {
addRecentDir(result.filePaths[0]);
Expand Down Expand Up @@ -706,7 +706,7 @@ ipcMain.handle('directory-chooser', (_event, replace: boolean = false) => {
ipcMain.handle('select-file-or-directory', async () => {
const result = await dialog.showOpenDialog({
properties: process.platform === 'darwin' ? ['openFile', 'openDirectory'] : ['openFile'],
});
}) as { canceled: boolean; filePaths: string[] };

if (!result.canceled && result.filePaths.length > 0) {
return result.filePaths[0];
Expand Down Expand Up @@ -1618,24 +1618,26 @@ app.on('before-quit', (event) => {
event.preventDefault();

// Show confirmation dialog
dialog
.showMessageBox({
try {
const result = await dialog.showMessageBox({
type: 'question',
buttons: ['Quit', 'Cancel'],
defaultId: 1, // Default to Cancel
title: 'Confirm Quit',
message: 'Are you sure you want to quit Goose?',
detail: 'Any unsaved changes may be lost.',
})
.then(({ response }: { response: number }) => {
if (response === 0) {
}) as { response: number };

if (result.response === 0) {
// User clicked "Quit"
// Set a flag to avoid showing the dialog again
app.removeAllListeners('before-quit');
// Actually quit the app
app.quit();
}
});
} catch (error) {
console.error('Error showing quit dialog:', error);
}
});

app.on('window-all-closed', () => {
Expand Down
2 changes: 1 addition & 1 deletion ui/desktop/src/utils/providerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const initializeSystem = async (

// Get recipeConfig directly here
const recipeConfig = window.appConfig?.get?.('recipeConfig');
const botPrompt = recipeConfig?.instructions;
const botPrompt = (recipeConfig as { instructions?: string })?.instructions;
// Extend the system prompt with desktop-specific information
const response = await fetch(getApiUrl('/agent/prompt'), {
method: 'POST',
Expand Down