Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions src/tests/memory-server-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ async function testUpdateMemoryTags(): Promise<void> {

const hash = storeOutput.hash;

// Update tags only (keep same content)
const updateResult = await executeCommand(['update-memory', '--hash', hash, '--content', 'TypeScript configuration notes', '--tags', 'typescript,config,complete']);
// Update tags only (WITHOUT providing content - the new feature!)
const updateResult = await executeCommand(['update-memory', '--hash', hash, '--tags', 'typescript,config,complete']);

if (updateResult.exitCode !== 0) {
throw new Error(`Tag update failed: ${updateResult.stderr}`);
Expand All @@ -469,7 +469,7 @@ async function testUpdateMemoryTags(): Promise<void> {
throw new Error('Tag update did not indicate tags were updated');
}

console.log(`✓ Updated tags successfully`);
console.log(`✓ Updated tags successfully without providing content`);

// Verify new tags by searching
const searchResult = await executeCommand(['search-memory', '--tags', 'config']);
Expand All @@ -488,7 +488,12 @@ async function testUpdateMemoryTags(): Promise<void> {
throw new Error('Tags were not properly updated');
}

console.log(`✓ Verified tags were updated correctly`);
// Verify content remained unchanged
if (foundMemory.content !== 'TypeScript configuration notes') {
throw new Error('Content was changed when it should have remained the same');
}

console.log(`✓ Verified tags were updated and content remained unchanged`);
}

/**
Expand Down
35 changes: 21 additions & 14 deletions src/tools/update-memory/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { debugLog, formatHash } from '../../utils/debug.js';

interface UpdateMemoryArgs {
hash: string;
content: string;
content?: string;
tags?: string[];
}

Expand All @@ -22,16 +22,6 @@ export async function execute(args: UpdateMemoryArgs, context: ToolContext): Pro
throw new Error('Hash cannot be empty');
}

if (!args.content || args.content.trim().length === 0) {
throw new Error('Content cannot be empty');
}

// Log content size for large memories
const contentSize = args.content.length;
if (contentSize > 100000) {
debugLog(`Updating with large content: ${contentSize} characters`);
}

// Check if memory exists before updating
const existing = context.memoryService.getByHash(args.hash);
if (!existing) {
Expand All @@ -41,8 +31,22 @@ export async function execute(args: UpdateMemoryArgs, context: ToolContext): Pro
};
}

// Use existing content if not provided (tags-only update)
const newContent = args.content !== undefined ? args.content : existing.content;

// Validate content is not empty
if (!newContent || newContent.trim().length === 0) {
throw new Error('Content cannot be empty');
}

// Log content size for large memories
const contentSize = newContent.length;
if (contentSize > 100000) {
debugLog(`Updating with large content: ${contentSize} characters`);
}

// Perform the update
const newHash = context.memoryService.update(args.hash, args.content, args.tags);
const newHash = context.memoryService.update(args.hash, newContent, args.tags);

if (!newHash) {
return {
Expand All @@ -53,15 +57,18 @@ export async function execute(args: UpdateMemoryArgs, context: ToolContext): Pro

const hashChanged = newHash !== args.hash;
const tagsUpdated = args.tags !== undefined;
const contentUpdated = args.content !== undefined;

let message = `Memory updated successfully.`;
if (hashChanged) {
message += ` New hash: ${formatHash(newHash)}...`;
} else {
message += ` Hash unchanged: ${formatHash(newHash)}...`;
}
if (tagsUpdated) {
message += ` (tags updated)`;
if (tagsUpdated && !contentUpdated) {
message += ` (tags updated only)`;
} else if (tagsUpdated) {
message += ` (content and tags updated)`;
}

return {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/update-memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseCliArgs } from './cli-parser.js';
export const updateMemoryTool: Tool = {
definition: {
name: 'update-memory',
description: 'Update an existing memory with new content and/or tags. The hash will change if content changes. If tags are provided, they replace all existing tags; if omitted, existing tags are preserved.',
description: 'Update an existing memory with new content and/or tags. The hash will change if content changes. If tags are provided, they replace all existing tags; if omitted, existing tags are preserved. If content is omitted, only tags are updated.',
inputSchema: {
type: 'object',
properties: {
Expand All @@ -15,15 +15,15 @@ export const updateMemoryTool: Tool = {
},
content: {
type: 'string',
description: 'The new content for the memory'
description: 'The new content for the memory (optional - if omitted, content remains unchanged)'
},
tags: {
type: 'array',
items: { type: 'string' },
description: 'New tags to replace existing tags (optional - if omitted, existing tags are preserved)'
}
},
required: ['hash', 'content']
required: ['hash']
}
},
handler: execute,
Expand Down