From 2d453d318d1d94d05eae99aa32568e2b5b8f7683 Mon Sep 17 00:00:00 2001 From: Wenzheng Jiang Date: Tue, 16 Dec 2025 12:16:49 +0900 Subject: [PATCH] Add path to variable_note format and reorder elements (#2049) Added tag to variable_note XML format for {activeNote} and other variable types. Reordered format so path comes before title heading to match note_context structure. Updated all test expectations to reflect the new format. This change ensures the LLM receives file path information when processing variable notes, enabling better context understanding and file reference capabilities. The consistent format with note_context also improves maintainability. --- src/commands/customCommandUtils.test.ts | 14 +++++++------- src/commands/customCommandUtils.ts | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/commands/customCommandUtils.test.ts b/src/commands/customCommandUtils.test.ts index 2bce78f6..ceb7b680 100644 --- a/src/commands/customCommandUtils.test.ts +++ b/src/commands/customCommandUtils.test.ts @@ -88,7 +88,7 @@ describe("processedPrompt()", () => { const result = await processPrompt(doc.content, selectedText, mockVault, mockActiveNote); expect(result.processedPrompt).toBe( - 'This is a {variable} and {selected_text}.\n\n\nhere is some selected text 12345\n\n\n\n\n## Variable Note\n\nhere is the note content for note0\n\n' + 'This is a {variable} and {selected_text}.\n\n\nhere is some selected text 12345\n\n\n\n\npath/to/active/note.md\n## Variable Note\n\nhere is the note content for note0\n\n' ); expect(result.includedFiles).toContain(mockActiveNote); }); @@ -121,7 +121,7 @@ describe("processedPrompt()", () => { const result = await processPrompt(doc.content, selectedText, mockVault, mockActiveNote); expect(result.processedPrompt).toBe( - 'This is a {variable1} and {variable2}.\n\n\n\n## Variable1 Note\n\nhere is the note content for note0\n\n\n\n\n\n## Variable2 Note\n\nnote content for note1\n\n' + 'This is a {variable1} and {variable2}.\n\n\n\npath/to/note1.md\n## Variable1 Note\n\nhere is the note content for note0\n\n\n\n\n\npath/to/note2.md\n## Variable2 Note\n\nnote content for note1\n\n' ); expect(result.includedFiles).toContain(mockNote1); expect(result.includedFiles).toContain(mockNote2); @@ -166,7 +166,7 @@ describe("processedPrompt()", () => { const result = await processPrompt(doc.content, selectedText, mockVault, mockActiveNote); expect(result.processedPrompt).toBe( - 'This is the active note: {activenote}\n\n\n\n## Active Note\n\nContent of the active note\n\n' + 'This is the active note: {activenote}\n\n\n\npath/to/active/note.md\n## Active Note\n\nContent of the active note\n\n' ); expect(result.includedFiles).toContain(mockActiveNote); expect(getFileContent).toHaveBeenCalledWith(mockActiveNote, mockVault); @@ -232,7 +232,7 @@ describe("processedPrompt()", () => { const result = await processPrompt(customPrompt, selectedText, mockVault, mockActiveNote); expect(result.processedPrompt).toBe( - 'Notes related to {#tag} are:\n\n\n\n## Tagged Note\n\nNote content for #tag\n\n' + 'Notes related to {#tag} are:\n\n\n\npath/to/tagged/note.md\n## Tagged Note\n\nNote content for #tag\n\n' ); expect(result.includedFiles).toContain(mockNoteForTag); }); @@ -271,7 +271,7 @@ describe("processedPrompt()", () => { const result = await processPrompt(customPrompt, selectedText, mockVault, mockActiveNote); expect(result.processedPrompt).toBe( - 'Notes related to {#tag1,#tag2,#tag3} are:\n\n\n\n## Tagged Note 1\n\nNote content for #tag1\n\n\n\n## Tagged Note 2\n\nNote content for #tag2\n\n' + 'Notes related to {#tag1,#tag2,#tag3} are:\n\n\n\npath/to/tagged/note1.md\n## Tagged Note 1\n\nNote content for #tag1\n\n\n\npath/to/tagged/note2.md\n## Tagged Note 2\n\nNote content for #tag2\n\n' ); expect(result.includedFiles).toContain(mockNoteForTag1); expect(result.includedFiles).toContain(mockNoteForTag2); @@ -454,7 +454,7 @@ describe("processedPrompt()", () => { // Check that getFileContent was called with the active note at least once expect(getFileContent).toHaveBeenCalledWith(mockActiveNote, mockVault); expect(result.processedPrompt).toBe( - 'This is the active note: {activeNote}. And again: {activeNote}\n\n\n\n## Active Note\n\nContent of the active note\n\n' + 'This is the active note: {activeNote}. And again: {activeNote}\n\n\n\npath/to/active/note.md\n## Active Note\n\nContent of the active note\n\n' ); expect(result.includedFiles).toContain(mockActiveNote); }); @@ -565,7 +565,7 @@ describe("processedPrompt()", () => { const result = await processPrompt(doc.content, selectedText, mockVault, mockActiveNote); expect(result.processedPrompt).toBe( - 'This is a test prompt with {invalidVariable} name and {activeNote}\n\n\n\n## Active Note\n\nActive Note Content\n\n' + 'This is a test prompt with {invalidVariable} name and {activeNote}\n\n\n\npath/to/active/note.md\n## Active Note\n\nActive Note Content\n\n' ); expect(result.includedFiles).toContain(mockActiveNote); // Expect the warning for the invalid variable diff --git a/src/commands/customCommandUtils.ts b/src/commands/customCommandUtils.ts index c9f794ef..62962885 100644 --- a/src/commands/customCommandUtils.ts +++ b/src/commands/customCommandUtils.ts @@ -274,7 +274,7 @@ async function extractVariablesFromPrompt( if (activeNote) { const content = await getFileContent(activeNote, vault); if (content) { - variableResult.content = `<${VARIABLE_NOTE_TAG}>\n## ${getFileName(activeNote)}\n\n${content}\n`; + variableResult.content = `<${VARIABLE_NOTE_TAG}>\n${activeNote.path}\n## ${getFileName(activeNote)}\n\n${content}\n`; variableResult.files.push(activeNote); } } else { @@ -292,7 +292,7 @@ async function extractVariablesFromPrompt( const content = await getFileContent(file, vault); if (content) { notesContent.push( - `<${VARIABLE_NOTE_TAG}>\n## ${getFileName(file)}\n\n${content}\n` + `<${VARIABLE_NOTE_TAG}>\n${file.path}\n## ${getFileName(file)}\n\n${content}\n` ); variableResult.files.push(file); } @@ -306,7 +306,7 @@ async function extractVariablesFromPrompt( const content = await getFileContent(file, vault); if (content) { notesContent.push( - `<${VARIABLE_NOTE_TAG}>\n## ${getFileName(file)}\n\n${content}\n` + `<${VARIABLE_NOTE_TAG}>\n${file.path}\n## ${getFileName(file)}\n\n${content}\n` ); variableResult.files.push(file); }