Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into spec-file-support
Browse files Browse the repository at this point in the history
  • Loading branch information
scottboyd-ai committed Jun 13, 2024
2 parents 7d2a027 + 66c7c10 commit 89b5f68
Show file tree
Hide file tree
Showing 17 changed files with 410 additions and 119 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.43](https://github.com/BuilderIO/micro-agent/compare/v0.0.42...v0.0.43) (2024-06-12)


### Features

* detect if in a valid project and generate one if not ([b8a5731](https://github.com/BuilderIO/micro-agent/commit/b8a5731e82fd5541c738cdf094870fbac035386b))

### [0.0.42](https://github.com/BuilderIO/micro-agent/compare/v0.0.41...v0.0.42) (2024-06-12)

### Bug Fixes

- default to vitest if no existing testing library ([1a71f6a](https://github.com/BuilderIO/micro-agent/commit/1a71f6a2c123ae48022b9ff66e13a80c03a6d301))

### [0.0.41](https://github.com/BuilderIO/micro-agent/compare/v0.0.40...v0.0.41) (2024-06-12)

### [0.0.40](https://github.com/BuilderIO/micro-agent/compare/v0.0.39...v0.0.40) (2024-06-12)

### [0.0.39](https://github.com/BuilderIO/micro-agent/compare/v0.0.38...v0.0.39) (2024-06-12)

### [0.0.37](https://github.com/BuilderIO/micro-agent/compare/v0.0.36...v0.0.37) (2024-06-12)

### [0.0.36](https://github.com/BuilderIO/micro-agent/compare/v0.0.35...v0.0.36) (2024-06-12)

### [0.0.34](https://github.com/BuilderIO/micro-agent/compare/v0.0.33...v0.0.34) (2024-06-11)

### [0.0.32](https://github.com/BuilderIO/micro-agent/compare/v0.0.31...v0.0.32) (2024-06-11)
Expand Down
16 changes: 1 addition & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,7 @@ npm start
First, install prettier.

```sh
npm install -g prettier
```

Once Prettier is installed, you can run it on a single file or multiple files using the following commands:

1. For a single file:

```sh
prettier --write path/to/your/file.js
```

2. For a multiple file:

```sh
prettier --write "src/**/*.js"
npm run lint:fix
```

If you use Vscode, It is recommended to use [prettier-vscode](https://github.com/prettier/prettier-vscode)
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,26 @@ All config options can be overridden as environment variables, for instance:
MODEL=gpt-3.5-turbo micro-agent ./file-to-edit.ts -t "npm test"
```

### Upgrading

Check the installed version with:

```bash
micro-agent --version
```

If it's not the [latest version](https://github.com/BuilderIO/micro-agent/tags), run:

```bash
micro-agent update
```

Or manually update with:

```bash
npm update -g @builder.io/micro-agent
```

## Contributing

We would love your contributions to make this project better, and gladly accept PRs. Please see [./CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute.
Expand All @@ -214,7 +234,6 @@ Usage:

Commands:
config Configure the CLI
run Run the micro agent from the given prompt and test script.
update Update Micro Agent to the latest version

Flags:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@builder.io/micro-agent",
"description": "An AI CLI that writes code for you.",
"version": "0.0.34",
"version": "0.0.43",
"type": "module",
"dependencies": {
"@anthropic-ai/sdk": "^0.21.1",
Expand Down Expand Up @@ -45,7 +45,7 @@
"lint": "prettier --check . && eslint",
"typecheck": "tsc",
"build": "pkgroll",
"release:patch": "npm run build && npm version patch && npm run build && npm publish && git push --follow-tags && standard-version --release-as patch",
"release:patch": "npm run build && standard-version --release-as patch git push --follow-tags origin main && npm publish",
"standard-version:release": "standard-version",
"standard-version:release:minor": "standard-version --release-as minor",
"standard-version:release:major": "standard-version --release-as major",
Expand Down
10 changes: 9 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { RunOptions, runAll } from './helpers/run';
import { interactiveMode } from './helpers/interactive-mode';
import { fileExists } from './helpers/file-exists';
import { outro } from '@clack/prompts';
import { isValidProject } from './helpers/validate-project';
import { invalidProjectWarningMessage } from './helpers/invalid-project-warning';

cli(
{
Expand Down Expand Up @@ -111,7 +113,13 @@ cli(
};
try {
if (!argv._.filePath || !argv.flags.test) {
await interactiveMode(runOptions);
const isValidproject = await isValidProject();

if (!isValidproject) {
await invalidProjectWarningMessage();
} else {
await interactiveMode(runOptions);
}
return;
}

Expand Down
9 changes: 9 additions & 0 deletions src/helpers/add-numbers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function addNumbers(a: any, b: any): number {
// Validate that both inputs are numbers
if (typeof a !== 'number' || typeof b !== 'number') {
throw new Error('Both arguments must be numbers');
}

// Return the sum of the two numbers
return a + b;
}
21 changes: 21 additions & 0 deletions src/helpers/find-package-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as fs from 'fs/promises';
import * as path from 'path';
import { fileExists } from './file-exists';

/**
* Find package.json file in the given directory or any
* parent directory.
*/
export async function findPackageJson(
directory = process.cwd()
): Promise<string | null> {
let currentDirectory = directory;
while (currentDirectory !== '/') {
const packageJsonPath = path.join(currentDirectory, 'package.json');
if (await fileExists(packageJsonPath)) {
return fs.readFile(packageJsonPath, 'utf-8');
}
currentDirectory = path.dirname(currentDirectory);
}
return null;
}
10 changes: 9 additions & 1 deletion src/helpers/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ export async function generate(options: RunOptions) {
</package-json>`
}
Please give me the code that satisfies the prompt and test.
Please update the code (or generate all new code if needed) to satisfy the prompt and test.
Be sure to use good coding conventions. For instance, if you are generating a typescript
file, use types (e.g. for function parameters, etc).
${
!options.interactive &&
dedent`
If there is already existing code, strictly maintain the same coding style as the existing code.
Any updated code should look like its written by the same person/team that wrote the original code.
`
}
`;

if (process.env.MA_DEBUG) {
Expand Down
48 changes: 48 additions & 0 deletions src/helpers/get-test-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import dedent from 'dedent';
import { findPackageJson } from './find-package-json';
import { getSimpleCompletion } from './llm';
import { removeBackticks } from './remove-backticks';

export async function getTestCommand({
testFilePath,
}: {
testFilePath: string;
}) {
const defaultTestCommand = `npm test -- ${
testFilePath.split('/').pop()!.split('.')[0]
}`;

const packageJson = await findPackageJson();
if (!packageJson) {
return defaultTestCommand;
}

const suggestion = removeBackticks(
await getSimpleCompletion({
messages: [
{
role: 'system',
content:
'You take a prompt and return a single line shell command and nothing else',
},
{
role: 'user',
content: dedent`
Here is my package.json. I want to run a single command to run the tests (e.g. "npm run test"). The tests should not run in watch mode, they should
exit once completed. Bonus points if the command only runs this specific test \`${testFilePath}\` such as \`npm test -- ${
testFilePath.split('/').pop()!.split('.')[0]
}\`.
<package-json>
${packageJson}
</package-json>
If there are no testing libraryes in the package.json, \`npx vitest ...\` is a good option.
`,
},
],
})
);

return suggestion || defaultTestCommand;
}
Loading

0 comments on commit 89b5f68

Please sign in to comment.