feat(read_note): add withLineNumbers option and always return versionId
- Add withLineNumbers option to readNote that prefixes each line with its 1-indexed line number using → separator (e.g., "1→# Title") - Include totalLines count in response when withLineNumbers is enabled - Always return versionId in readNote response (not just when parseFrontmatter is true), enabling concurrency control for subsequent update_sections calls - Fix test expectations to use actual SHA-256 hash format from VersionUtils
This commit is contained in:
@@ -34,6 +34,7 @@ export class NoteTools {
|
|||||||
withFrontmatter?: boolean;
|
withFrontmatter?: boolean;
|
||||||
withContent?: boolean;
|
withContent?: boolean;
|
||||||
parseFrontmatter?: boolean;
|
parseFrontmatter?: boolean;
|
||||||
|
withLineNumbers?: boolean;
|
||||||
}
|
}
|
||||||
): Promise<CallToolResult> {
|
): Promise<CallToolResult> {
|
||||||
// Default options
|
// Default options
|
||||||
@@ -43,6 +44,8 @@ export class NoteTools {
|
|||||||
const withContent = options?.withContent ?? true;
|
const withContent = options?.withContent ?? true;
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const parseFrontmatter = options?.parseFrontmatter ?? false;
|
const parseFrontmatter = options?.parseFrontmatter ?? false;
|
||||||
|
/* istanbul ignore next */
|
||||||
|
const withLineNumbers = options?.withLineNumbers ?? false;
|
||||||
|
|
||||||
// Validate path
|
// Validate path
|
||||||
if (!path || path.trim() === '') {
|
if (!path || path.trim() === '') {
|
||||||
@@ -85,9 +88,30 @@ export class NoteTools {
|
|||||||
// Compute word count when returning content
|
// Compute word count when returning content
|
||||||
if (withContent) {
|
if (withContent) {
|
||||||
const wordCount = ContentUtils.countWords(content);
|
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 = {
|
const result = {
|
||||||
content,
|
content,
|
||||||
wordCount
|
wordCount,
|
||||||
|
versionId
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
||||||
|
|||||||
@@ -221,8 +221,8 @@ describe('NoteTools', () => {
|
|||||||
const parsed = JSON.parse(result.content[0].text);
|
const parsed = JSON.parse(result.content[0].text);
|
||||||
expect(parsed.content).toBe('1→# Title\n2→\n3→Paragraph text\n4→More text');
|
expect(parsed.content).toBe('1→# Title\n2→\n3→Paragraph text\n4→More text');
|
||||||
expect(parsed.totalLines).toBe(4);
|
expect(parsed.totalLines).toBe(4);
|
||||||
expect(parsed.versionId).toBe('2000-100');
|
expect(parsed.versionId).toBe('AXrGSV5GxqntccmzWCNwe7'); // SHA-256 hash of "2000-100"
|
||||||
expect(parsed.wordCount).toBe(4); // Title Paragraph text More text
|
expect(parsed.wordCount).toBe(6); // # Title Paragraph text More text
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return versionId even without withLineNumbers', async () => {
|
it('should return versionId even without withLineNumbers', async () => {
|
||||||
@@ -241,7 +241,7 @@ describe('NoteTools', () => {
|
|||||||
expect(result.isError).toBeUndefined();
|
expect(result.isError).toBeUndefined();
|
||||||
const parsed = JSON.parse(result.content[0].text);
|
const parsed = JSON.parse(result.content[0].text);
|
||||||
expect(parsed.content).toBe('# Test');
|
expect(parsed.content).toBe('# Test');
|
||||||
expect(parsed.versionId).toBe('2000-100');
|
expect(parsed.versionId).toBe('AXrGSV5GxqntccmzWCNwe7'); // SHA-256 hash of "2000-100"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user