Skip to content

Add custom CLI commands feature #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
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
93 changes: 93 additions & 0 deletions docs/custom-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Custom CLI Commands

MyCoder allows you to define custom CLI commands in your `mycoder.config.js` file. These commands can have arguments and will execute predefined prompts using JavaScript functions.

## Configuration

To add custom commands, add a `commands` section to your `mycoder.config.js` file:

```js
// mycoder.config.js
export default {
// ... other config options

// Custom commands
commands: {
search: {
description: 'Search for a term in the codebase',
args: [{ name: 'term', description: 'Search term', required: true }],
execute: (args) => {
return `Find all instances of ${args.term} in the codebase and suggest improvements`;
},
},

'fix-issue': {
description: 'Fix a GitHub issue',
args: [
{ name: 'issue', description: 'Issue number', required: true },
{ name: 'scope', description: 'Scope of the fix', default: 'full' },
],
execute: (args) => {
return `Analyze GitHub issue #${args.issue} and implement a ${args.scope} fix`;
},
},
},
};
```

## Command Structure

Each command in the `commands` object has the following properties:

- `description` (optional): A description of what the command does
- `args` (optional): An array of argument definitions
- `name`: The name of the argument
- `description` (optional): A description of the argument
- `required` (optional): Whether the argument is required (default: false)
- `default` (optional): Default value for the argument if not provided
- `execute` (required): A function that takes the arguments and returns a prompt string

## Using Commands

Once defined in your config file, you can use your custom commands like any other MyCoder command:

```bash
# Using the search command
mycoder search "deprecated API"

# Using the fix-issue command with all arguments
mycoder fix-issue 123 --scope partial

# Using the fix-issue command with default scope
mycoder fix-issue 123
```

## Advanced Usage

The `execute` function can also be asynchronous, allowing you to fetch data or perform other async operations before generating the prompt:

```js
"github-pr": {
description: "Review a GitHub PR",
args: [
{ name: "repo", description: "Repository name", required: true },
{ name: "pr", description: "PR number", required: true }
],
execute: async (args) => {
// You could fetch PR details here if needed
return `Review GitHub PR #${args.pr} in repository ${args.repo} and provide feedback`;
}
}
```

## Command Naming

Command names must:

- Start with a letter
- Contain only letters, numbers, hyphens, and underscores

## Limitations

- Custom commands cannot override built-in commands
- The `execute` function must return a string (the prompt to execute)
29 changes: 29 additions & 0 deletions mycoder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,33 @@ export default {
customPrompt: '',
profile: false,
tokenCache: true,

// Custom commands
// Uncomment and modify to add your own commands
/*
commands: {
// Function-based command example
"search": {
description: "Search for a term in the codebase",
args: [
{ name: "term", description: "Search term", required: true }
],
execute: (args) => {
return `Find all instances of ${args.term} in the codebase and suggest improvements`;
}
},

// Another example with multiple arguments
"fix-issue": {
description: "Fix a GitHub issue",
args: [
{ name: "issue", description: "Issue number", required: true },
{ name: "scope", description: "Scope of the fix", default: "full" }
],
execute: (args) => {
return `Analyze GitHub issue #${args.issue} and implement a ${args.scope} fix`;
}
}
}
*/
};
Loading
Loading