I am trying to create a custom slash command in Continue.dev that generates a Git commit message. /customize/slash-commands /customize/tutorials/build-your-own-slash-command
The command works fine when I call it as /commit_message_any_changes
, but I want to modify it so I can pass an argument like this:
/commit_message_any_changes FA-92
This argument (FA-92
) should be included in the output, like this:
git commit -m "[FA-92 | Documentation] Updated files with more details of the change."
Here’s my slash command definition:
export function modifyConfig(config: Config): Config {
config.slashCommands?.push({
name: "commit_message_any_changes",
description: "Write a commit message for all local changes",
run: async function* (sdk) {
const diff = await sdk.ide.getDiff(true);
const prompt = `${diff}\n\nWrite a commit message for the above changes. Write it all in one line and make it very concise and adhere to the following style: git commit -m "[ID-XY | Categories] Affected files or feature: more details of the change."\n Categories should be similar or one of these: [Cleanup|Documentation|Refactoring|UI|Navigation|Content Update|Functionality|New Feature|BugFix]. Ideally, it should only be one category, but if the changes are bigger, a max of 2 categories can be used.\n\nIf there are no changes, write "No changes" and stop.`;
const controller = new AbortController();
for await (const message of sdk.llm.streamComplete(prompt, controller.signal, { maxTokens: 50 })) {
yield message;
}
},
});
return config;
}
This works fine for generating a commit message, but it doesn't allow me to pass a custom ID (like FA-92
) as an argument.
When I try to change the run
method to accept arguments (e.g., (sdk: any, args: any)
), I get the following TypeScript error:
Type '(sdk: any, args: any) => AsyncGenerator<any, void, unknown>' is not assignable to type '(sdk: ContinueSDK) => AsyncGenerator<string | undefined, any, any>'.
Target signature provides too few arguments. Expected 2 or more, but got 1.ts(2322)
I found in the Continue.dev documentation that it is possible to use custom HTTP endpoints for slash commands, but I’m not sure how to integrate this while still allowing my command to process the diff
and include the provided ID in the commit message.
run
method to accept args
—this leads to the TypeScript error above.I want to be able to call the command like this:
/commit_message_any_changes FA-92
And get an output like:
git commit -m "[FA-92 | Documentation] Updated files with more details of the change."
How can I modify my slash command to accept arguments (like FA-92
) while adhering to the required method signature?
I am trying to create a custom slash command in Continue.dev that generates a Git commit message. https://docs.continue.dev/customize/slash-commands https://docs.continue.dev/customize/tutorials/build-your-own-slash-command
The command works fine when I call it as /commit_message_any_changes
, but I want to modify it so I can pass an argument like this:
/commit_message_any_changes FA-92
This argument (FA-92
) should be included in the output, like this:
git commit -m "[FA-92 | Documentation] Updated files with more details of the change."
Here’s my slash command definition:
export function modifyConfig(config: Config): Config {
config.slashCommands?.push({
name: "commit_message_any_changes",
description: "Write a commit message for all local changes",
run: async function* (sdk) {
const diff = await sdk.ide.getDiff(true);
const prompt = `${diff}\n\nWrite a commit message for the above changes. Write it all in one line and make it very concise and adhere to the following style: git commit -m "[ID-XY | Categories] Affected files or feature: more details of the change."\n Categories should be similar or one of these: [Cleanup|Documentation|Refactoring|UI|Navigation|Content Update|Functionality|New Feature|BugFix]. Ideally, it should only be one category, but if the changes are bigger, a max of 2 categories can be used.\n\nIf there are no changes, write "No changes" and stop.`;
const controller = new AbortController();
for await (const message of sdk.llm.streamComplete(prompt, controller.signal, { maxTokens: 50 })) {
yield message;
}
},
});
return config;
}
This works fine for generating a commit message, but it doesn't allow me to pass a custom ID (like FA-92
) as an argument.
When I try to change the run
method to accept arguments (e.g., (sdk: any, args: any)
), I get the following TypeScript error:
Type '(sdk: any, args: any) => AsyncGenerator<any, void, unknown>' is not assignable to type '(sdk: ContinueSDK) => AsyncGenerator<string | undefined, any, any>'.
Target signature provides too few arguments. Expected 2 or more, but got 1.ts(2322)
I found in the Continue.dev documentation that it is possible to use custom HTTP endpoints for slash commands, but I’m not sure how to integrate this while still allowing my command to process the diff
and include the provided ID in the commit message.
run
method to accept args
—this leads to the TypeScript error above.I want to be able to call the command like this:
/commit_message_any_changes FA-92
And get an output like:
git commit -m "[FA-92 | Documentation] Updated files with more details of the change."
How can I modify my slash command to accept arguments (like FA-92
) while adhering to the required method signature?
Managed to get it done.
You can view the whole input command by using "sdk.input". So i just needed to remove the command name itself from the whole input and got a "parameter"
// Any input after the command itself is considered the project management task id.
let projectmgmnt_task_id = "";
if (sdk.input) {
projectmgmnt_task_id = sdk.input.replace("/commit_message_staged", "").trim();
}
if (projectmgmnt_task_id.length === 0 || projectmgmnt_task_id === "") {
yield no_task_id_message;
return;
}
export function modifyConfig(config: Config): Config {
config.slashCommands?.push({
name: "commit_message_staged",
description: "Write a commit message for all local changes",
run: async function* (sdk) {
const diff = await sdk.ide.getDiff(true);
// Any input after the command itself is considered the project management task id.
let projectmgmnt_task_id = "";
if (sdk.input) {
projectmgmnt_task_id = sdk.input.replace("/commit_message_staged", "").trim();
}
if (projectmgmnt_task_id.length === 0 || projectmgmnt_task_id === "") {
yield no_task_id_message;
return;
}
const prompt = `${diff} Create git commit message`;
const controller = new AbortController();
for await (const message of sdk.llm.streamComplete(prompt, controller.signal, { maxTokens: 50 })) {
yield message;
}
},
});
return config;
}
And here is full code if someone is interested:
const no_git_changes_message = `It seems there are no changes to commit. Here are some commands to help you check your repository's status:
1. **View all local changes (including untracked files):**
\`\`\`bash
git status
\`\`\`
This will show you the current state of the working directory and staging area, including modified, deleted, and untracked files.
2. **View all changes that are staged (ready to be committed):**
\`\`\`bash
git diff --staged
\`\`\`
This will display the differences between the index (staged changes) and the last commit.
If you need any further clarification or want help interpreting the output of these commands, let me know!`;
const no_task_id_message = `It seems you did not provide a task ID for this commit. Please follow these steps:
1. **Check the Kanban Board or Jira Project Management site** to locate a task associated with this project.
- If you find a relevant task, note its ID and use it for your commit.
2. **If there is no existing task for your work:**
- Create a new task in the Kanban Board or Jira system for this project.
- Ensure the task captures the purpose of your changes and any relevant details.
3. Once you have the task ID, please include it in your commit message to maintain proper tracking.
If you need further assistance navigating the Kanban Board or Jira, let me know!`;
async function* handleDiffCommand(
sdk: any,
includeAllChanges: boolean,
taskID: string
): AsyncGenerator<string> {
const diff = await sdk.ide.getDiff(includeAllChanges);
if (!taskID || taskID.trim().length === 0) {
yield no_task_id_message;
return;
}
if (!diff || diff.length === 0 || diff.every((line: string) => line.trim() === "")) {
yield no_git_changes_message;
return;
}
const prompt = `${diff}\n\nWrite a commit message for the above changes. Write it all in one line and make it very concise and adhere to the following style: git commit -m "[ID-XY | Categories] Affected files or feature: more details of the change."\n Categories should be similar or one of these: [Cleanup|Documentation|Refactoring|UI|Navigation|Content Update|Functionality|New Feature|BugFix]. Ideally, it should only be one category, but if the changes are bigger, a max of 2 categories can be used. As ID-XY, use the following project management task id: ${taskID}`;
const controller = new AbortController();
for await (const message of sdk.llm.streamComplete(prompt, controller.signal, { maxTokens: 50 })) {
yield message;
}
}
function extractTaskId(input: string, commandName: string): string {
return input.replace(commandName, "").trim();
}
export function modifyConfig(config: Config): Config {
config.slashCommands?.push(
{
name: "commit_message_staged",
description: "Write a commit message for staged commits",
run: async function* (sdk) {
const taskID = extractTaskId(sdk.input || "", "/commit_message_staged");
yield* handleDiffCommand(sdk, false, taskID);
},
},
{
name: "commit_message_any_changes",
description: "Write a commit message for all local changes",
run: async function* (sdk) {
const taskID = extractTaskId(sdk.input || "", "/commit_message_any_changes");
yield* handleDiffCommand(sdk, true, taskID);
},
}
);
return config;
}