Closed kgilpin closed 1 month ago
Support '/' as a command delimiter in addition to '@'
Currently, the command delimiter for triggering commands is limited to the @
character. The user wants to also support the /
character as a more standard delimiter for commands.
The existing implementation parses commands by looking for a prefix with the @
character. To support both @
and /
as command delimiters, the logic needs to be modified to handle either character when detecting and parsing commands.
packages/navie/src/navie.ts
: Modify the command detection logic to support both @
and /
characters as command delimiters.
@
and /
prefixes.packages/navie/test
: Update or add test cases to verify that both /
and @
can be used as command delimiters.
packages/navie/src/navie.ts
commandBuilders
are defined and question parsing occurs.let { question } = clientRequest;
question = question.trim();
let command: Command | undefined;
for (const commandMode of Object.values(CommandMode)) {
// Check both `@` and `/` prefixes
const prefixes = [`@${commandMode} `, `/${commandMode} `];
const linePrefixes = [`@${commandMode}`, `/${commandMode}`];
for (const prefix of prefixes) {
if (question.startsWith(prefix) || question.split('\n')[0].trim() === linePrefixes.find(linePrefix => question.startsWith(linePrefix))) {
command = commandBuilders[commandMode]();
question = question.slice(prefix.length).trim();
break;
}
}
if (command) break;
}
Test Cases
packages/navie/test/commands
:
/
and @
delimiters are being recognized and processed correctly.packages/navie/test/commands/update-command.spec.ts
:test('correctly parses commands with "@" prefix', () => {
const request: CommandRequest = {
question: '@update What is the update?',
codeSelection: 'some code selection',
userOptions: new UserOptions(new Map()),
};
const result = command.execute(request);
const updates = await collectUpdates(result);
expect(updates.length).toBeGreaterThan(0);
});
test('correctly parses commands with "/" prefix', () => {
const request: CommandRequest = {
question: '/update What is the update?',
codeSelection: 'some code selection',
userOptions: new UserOptions(new Map()),
};
const result = command.execute(request);
const updates = await collectUpdates(result);
expect(updates.length).toBeGreaterThan(0);
});
By making these changes, the system will support both @
and /
as valid command delimiters.
@dustinbyrne @dividedmind @apotterri your thoughts?
I don't think it's a good idea:
No plan to implement
Currently, our commands such as @help, @plan are triggered by the
@
character.It seems more standard to use
/
instead.Refactor the code in the
navie
project to accept/
as the command delimiter, in addition to the current@
.