Evolving and in support of #7 , #10
I have a consistent need to reuse parts of prompts in my codebase context.
this method utilizes the @ reference to auto-inject saved prompt snippets.
Feature: Saved Prompt Snippets (V1)
Goal: Allow users to save frequently used pieces of text (snippets) from the Prompt Prefix or Prompt Suffix inputs. When a user inserts a reference to these snippets (e.g., @snippet_name) into their Prompt Prefix or Suffix, this reference will be automatically expanded with the snippet's full content before the final prompt context is generated and sent to the LLM.
Core Functionality (V1):
- Save Snippets: Users can save the content of the "Prompt Prefix" or "Prompt Suffix" textareas as named snippets.
- View Snippets: Saved snippets are listed in a new dedicated tree view in the Prompt Tower sidebar.
- Insert Snippet References: Clicking a snippet in the tree view inserts its reference (e.g.,
@snippet_name) into the "Prompt Prefix" textarea in the webview. Users can also manually type these references.
- Reference Expansion: During the "Create Context" or "Create & Copy to Clipboard" process, any
@snippet_name references found in the Prompt Prefix or Prompt Suffix text are replaced with the actual content of the corresponding saved snippet. This expansion happens before the prefix/suffix are combined with the selected files and other context elements.
1. Data Model
A SavedPromptSnippet will be defined as follows:
interface SavedPromptSnippet {
id: string; // Unique identifier (e.g., generated UUID)
name: string; // User-defined name. Must be unique within the workspace.
// This name is used for the @reference (e.g., "project_overview").
// Does not contain the '@' symbol itself.
content: string; // The actual text content of the snippet.
createdAt: string; // ISO timestamp of when the snippet was created.
}
2. Storage
- Snippets will be stored in the VS Code
workspaceState under a key like 'promptTower.savedPromptSnippets'.
- The stored value will be an array of
SavedPromptSnippet objects.
- This makes snippets specific to the current workspace.
3. Webview UI & Interaction
4. Sidebar Tree View ("Prompt Snippets")
- Location: A new tree view will be added to the "Prompt Tower" section in the VS Code Activity Bar. It should be titled "Prompt Snippets" (or "Saved Snippets") and appear above the "GitHub Issues" view.
- Tree Items:
- Each
SavedPromptSnippet will be represented as an item in this tree.
- Label: The
snippet.name (e.g., project_overview).
- Tooltip: "Click to insert
@snippet.name into Prompt Prefix. This reference will be expanded with the snippet's content during context generation."
- Icon: A default file/text icon, or a custom snippet icon.
- Collapsible State:
vscode.TreeItemCollapsibleState.None.
- Primary Action (On Click):
- Clicking a tree item will trigger a VS Code command (e.g.,
promptTower.insertSnippetReference).
- This command will receive the
snippet.name as an argument.
- The command's handler in
extension.ts will then send the appendToPrefix message to the webview with the reference string (e.g., @project_overview).
- No Checkboxes or Context Menu: These are deferred for future enhancements.
5. Reference Format
- The standard format for referencing a saved snippet within the prompt text will be
@snippetName.
- Example: If a snippet is saved with the name
my_system_prompt, it will be referenced as @my_system_prompt.
6. Context Generation (Reference Expansion)
- This is a critical component of V1.
- The
ContextGenerationService (or a dedicated helper function called by it) will be responsible for processing the raw prefix and suffix text provided from the webview before they are used to construct the final prompt.
- Expansion Process:
- When "Create Context" or "Create & Copy to Clipboard" is triggered, retrieve the current text from the "Prompt Prefix" and "Prompt Suffix" inputs.
- Scan these texts for any occurrences of the
@snippetName pattern (e.g., using a regular expression like /@[a-zA-Z0-9_]+/g).
- For each valid
@snippetName reference found:
a. Extract the snippetName (the part after @).
b. Look up the SavedPromptSnippet in the workspaceState (via SnippetService) that has a matching name.
c. If a matching snippet is found, replace the entire @snippetName reference in the prefix/suffix string with the snippet.content.
d. If no matching snippet is found: The reference @snippetName should be left as-is in the text. A warning can be logged to the Output channel (e.g., "Prompt Tower: Unknown snippet reference '@unknown_snippet' found in prefix/suffix."). This prevents errors and makes the user aware if they mistyped a reference.
- Recursion: For V1, recursive expansion (where a snippet's content itself contains another
@reference) will not be supported to prevent complexity and potential infinite loops. Only one level of expansion will occur on the initial prefix/suffix text.
- The resulting prefix and suffix strings (with all valid references expanded) are then used by
ContextGenerationService to build the final prompt.
- The "Context Preview" in the webview will be updated with the fully expanded context after the "Create Context" button is clicked. The textareas for Prefix and Suffix in the webview will continue to show the
@references.
7. Scope of V1 (Exclusions)
- No editing of existing snippets.
- No deleting of existing snippets.
- No renaming of existing snippets.
- No reordering or grouping of snippets in the tree view.
- No live/inline autocompletion or expansion of
@snippetName references as the user types in the webview textareas. Expansion occurs only during the context generation step.
- No support for recursive snippet expansion.
This V1 plan ensures that the core utility of injecting predefined content into prompts via simple @references is delivered, directly addressing the spirit of the user's need for "cheat sheets" or reusable blocks of text. The LLM will receive the expanded content.
Evolving and in support of #7 , #10
I have a consistent need to reuse parts of prompts in my codebase context.
this method utilizes the
@reference to auto-inject saved prompt snippets.Feature: Saved Prompt Snippets (V1)
Goal: Allow users to save frequently used pieces of text (snippets) from the Prompt Prefix or Prompt Suffix inputs. When a user inserts a reference to these snippets (e.g.,
@snippet_name) into their Prompt Prefix or Suffix, this reference will be automatically expanded with the snippet's full content before the final prompt context is generated and sent to the LLM.Core Functionality (V1):
@snippet_name) into the "Prompt Prefix" textarea in the webview. Users can also manually type these references.@snippet_namereferences found in the Prompt Prefix or Prompt Suffix text are replaced with the actual content of the corresponding saved snippet. This expansion happens before the prefix/suffix are combined with the selected files and other context elements.1. Data Model
A
SavedPromptSnippetwill be defined as follows:2. Storage
workspaceStateunder a key like'promptTower.savedPromptSnippets'.SavedPromptSnippetobjects.3. Webview UI & Interaction
Saving a Snippet:
vscode.window.showInputBox:project_overview). It will be referenced as@project_overviewand its content will be injected when used."snippet_namevscode.window.showErrorMessage) will be shown, and the save operation will be aborted.^[a-zA-Z0-9_]+$) for clarity.SavedPromptSnippetobject is created and added to the array inworkspaceState.vscode.window.showInformationMessage(\Snippet '@${name}' saved. Its content will be injected when this reference is used.`);`Receiving Snippet References (from Tree View Click):
command: 'appendToPrefix', text: string).text(which will be the@snippet_namereference) to the "Prompt Prefix" textarea.prefixTextArea.value += (currentVal.endsWith('\n') || currentVal.length === 0 ? '' : '\n') + referenceText + '\n';updatePrefixmessage back to the extension with the new full content of the prefix textarea. This ensures theMultiRootTreeProvider's internal prefix state is updated and the context preview is invalidated (the preview itself will still show the@referenceuntil context is re-generated).4. Sidebar Tree View ("Prompt Snippets")
SavedPromptSnippetwill be represented as an item in this tree.snippet.name(e.g.,project_overview).@snippet.nameinto Prompt Prefix. This reference will be expanded with the snippet's content during context generation."vscode.TreeItemCollapsibleState.None.promptTower.insertSnippetReference).snippet.nameas an argument.extension.tswill then send theappendToPrefixmessage to the webview with the reference string (e.g.,@project_overview).5. Reference Format
@snippetName.my_system_prompt, it will be referenced as@my_system_prompt.6. Context Generation (Reference Expansion)
ContextGenerationService(or a dedicated helper function called by it) will be responsible for processing the raw prefix and suffix text provided from the webview before they are used to construct the final prompt.@snippetNamepattern (e.g., using a regular expression like/@[a-zA-Z0-9_]+/g).@snippetNamereference found:a. Extract the
snippetName(the part after@).b. Look up the
SavedPromptSnippetin theworkspaceState(viaSnippetService) that has a matchingname.c. If a matching snippet is found, replace the entire
@snippetNamereference in the prefix/suffix string with thesnippet.content.d. If no matching snippet is found: The reference
@snippetNameshould be left as-is in the text. A warning can be logged to the Output channel (e.g., "Prompt Tower: Unknown snippet reference '@unknown_snippet' found in prefix/suffix."). This prevents errors and makes the user aware if they mistyped a reference.@reference) will not be supported to prevent complexity and potential infinite loops. Only one level of expansion will occur on the initial prefix/suffix text.ContextGenerationServiceto build the final prompt.@references.7. Scope of V1 (Exclusions)
@snippetNamereferences as the user types in the webview textareas. Expansion occurs only during the context generation step.This V1 plan ensures that the core utility of injecting predefined content into prompts via simple
@referencesis delivered, directly addressing the spirit of the user's need for "cheat sheets" or reusable blocks of text. The LLM will receive the expanded content.