Skip to content

Reusable prompt snippets insertable in the composer (#189) - #1575

Merged
currentbits merged 2 commits into
mainfrom
coder/reusable-prompt-snippets-insertable-in-t-9e1e03
Oct 10, 2026
Merged

currentbits merged 2 commits into
mainfrom
coder/reusable-prompt-snippets-insertable-in-t-9e1e03

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #189.

What

  • Settings → Agents → Prompt snippets: add/edit/delete named text snippets (settings.promptSnippets, store-persisted so web mode shares them).
  • Composer: typing @name lists matching snippets above file matches in the existing @-mention popup. Enter/Tab/click replaces the @token with the snippet text. Arrow keys walk from snippets into files.

Validation

Store rejects names that aren't one token (1-40 of letters, digits, ., -, _), empty or >8000-char text, and duplicate names on settings:set. Disk reads drop bad entries instead of throwing.

Tests

  • electron/test/prompt-snippets.test.js: default, strict rejects, failed set keeps old list, heal on reload.
  • test/composerMention.test.tsx: snippets above files, Enter inserts text, ArrowDown crosses into files.
  • Locally: typecheck, vite build, and the full electron suite (4478/4478) pass. Targeted renderer files pass.

Known edge

If a snippet is named like a provider id (e.g. claude), it appears first while typing @claude task, so Enter inserts the snippet instead of keeping the delegate token.

🤖 Generated with Claude Code

Snippets (name + text) live in settings.promptSnippets, edited under
Settings > Agents. Typing @name in the composer lists matching snippets
above file matches; accepting replaces the token with the snippet text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T08:01:11.670391Z 4e03590 PR opened
ℹ️ 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
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@currentbits
currentbits merged commit 0fa1133 into main Oct 10, 2026
6 checks passed

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

Copy link
Copy Markdown

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 automated review suggestions for this pull request.

Reviewed commit: 4e03590032

ℹ️ 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
  • 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 address that feedback".

Comment on lines +47 to +51
/** Snippets first, then files; one index walks both. */
const mentionCount = snippetMatches.length + mentionFiles.length;
// Files land 150ms after the query changes; clamp so a shorter snippet
// list never leaves the highlight past the end in between.
const mentionActive = Math.max(0, Math.min(mentionIndex, mentionCount - 1));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep keyboard selection stable while files load

When snippets match, the popup opens immediately, but the pending file lookup in refreshMention still calls setMentionIndex(0) when it resolves. If the user presses ArrowDown during the 150 ms debounce or while file lookup is pending, the highlight silently jumps back to the first snippet, so Enter can insert a different prompt than the one the user selected. Preserve the current unified index when files arrive, or reset it only when the query itself changes.

Useful? React with 👍 / 👎.

Comment on lines +508 to +511
onPersist={async (promptSnippets) => {
setError(null);
try {
await onSaveSettings({ promptSnippets });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Serialize prompt-snippet saves

This callback bypasses SettingsModal's savingRef/setSaving guard, leaving every snippet control enabled while settings.set is pending. In a remote/web session, deleting two snippets before the first round trip completes sends two full arrays derived from the same stale snippets prop—for [A, B], the requests are [B] and [A]—so whichever completes last restores one of the deleted snippets. Route these mutations through a guarded persistence helper or otherwise disable/serialize them until the returned settings arrive.

Useful? React with 👍 / 👎.

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.

Reusable prompt snippets insertable in the composer

1 participant