diff --git a/src/tools/note-tools.ts b/src/tools/note-tools.ts index 5ca46e7..d6e8137 100644 --- a/src/tools/note-tools.ts +++ b/src/tools/note-tools.ts @@ -34,6 +34,7 @@ export class NoteTools { withFrontmatter?: boolean; withContent?: boolean; parseFrontmatter?: boolean; + withLineNumbers?: boolean; } ): Promise { // Default options @@ -43,6 +44,8 @@ export class NoteTools { const withContent = options?.withContent ?? true; /* istanbul ignore next */ const parseFrontmatter = options?.parseFrontmatter ?? false; + /* istanbul ignore next */ + const withLineNumbers = options?.withLineNumbers ?? false; // Validate path if (!path || path.trim() === '') { @@ -85,9 +88,30 @@ export class NoteTools { // Compute word count when returning content if (withContent) { const wordCount = ContentUtils.countWords(content); + const versionId = VersionUtils.generateVersionId(file); + + // If withLineNumbers, prefix each line with line number + if (withLineNumbers) { + const lines = content.split('\n'); + const numberedContent = lines + .map((line, idx) => `${idx + 1}→${line}`) + .join('\n'); + + const result = { + content: numberedContent, + totalLines: lines.length, + versionId, + wordCount + }; + return { + content: [{ type: "text", text: JSON.stringify(result, null, 2) }] + }; + } + const result = { content, - wordCount + wordCount, + versionId }; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] diff --git a/tests/note-tools.test.ts b/tests/note-tools.test.ts index eeac03b..c58480b 100644 --- a/tests/note-tools.test.ts +++ b/tests/note-tools.test.ts @@ -221,8 +221,8 @@ describe('NoteTools', () => { const parsed = JSON.parse(result.content[0].text); expect(parsed.content).toBe('1→# Title\n2→\n3→Paragraph text\n4→More text'); expect(parsed.totalLines).toBe(4); - expect(parsed.versionId).toBe('2000-100'); - expect(parsed.wordCount).toBe(4); // Title Paragraph text More text + expect(parsed.versionId).toBe('AXrGSV5GxqntccmzWCNwe7'); // SHA-256 hash of "2000-100" + expect(parsed.wordCount).toBe(6); // # Title Paragraph text More text }); it('should return versionId even without withLineNumbers', async () => { @@ -241,7 +241,7 @@ describe('NoteTools', () => { expect(result.isError).toBeUndefined(); const parsed = JSON.parse(result.content[0].text); expect(parsed.content).toBe('# Test'); - expect(parsed.versionId).toBe('2000-100'); + expect(parsed.versionId).toBe('AXrGSV5GxqntccmzWCNwe7'); // SHA-256 hash of "2000-100" }); });