Skip to content

Conversation

Konippi
Copy link
Contributor

@Konippi Konippi commented Sep 6, 2025

Issue #, if available:

resolve #2794

Description of changes:

This PR implements a comprehensive prompt management system that supports both global and local prompts. Users can now create, edit, and manage reusable prompt templates that are stored locally in their projects or globally across all projects.

Features added

  1. Global and Local Prompt Support

    • Global prompts: Stored in ~/.aws/amazonq/prompts/ (shared across all projects)
    • Local prompts: Stored in /.amazonq/prompts/ (project-specific)
    • Priority system: Local prompts override global prompts when names conflict
  2. New Commands

    • /prompts create <name> - Create a new local prompt (--content <content> argument is also supported)
    • /prompts edit <name> - Edit an existing prompt with automatic editor opening

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

@Konippi Konippi changed the title feat: expand support for /prompts command feat(chat): expand support for /prompts command Sep 6, 2025
@peteryxu
Copy link

peteryxu commented Sep 9, 2025

can we get this PR merged asap? Very important feature all othe major CLI AI tools already support!

@kensave
Copy link
Contributor

kensave commented Sep 11, 2025

Can you add the test scenarios you did to validate this?

For reviewers add repro steps and validated scenarios.

@Konippi
Copy link
Contributor Author

Konippi commented Sep 11, 2025

@kensave

Test1: Prompt creation

Test 1.1: Create local prompt with content

# Create a prompt with inline content
q chat
/prompts create hello --content "Hello! How can I help you today?"

# Expected: Success message with file path
# ✓ Created prompt hello at <project>/.amazonq/prompts/hello.md

Test 1.2: Create local prompt without content (editor mode)

/prompts create deploy

# Expected: 
# - Default template content appears in editor
# - After saving and closing editor, success message appears

Test 1.3: Attempt to create duplicate prompt

/prompts create hello --content "Duplicate test"

# Expected: Prompt hello already exists. Use /prompts edit hello to modify it.

2. Prompt Listing and Discovery

Test 2.1: Create global prompt and test listing

# Create global prompt directory and file manually
mkdir -p ~/.aws/amazonq/prompts
echo "This is a global prompt for testing" > ~/.aws/amazonq/prompts/global-test.md

/prompts list

# Expected: Shows both sections:
# Global (.aws/amazonq/prompts):
# - global-test
# 
# Local (.amazonq/prompts):
# - hello
# - deploy

Test 2.2: Test search functionality (Please confirm that amazonq/prompts/hello.md exists.)

/prompts list hello

# Expected: Only shows prompts containing "hello"

3. Priority System Testing

Test 3.1: Create conflicting prompt names

# Create global prompt with same name as local
echo "Global version of hello prompt" > ~/.aws/amazonq/prompts/hello.md

/prompts list

# Expected: Only shows one "hello" in Local section (local overrides global)

Test 3.2: Test prompt loading priority

@hello

# Expected: Should load the LOCAL version of hello prompt, not global
# Verify by checking the content that gets loaded

4. Prompt Editing

Test 4.1: Edit existing local prompt

/prompts edit hello

# Expected: 
# - Editor opens with current content
# - After editing and saving, success message appears
# - ✓ Prompt edited successfully.

Test 4.2: Edit global prompt (should edit local copy if exists)

/prompts edit hello

# Expected: Opens the LOCAL version for editing (due to priority system)

Test 4.3: Edit non-existent prompt

/prompts edit nonexistent

# Expected: Error message suggesting to use /prompts create instead

@kensave
Copy link
Contributor

kensave commented Sep 11, 2025

Thanks for the detailed explanation.

Couple of comments:

  1. What do you think about?

/prompts create -n hello --content "hello world"

  1. Test 1.2 is failing for me, see output:
[rust-developer] > /prompts create deploy

Opening editor to create prompt content...

✓ Created prompt deploy at /Volumes/workplace/QCLI/amazon-q-developer-cli_main/.amazonq/prompts/deploy.md
  1. Duplicate handling when global and local.

Currently when a global prompt with same name as local is created, file is created but its not shown in the list. I see Global start showing in list once we remove the local, if global is expected to be overridden should UX be clear denoting this is happening?

  1. Should we sanitize validate the name, this seem to work:
/prompts create /Users/kennvene/workplace/AWSZornDataPlaneService/src/AWSZornDataPlaneService/hola.ms


Opening editor to create prompt content...

✓ Created prompt /Users/kennvene/workplace/AWSZornDataPlaneService/src/AWSZornDataPlaneService/hola.ms at /Users/kennvene/workplace/AWSZornDataPlaneService/src/AWSZornDataPlaneService/hola.ms.md

Though editor is not opened either, interesting is that after that we see

/prompts create /Users/kennvene/workplace/AWSZornDataPlaneService/src/AWSZornDataPlaneService/hola.ms


Prompt /Users/kennvene/workplace/AWSZornDataPlaneService/src/AWSZornDataPlaneService/hola.ms already exists. Use /prompts edit /Users/kennvene/workplace/AWSZornDataPlaneService/src/AWSZornDataPlaneService/hola.ms to modify it

But prompts list will now show it

@Konippi
Copy link
Contributor Author

Konippi commented Sep 11, 2025

@kensave
I have reviewed the comments and completed all necessary corrections. Could you check it again?

@kensave
Copy link
Contributor

kensave commented Sep 11, 2025

An additional comment is that, what are your though on removing global and local prompts? We do support create and update.

@Konippi
Copy link
Contributor Author

Konippi commented Sep 11, 2025

An additional comment is that, what are your though on removing global and local prompts? We do support create and update.

It's definitely necessary. Let's add a delete function too.

@Konippi
Copy link
Contributor Author

Konippi commented Sep 11, 2025

@kensave
I've just added the /prompts delete command. Additionally, as a minor fix, we've updated each update command to support the --global option.

Commands:
  list    List available prompts from a tool or show all available prompt
  get     Get a specific prompt by name
  create  Create a new prompt
  edit    Edit an existing prompt
  delete  Delete an existing prompt
  help    Print this message or the help of the given subcommand(s)

@kensave
Copy link
Contributor

kensave commented Sep 11, 2025

Thank you

@kensave
Copy link
Contributor

kensave commented Sep 11, 2025

Can we use remove so we match other commands like /context

}

// Check for path separators
if name.contains('/') || name.contains('\\') {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - we could just use a regex here like [a-zA-Z_-]+

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it okay that this regex doesn't allow numbers?
Considering that numbers might be needed for like versioning and workflows, I defined it as [a-zA-Z0-9_-]+.

execute!(session.stderr)?;

// Ask for user confirmation
let user_input = match session.read_user_input("Are you sure you want to remove this prompt? (y/n): ", false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can user input be read using the util function like this instead? https://github.com/aws/amazon-q-developer-cli/blob/main/crates/chat-cli/src/cli/chat/cli/profile.rs#L310-L317

Otherwise the y/n will be stored as part of the readline history

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely yes.

execute!(session.stderr)?;

// Ask for user confirmation
let user_input = match session.read_user_input("Do you want to continue? (y/n): ", false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here for reading user input

}

// Check for conflicts between global and local
if !global {
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of this code seems a bit verbose - can this be restructured to instead be

struct Prompts {
local: Prompt
global: Prompt
}

struct Prompt {
name: String,
path: PathBuf,
}

Then the logic for getting local/global names, checking if something exists, validation, etc. could be added as methods on these structs rather than implicitly duplicated across these different methods.

The logic for creating/editing/deleting etc. shouldn't really need to concern itself with checking md extensions for example, just more maintainable to add some structure around this IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've modified it to use structs.

@Konippi
Copy link
Contributor Author

Konippi commented Sep 13, 2025

@brandonskiser
Since the prompt has been significantly modified to use structs, I would like you to review it again.

@briananderson1222
Copy link

Does this support arguments?

Perhaps a default "context" argument that appends to the bottom of the prompt or the ability to insert {argument} {argument?} (optional) {argument:default} (optional, w/ default) in the content and have it get auto extracted into an argument? The default one (if supported) would also be nice to not require wrapping in double quotes (") ..

Thinking about integration with things like GitHub's new SpecKit where you may @specify <description of feature>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Support local prompts for /prompts from .amazonq/prompts directory
5 participants