Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ jobs:

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build:ci

- name: Install browsers
run: pnpm exec playwright install --with-deps chromium

- name: Test
run: pnpm test

- name: Lint
run: pnpm lint
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# mycoder

## 0.1.0

### Minor Changes

- Add support for browsing the web

## 0.0.23

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mycoder",
"description": "A command line tool using agent that can do arbitrary tasks, including coding tasks",
"version": "0.0.23",
"version": "0.1.0",
"type": "module",
"bin": "./bin/cli.js",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/browser/BrowserAutomation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class BrowserAutomation {
return BrowserAutomation.instance;
}

async createSession(headless: boolean = false) {
async createSession(headless: boolean = true) {
const session = await this.browserManager.createSession({ headless });
const pageController = new PageController(session.page);

Expand Down
2 changes: 1 addition & 1 deletion src/tools/browser/BrowserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
export class BrowserManager {
private sessions: Map<string, BrowserSession> = new Map();
private readonly defaultConfig: BrowserConfig = {
headless: false,
headless: true,
defaultTimeout: 30000,
};

Expand Down
12 changes: 7 additions & 5 deletions src/tools/browser/PageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
BrowserError,
BrowserErrorCode,
} from './types.js';
import { errorToString } from '../../utils/errorToString.js';

export class PageController {
constructor(private page: Page) {}
Expand All @@ -27,13 +28,14 @@ export class PageController {
}
}

private validateSelector(selector: string, type: SelectorType): void {
private validateSelector(selector: string, _type: SelectorType): void {
if (!selector) {
throw new BrowserError(
'Invalid selector: empty string',
BrowserErrorCode.SELECTOR_INVALID,
);
}
// TODO: Add more validation
}

async waitForSelector(
Expand All @@ -51,7 +53,7 @@ export class PageController {
});
} catch (error) {
throw new BrowserError(
`Failed to find element: ${error}`,
`Failed to find element: ${errorToString(error)}`,
BrowserErrorCode.ELEMENT_NOT_FOUND,
error,
);
Expand All @@ -67,7 +69,7 @@ export class PageController {
await locator.click({ timeout: options.timeout });
} catch (error) {
throw new BrowserError(
`Failed to click element: ${error}`,
`Failed to click element: ${errorToString(error)}`,
BrowserErrorCode.SELECTOR_ERROR,
error,
);
Expand All @@ -87,7 +89,7 @@ export class PageController {
await locator.fill(text, { timeout: options.timeout });
} catch (error) {
throw new BrowserError(
`Failed to type text: ${error}`,
`Failed to type text: ${errorToString(error)}`,
BrowserErrorCode.SELECTOR_ERROR,
error,
);
Expand All @@ -106,7 +108,7 @@ export class PageController {
return (await locator.textContent()) || '';
} catch (error) {
throw new BrowserError(
`Failed to get text: ${error}`,
`Failed to get text: ${errorToString(error)}`,
BrowserErrorCode.SELECTOR_ERROR,
error,
);
Expand Down
3 changes: 2 additions & 1 deletion src/tools/browser/browseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Tool } from '../../core/types.js';
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';
import { browserSessions, type BrowserAction, SelectorType } from './types.js';
import { errorToString } from '../../utils/errorToString.js';

// Schema for browser action
const browserActionSchema = z
Expand Down Expand Up @@ -141,7 +142,7 @@ export const browseMessageTool: Tool<Parameters, ReturnType> = {
logger.error('Browser action failed:', { error });
return {
status: 'error',
error: error instanceof Error ? error.message : String(error),
error: errorToString(error),
};
}
},
Expand Down
5 changes: 3 additions & 2 deletions src/tools/browser/browseStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
import { v4 as uuidv4 } from 'uuid';
import { chromium } from '@playwright/test';
import { browserSessions } from './types.js';
import { errorToString } from '../../utils/errorToString.js';

const parameterSchema = z.object({
url: z.string().url().optional().describe('Initial URL to navigate to'),
Expand Down Expand Up @@ -91,11 +92,11 @@ export const browseStartTool: Tool<Parameters, ReturnType> = {
content: content || undefined,
};
} catch (error) {
logger.error(`Failed to start browser: ${error}`);
logger.error(`Failed to start browser: ${errorToString(error)}`);
return {
instanceId: '',
status: 'error',
error: error instanceof Error ? error.message : String(error),
error: errorToString(error),
};
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/tools/system/shellStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const shellStartTool: Tool<Parameters, ReturnType> = {
stdout: '',
stderr: '',
exitCode: 1,
error: error instanceof Error ? error.message : String(error),
error: errorToString(error),
});
}
});
Expand Down
11 changes: 3 additions & 8 deletions src/utils/versionCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getSettingsDir } from '../settings/settings.js';
import * as fsPromises from 'fs/promises';
import * as fs from 'fs';
import * as semver from 'semver';
import { errorToString } from './errorToString.js';

const require = createRequire(import.meta.url);
const logger = new Logger({ name: 'version-check' });
Expand Down Expand Up @@ -76,19 +77,13 @@ export async function checkForUpdates(): Promise<string | null> {
return fsPromises.writeFile(versionFilePath, latestVersion, 'utf8');
})
.catch((error) => {
logger.warn(
'Error fetching latest version:',
error instanceof Error ? error.message : String(error),
);
logger.warn('Error fetching latest version:', errorToString(error));
});

return null;
} catch (error) {
// Log error but don't throw to handle gracefully
logger.warn(
'Error checking for updates:',
error instanceof Error ? error.message : String(error),
);
logger.warn('Error checking for updates:', errorToString(error));
return null;
}
}