10000 Add custom CLI commands feature · drivecore/mycoder@ccec2f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit ccec2f0

Browse files
committed
Add custom CLI commands feature
1 parent 1bffa4d commit ccec2f0

File tree

< 10000 span class="prc-TooltipV2-Tooltip-cYMVY" data-direction="se" aria-hidden="true" id=":R2atdab:">Expand file tree

6 files changed

+423
-180
lines changed

6 files changed

+423
-180
lines changed

docs/custom-commands.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Custom CLI Commands
2+
3+
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.
4+
5+
## Configuration
6+
7+
To add custom commands, add a `commands` section to your `mycoder.config.js` file:
8+
9+
```js
10+
// mycoder.config.js
11+
export default {
12+
// ... other config options
13+
14+
// Custom commands
15+
commands: {
16+
search: {
17+
description: 'Search for a term in the codebase',
18+
args: [{ name: 'term', description: 'Search term', required: true }],
19+
execute: (args) => {
20+
return `Find all instances of ${args.term} in the codebase and suggest improvements`;
21+
},
22+
},
23+
24+
'fix-issue': {
25+
description: 'Fix a GitHub issue',
26+
args: [
27+
{ name: 'issue', description: 'Issue number', required: true },
28+
{ name: 'scope', description: 'Scope of the fix', default: 'full' },
29+
],
30+
execute: (args) => {
31+
return `Analyze GitHub issue #${args.issue} and implement a ${args.scope} fix`;
32+
},
33+
},
34+
},
35+
};
36+
```
37+
38+
## Command Structure
39+
40+
Each command in the `commands` object has the following properties:
41+
42+
- `description` (optional): A description of what the command does
43+
- `args` (optional): An array of argument definitions
44+
- `name`: The name of the argument
45+
- `description` (optional): A description of the argument
46+
- `required` (optional): Whether the argument is required (default: false)
47+
- `default` (optional): Default value for the argument if not provided
48+
- `execute` (required): A function that takes the arguments and returns a prompt string
49+
50+
## Using Commands
51+
52+
Once defined in your config file, you can use your custom commands like any other MyCoder command:
53+
54+
```bash
55+
# Using the search command
56+
mycoder search "deprecated API"
57+
58+
# Using the fix-issue command with all arguments
59+
mycoder fix-issue 123 --scope partial
60+
61+
# Using the fix-issue command with default scope
62+
mycoder fix-issue 123
63+
```
64+
65+
## Advanced Usage
66+
67+
The `execute` function can also be asynchronous, allowing you to fetch data or perform other async operations before generating the prompt:
68+
69+
```js
70+
"github-pr": {
71+
description: "Review a GitHub PR",
72+
args: [
73+
{ name: "repo", description: "Repository name", required: true },
74+
{ name: "pr", description: "PR number", required: true }
75+
],
76+
execute: async (args) => {
77+
// You could fetch PR details here if needed
78+
return `Review GitHub PR #${args.pr} in repository ${args.repo} and provide feedback`;
79+
}
80+
}
81+
```
82+
83+
## Command Naming
84+
85+
Command names must:
86+
87+
- Start with a letter
88+
- Contain only letters, numbers, hyphens, and underscores
89+
90+
## Limitations
91+
92+
- Custom commands cannot override built-in commands
93+
- The `execute` function must return a string (the prompt to execute)

mycoder.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,33 @@ export default {
2323
customPrompt: '',
2424
profile: false,
2525
tokenCache: true,
26+
27+
// Custom commands
28+
// Uncomment and modify to add your own commands
29+
/*
30+
commands: {
31+
// Function-based command example
32+
"search": {
33+
description: "Search for a term in the codebase",
34+
args: [
35+
{ name: "term", description: "Search term", required: true }
36+
],
37+
execute: (args) => {
38+
return `Find all instances of ${args.term} in the codebase and suggest improvements`;
39+
}
40+
},
41+
42+
// Another example with multiple arguments
43+
"fix-issue": {
44+
description: "Fix a GitHub issue",
45+
args: [
46+
{ name: "issue", description: "Issue number", required: true },
47+
{ name: "scope", description: "Scope of the fix", default: "full" }
48+
],
49+
execute: (args) => {
50+
return `Analyze GitHub issue #${args.issue} and implement a ${args.scope} fix`;
51+
}
52+
}
53+
}
54+
*/
2655
};

0 commit comments

Comments
 (0)
0