-
Notifications
You must be signed in to change notification settings - Fork 361
Update comment-memory rendering to use six-backtick code regions #28115
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
10b75e1
6671286
70b6bb7
072d528
73db6af
91ebb7d
a0671b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,23 @@ const COMMENT_MEMORY_MAX_SCAN_PAGES = 50; | |
| const COMMENT_MEMORY_MAX_SCAN_EMPTY_PAGES = 5; | ||
| const COMMENT_MEMORY_PROMPT_START_MARKER = "<!-- gh-aw-comment-memory-prompt:start -->"; | ||
| const COMMENT_MEMORY_PROMPT_END_MARKER = "<!-- gh-aw-comment-memory-prompt:end -->"; | ||
| const COMMENT_MEMORY_CODE_FENCE = "``````"; | ||
| const ESCAPED_COMMENT_MEMORY_CODE_FENCE = COMMENT_MEMORY_CODE_FENCE.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
|
|
||
| function stripCommentMemoryCodeFence(content) { | ||
| const trimmed = typeof content === "string" ? content.trim() : ""; | ||
| if (trimmed.length === 0) { | ||
| return ""; | ||
| } | ||
| if (!trimmed.startsWith(COMMENT_MEMORY_CODE_FENCE)) { | ||
| return trimmed; | ||
| } | ||
| const match = trimmed.match(new RegExp(`^${ESCAPED_COMMENT_MEMORY_CODE_FENCE}[^\\n]*\\n([\\s\\S]*)\\n${ESCAPED_COMMENT_MEMORY_CODE_FENCE}$`)); | ||
| if (!match) { | ||
|
Comment on lines
+17
to
+26
|
||
| return trimmed; | ||
| } | ||
| return match[1].trim(); | ||
| } | ||
|
|
||
| function isSafeMemoryId(memoryId) { | ||
| if (typeof memoryId !== "string" || memoryId.length === 0 || memoryId.length > MAX_MEMORY_ID_LENGTH) { | ||
|
|
@@ -57,7 +74,7 @@ function extractCommentMemoryEntries(commentBody, warn = () => {}) { | |
| if (isSafeMemoryId(memoryId)) { | ||
| entries.push({ | ||
| memoryId, | ||
| content: (commentBody.slice(contentStart, closeStart) || "").trim(), | ||
| content: stripCommentMemoryCodeFence(commentBody.slice(contentStart, closeStart)), | ||
| }); | ||
| } else { | ||
| warn(`skipping unsafe memory_id '${memoryId}'`); | ||
|
|
@@ -99,7 +116,9 @@ module.exports = { | |
| COMMENT_MEMORY_MAX_SCAN_EMPTY_PAGES, | ||
| COMMENT_MEMORY_PROMPT_START_MARKER, | ||
| COMMENT_MEMORY_PROMPT_END_MARKER, | ||
| COMMENT_MEMORY_CODE_FENCE, | ||
| isSafeMemoryId, | ||
| stripCommentMemoryCodeFence, | ||
| extractCommentMemoryEntries, | ||
| listCommentMemoryFiles, | ||
| resolveCommentMemoryConfig, | ||
|
|
||
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.
Wrapping memory content with a fixed six-backtick fence will break Markdown rendering if the memory itself contains a line equal to the same six-backtick sequence (it will prematurely close the outer fence and corrupt the rest of the comment). Consider selecting a fence length that is longer than any backtick-run present in the sanitized memory content (minimum 6), and update the stripping/parser logic to accept that variable fence length so round-tripping remains reliable.