feat(coding-agent): add $ARGUMENTS syntax for slash commands (#418)

* feat(coding-agent): add $ARGUMENTS syntax for slash commands

* test(coding-agent): add tests for slash command argument substitution
This commit is contained in:
Evgeniy Skuridin 2026-01-03 14:08:39 +01:00 committed by GitHub
parent 9e3b1408f3
commit 8917a1f853
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 297 additions and 6 deletions

View file

@ -81,20 +81,30 @@ export function parseCommandArgs(argsString: string): string[] {
/**
* Substitute argument placeholders in command content
* Supports $1, $2, ... for positional args and $@ for all args
* Supports $1, $2, ... for positional args, $@ and $ARGUMENTS for all args
*
* Note: Replacement happens on the template string only. Argument values
* containing patterns like $1, $@, or $ARGUMENTS are NOT recursively substituted.
*/
export function substituteArgs(content: string, args: string[]): string {
let result = content;
// Replace $@ with all args joined
result = result.replace(/\$@/g, args.join(" "));
// Replace $1, $2, etc. with positional args
// Replace $1, $2, etc. with positional args FIRST (before wildcards)
// This prevents wildcard replacement values containing $<digit> patterns from being re-substituted
result = result.replace(/\$(\d+)/g, (_, num) => {
const index = parseInt(num, 10) - 1;
return args[index] ?? "";
});
// Pre-compute all args joined (optimization)
const allArgs = args.join(" ");
// Replace $ARGUMENTS with all args joined (new syntax, aligns with Claude, Codex, OpenCode)
result = result.replace(/\$ARGUMENTS/g, allArgs);
// Replace $@ with all args joined (existing syntax)
result = result.replace(/\$@/g, allArgs);
return result;
}