-
-
Notifications
You must be signed in to change notification settings - Fork 6
fix(node): escape prompt blocks, harden prompt isolation and improve error typing #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,7 @@ | ||||||
| function escapeForPromptBlock(input: string): string { | ||||||
| return input.replace(/</g, "<").replace(/>/g, ">"); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While escaping
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| export function buildPrompt( | ||||||
| repoName: string, | ||||||
| description: string | null, | ||||||
|
|
@@ -11,20 +15,20 @@ export function buildPrompt( | |||||
| Your task is to explain a GitHub repository clearly and concisely for a human reader. | ||||||
|
|
||||||
| <repository_metadata> | ||||||
| Name: ${repoName} | ||||||
| Description: ${description || "No description provided"} | ||||||
| Name: ${escapeForPromptBlock(repoName)} | ||||||
| Description: ${escapeForPromptBlock(description || "No description provided")} | ||||||
| </repository_metadata> | ||||||
|
|
||||||
| <readme> | ||||||
| ${readme || "No README provided"} | ||||||
| ${escapeForPromptBlock(readme || "No README provided")} | ||||||
| </readme> | ||||||
|
|
||||||
| <repo_structure> | ||||||
| ${treeText || "No file tree provided"} | ||||||
| ${escapeForPromptBlock(treeText || "No file tree provided")} | ||||||
| </repo_structure> | ||||||
|
|
||||||
| <code_files> | ||||||
| ${filesText || "No code files provided"} | ||||||
| ${escapeForPromptBlock(filesText || "No code files provided")} | ||||||
| </code_files> | ||||||
|
|
||||||
| Instructions: | ||||||
|
|
@@ -75,12 +79,12 @@ export function buildQuickPrompt( | |||||
| Write a ONE-SENTENCE plain-English definition of what this GitHub repository is. | ||||||
|
|
||||||
| <repository_metadata> | ||||||
| Name: ${repoName} | ||||||
| Description: ${description || "No description provided"} | ||||||
| Name: ${escapeForPromptBlock(repoName)} | ||||||
| Description: ${escapeForPromptBlock(description || "No description provided")} | ||||||
| </repository_metadata> | ||||||
|
|
||||||
| <readme> | ||||||
| ${readmeSnippet} | ||||||
| ${escapeForPromptBlock(readmeSnippet)} | ||||||
| </readme> | ||||||
|
|
||||||
| Rules: | ||||||
|
|
@@ -112,16 +116,16 @@ export function buildSimplePrompt( | |||||
| Summarize this GitHub repository in a concise bullet-point format. | ||||||
|
|
||||||
| <repository_metadata> | ||||||
| Name: ${repoName} | ||||||
| Description: ${description || "No description provided"} | ||||||
| Name: ${escapeForPromptBlock(repoName)} | ||||||
| Description: ${escapeForPromptBlock(description || "No description provided")} | ||||||
| </repository_metadata> | ||||||
|
|
||||||
| <readme> | ||||||
| ${readmeContent} | ||||||
| ${escapeForPromptBlock(readmeContent)} | ||||||
| </readme> | ||||||
|
|
||||||
| <repo_structure> | ||||||
| ${treeContent} | ||||||
| ${escapeForPromptBlock(treeContent)} | ||||||
| </repo_structure> | ||||||
|
|
||||||
| Output style rules: | ||||||
|
|
||||||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic for extracting an error message is repeated in multiple
catchblocks throughout this file. To improve maintainability and reduce code duplication, consider creating a utility function. For example:This function could then be called in each
catchblock, making the code cleaner and easier to maintain.