continuedev / continue

⏩ Continue is the leading open-source AI code assistant. You can connect any models and any context to build custom autocomplete and chat experiences inside VS Code and JetBrains
https://docs.continue.dev/
Apache License 2.0
15.89k stars 1.21k forks source link

Disappearance of Custom Slash Command in Dropdown for Preview Version #695

Closed LangLangBart closed 8 months ago

LangLangBart commented 9 months ago

Before submitting your bug report

Relevant environment info

- Continue: 0.7.54 Pre-Release
- VSCode: 1.85.1

Description

My custom slash command in version 0.7.54 (2023-12-16T05:19:30.77Z) no longer appears in the dropdown. This bug report is somewhat similar to #632 in that the command doesn't show in the dropdown, but it's otherwise unrelated.

The custom slash command functions well in version 0.6.15 (2023-12-08T21:46:59.053Z).


Should users switch from config.py to config.{ts,js} if they find a new .ts/.js file in their ~/.continue/ directory?

ls -1 ~/.continue/
# config.js
# config.json
# config.py
# config.ts
# continue.log
# …

To reproduce

  1. Open your ~/.continue/config.py and write a custom slash command, for example, the one you see in #632.
  2. Try to execute this custom slash command. It simply won't appear in the dropdown when interacting with Continue through the VSCode extension.

[!CAUTION] No logs. The option Continue: View Continue Server Logs is gone.

Log output

No response

sestinj commented 9 months ago

@LangLangBart Both of the things you have mentioned here are part of a migration away from the Python server, so the real solution will involve better education of the transition. Full details are in this Discord thread here

But abridged version to address this issue: config.py is replaced by config.ts, which has extremely similar syntax, and is then bundled into config.js. So config.ts is the one you want to edit. And continue.log also does not exist since all logs are naturally put into the developer tools console (cmd+shift+p, "Toggle Developer Tools").

If I recall, your slash command was the generation of a commit message? I actually made a built-in slash command for this if you'd like to use it as an example: https://github.com/continuedev/continue/blob/preview/core/commands/slash/commit.ts

LangLangBart commented 9 months ago

Full details are in this Discord thread here

Thank you. The thread explained my dilema.


If I recall, your slash command was the generation of a commit message?

Yes, I was using the CommitMessageStep below, it placed the command on the terminal. It allowed for a quick review - I only had to press ⏎ Enter.

CommitMessageStep - `config.py` ```py """ Continue Code Configuration """ import subprocess from textwrap import dedent from continuedev.core.main import ContinueCustomException, SetStep, Step from continuedev.core.sdk import ContinueSDK from continuedev.core.config import SlashCommand, ContinueConfig class CommitMessageStep(Step): async def run(self, sdk: ContinueSDK): # Get the root directory of the workspace dir = sdk.ide.workspace_directory commit_command = "git commit --message" # Check if there are staged changes diff = subprocess.check_output( ["git", "diff", "--staged"], cwd=dir).decode("utf-8") # If there are no staged changes, run git diff if not diff.strip(): diff = subprocess.check_output( ["git", "diff"], cwd=dir).decode("utf-8") commit_command = "git add . && git commit --message" # Only run the command if diff is not empty if diff.strip(): # Ask the LLM to write a commit message, and set it as the description of this step. resp = await sdk.models.default.complete( f"{diff}\n\nPlease provide a brief, specific commit message (under 50 characters) about the changes above, using the Conventional Commits format: ': '. Always include a scope. If the changes are only in markdown files, use 'docs' as the scope. Valid scopes include: build, ci, docs, feat, fix, perf, refactor, style, test, chore, revert, bump. If it's unclear, use 'chore' as the scope.") resp = resp.replace('\"', '').replace('\'', '').replace('`', '').replace('\\', '') await sdk.ide.runCommand(rf"{commit_command} '{resp}'") # yield SetStep(description=resp) # Updates are yielded so the UI can be incrementally updated else: raise ContinueCustomException( title="nothing to commit", message="If you want to commit, you need to add the changes to the staging area." ) def modify_config(config: ContinueConfig) -> ContinueConfig: config.slash_commands.append( SlashCommand( name="commit", description="Generate a commit message for the current changes", step=CommitMessageStep, ) ) return config ```

I will try to move it to config.ts and close the ticket upon success.

LangLangBart commented 8 months ago

I will try to move it to config.ts and close the ticket upon success.

The transition to the new format has been successful, but the new config.ts file doesn't allow running arbitrary child processes like config.py did. I will open a new feature request to see if the maintainer is interested in implementing this. In my case, it was about accessing the git diff and git diff --staged commands.

config.ts ```ts async function* createCommitMessage(sdk: ContinueSDK) { const commitCommand: string = 'git add . && git commit --message' let diff = await sdk.ide.getDiff() if (diff) { const commitMessage = await sdk.llm.complete( `${diff}\n\nPlease provide a brief, specific commit message (under 50 characters) about the changes above, using the Conventional Commits format: ': '. Always include a scope. If the changes are only in markdown files, use 'docs' as the scope. Valid scopes include: build, ci, docs, feat, fix, perf, refactor, style, test, chore, revert, bump. If it's unclear, use 'chore' as the scope.`) await sdk.ide.runCommand(`${commitCommand} '${commitMessage}'`) } else { yield 'nothing to commit' return } } export function modifyConfig(config: Config): Config { config.slashCommands?.push( { name: 'commit', description: 'Write a commit message', run: createCommitMessage } ) return config } ```

The underlying issue described in the report was invalid because the reason was the transition to the new config.ts format, thus closing this ticket.