Skip to content

Custom /prompts - #2696

Merged
dedrisian-oai merged 25 commits into
mainfrom
daniel/prompts
Aug 29, 2025
Merged

dedrisian-oai merged 25 commits into
mainfrom
daniel/prompts

Conversation

@dedrisian-oai

@dedrisian-oai dedrisian-oai commented Aug 26, 2025 •

Copy link
Copy Markdown
Contributor

Adds custom /prompts to ~/.codex/prompts/<command>.md.

Screenshot 2025-08-25 at 6 22 42 PM

Details:

  1. Adds Op::ListCustomPrompts to core.
  2. Returns ListCustomPromptsResponse with list of CustomPrompt (name, content).
  3. TUI calls the operation on load, and populates the custom prompts (excluding prompts that collide with builtins).
  4. Selecting the custom prompt automatically sends the prompt to the agent.

@dedrisian-oai
dedrisian-oai requested a review from Copilot August 26, 2025 15:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements custom prompts functionality that allows users to save frequently used prompts as Markdown files in ~/.codex/prompts/ and access them through the TUI slash command interface.

  • Adds discovery and loading of custom prompts from the filesystem
  • Integrates custom prompts into the TUI slash command popup alongside built-in commands
  • Automatically submits prompt content when selected, excluding prompts that collide with built-in command names

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
codex-rs/protocol/src/custom_prompts.rs Defines CustomPrompt struct for representing custom prompts
codex-rs/protocol/src/protocol.rs Adds ListCustomPrompts operation and response event types
codex-rs/core/src/custom_prompts.rs Implements prompt file discovery logic with exclusion support
codex-rs/core/src/codex.rs Handles ListCustomPrompts operation by discovering and returning prompts
codex-rs/tui/src/bottom_pane/command_popup.rs Extends popup to display both built-in commands and custom prompts
codex-rs/tui/src/bottom_pane/chat_composer.rs Handles selection of custom prompts and submission of their content
codex-rs/tui/src/chatwidget.rs Requests custom prompts on session start and forwards to UI
codex-rs/README.md Documents custom prompts feature and usage instructions
Comments suppressed due to low confidence (1)

codex-rs/tui/src/bottom_pane/command_popup.rs:1

  • The cursor positioning logic on line 396 is moved outside the match statement but only applies when the textarea text is set inside the match branches. This could lead to unexpected cursor behavior when the textarea is already non-empty but no text was set. Move the cursor positioning inside each match branch after setting the text.
use ratatui::buffer::Buffer;

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@dedrisian-oai
dedrisian-oai marked this pull request as ready for review August 26, 2025 15:39
@dedrisian-oai

Copy link
Copy Markdown
Contributor Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Summary

Testing

  • ❌ cargo test -p codex-tui (diff_render snapshot tests failed)

View task →

@dedrisian-oai
dedrisian-oai marked this pull request as draft August 26, 2025 16:39
@dedrisian-oai
dedrisian-oai marked this pull request as ready for review August 26, 2025 16:39
@dedrisian-oai dedrisian-oai added the code-review Issues relating to code reviews performed by codex label Aug 26, 2025
@github-actions github-actions Bot added codex-review-in-progress and removed code-review Issues relating to code reviews performed by codex labels Aug 26, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Summary
Adds “Custom Prompts” support: discovers ~/.codex/prompts/*.md, exposes via protocol (Op::ListCustomPrompts + response), and integrates into the TUI slash popup with tests and README docs.

Review
Nice feature cut with clean protocol/core/TUI threading and good tests. A few small nits to tighten behavior and UX:

  • codex-rs/core/src/custom_prompts.rs (new file): Consider using a cross‑platform home resolver (e.g., dirs crate) in default_prompts_dir() to avoid relying on HOME on non‑Unix systems.
  • codex-rs/core/src/codex.rs (@@ -1279,+): The spawn_blocking(...).await.unwrap_or_default() swallows discovery errors; consider logging the join/error cause so failures aren’t silent.
  • codex-rs/tui/src/bottom_pane/chat_composer.rs (@@ -372,7 +376,18): You removed set_cursor(...) after inserting the slash text. Confirm the caret ends at the line end; if not, re-add setting the cursor to self.textarea.text().len().
  • codex-rs/tui/src/bottom_pane/command_popup.rs (multiple hunks): CommandItem::Prompt(usize) indexes into prompts. If prompts can refresh while the popup is open, ensure selection remains consistent; otherwise consider referencing by name to decouple from indices.
  • codex-rs/tui/src/bottom_pane/command_popup.rs (@@ -126,5 +179,13): Label “send saved prompt” reads fine; if you standardize descriptions elsewhere, align casing/tense as needed.

Follow-up (outside this PR scope)

  • Run TUI snapshot tests and accept updates if expected: cargo test -p codex-tui, then cargo insta pending-snapshots -p codex-tui.

View workflow run

@dedrisian-oai
dedrisian-oai marked this pull request as ready for review August 26, 2025 17:05
@dedrisian-oai

Copy link
Copy Markdown
Contributor Author

some tests are now failing because of a different PR merged before this, hold on a sec while I fix

Comment thread codex-rs/core/src/codex.rs Resolved
Comment thread codex-rs/core/src/codex.rs Resolved
Comment thread codex-rs/core/src/custom_prompts.rs Resolved
Comment thread codex-rs/core/src/custom_prompts.rs Resolved
Comment thread codex-rs/protocol/src/custom_prompts.rs Resolved
name: format!("/{}", self.prompts[i].name),
match_indices: indices.map(|v| v.into_iter().map(|i| i + 1).collect()),
is_current: false,
description: Some("send saved prompt".to_string()),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why don't we take the first line of the prompt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that might look weird if a prompt has just one word in the first line. The "send saved prompt" at least tells the user what happens if they hit enter. But either way works, lmk which you'd prefer!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can try it this way and change it if it doesn't feel right, I guess.

Comment thread codex-rs/tui/src/chatwidget.rs Resolved
@easong-openai

Copy link
Copy Markdown
Contributor

@codex do a deep review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment thread codex-rs/core/src/custom_prompts.rs Resolved
Comment thread codex-rs/protocol/src/custom_prompts.rs Resolved
name: format!("/{}", self.prompts[i].name),
match_indices: indices.map(|v| v.into_iter().map(|i| i + 1).collect()),
is_current: false,
description: Some("send saved prompt".to_string()),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can try it this way and change it if it doesn't feel right, I guess.

@dedrisian-oai
dedrisian-oai enabled auto-merge (squash) August 29, 2025 02:15
@dedrisian-oai
dedrisian-oai merged commit b8e8454 into main Aug 29, 2025
@dedrisian-oai
dedrisian-oai deleted the daniel/prompts branch August 29, 2025 02:16
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants