Skip to content

Conversation

@ranrmak
Copy link

@ranrmak ranrmak commented Nov 6, 2025

Issue #, if available:
#3064 #3049

Description of changes:
Support arguments for saved prompts.

  • Arguments are positional and can be placed in the prompt like ${1}, ${2}.
  • ${@} and $ARGS can be used as a placeholder for referencing all arguments.
  • Supports a maximum of 10 arguments.
  • Arguments can be quoted.

Example
Create a prompt
/prompts create -n test-prompt --content "read the file ${1} in the path ${2}. Print the git status of the ${1}. Before printing the git status show the complete file path ${@}.

Invoke the prompt
@test-prompt file1.js src/frontend

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ranrmak ranrmak requested a review from brandonskiser November 6, 2025 17:54
@ranrmak ranrmak added the enhancement New feature or request label Nov 6, 2025
substituted
},
Err(arg_error) => {
queue!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just call execute! here.

let mut positions = Vec::new();

for cap in PLACEHOLDER_FINDER.captures_iter(content) {
let full_match = cap.get(0).unwrap().as_str();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use expect here

"arg2".to_string(),
])
.unwrap();
assert_eq!(result, "Command: Command arg1 arg2");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this test passes doesn't that mean your example in your description doesn't quite work?

In your example you have:
Example
Create a prompt
/prompts create -n test-prompt --content "read the file ${1} in the path ${2}. Print the git status of the ${1}. Before printing the git status show the complete file path ${@}.

Invoke the prompt
@test-prompt file1.js src/frontend

This would then create the following:
"read the file file1.js in the path src/frontend. Print the git status of the file1.js. Before printing the git status show the complete file path file1.js src/frontend."

Or is the example the problem here?

Comment on lines +14 to +23
static PLACEHOLDER_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\$\{([1-9]|10)\}").unwrap());

/// Regex for validating $ARGS placeholder
static ARGS_PLACEHOLDER_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\$ARGS").unwrap());

/// Regex for validating ${@} placeholder
static AT_PLACEHOLDER_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\$\{@\}").unwrap());

/// Regex for finding all placeholders in content (${n}, $ARGS, and ${@})
static PLACEHOLDER_FINDER: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\$\{(\d+|@)\}|\$ARGS").unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use expect here so that if it does go wrong it's easier to debug.

@konippi
Copy link
Contributor

konippi commented Nov 8, 2025

This feature is highly important, so thank you for implementing it. The spec-kit currently provides partial support for the q CLI, and this feature enables full support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants