fix: strip persisted-output tags from memory
Fixes #1551 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,8 @@ function countTags(content: string): number {
|
||||
const contextCount = (content.match(/<claude-mem-context>/g) || []).length;
|
||||
const systemInstructionCount = (content.match(/<system_instruction>/g) || []).length;
|
||||
const systemInstructionHyphenCount = (content.match(/<system-instruction>/g) || []).length;
|
||||
return privateCount + contextCount + systemInstructionCount + systemInstructionHyphenCount;
|
||||
const persistedOutputCount = (content.match(/<persisted-output>/g) || []).length;
|
||||
return privateCount + contextCount + systemInstructionCount + systemInstructionHyphenCount + persistedOutputCount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,6 +56,7 @@ function stripTagsInternal(content: string): string {
|
||||
.replace(/<private>[\s\S]*?<\/private>/g, '')
|
||||
.replace(/<system_instruction>[\s\S]*?<\/system_instruction>/g, '')
|
||||
.replace(/<system-instruction>[\s\S]*?<\/system-instruction>/g, '')
|
||||
.replace(/<persisted-output>[\s\S]*?<\/persisted-output>/g, '')
|
||||
.trim();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,12 @@ describe('Tag Stripping Utilities', () => {
|
||||
const result = stripMemoryTagsFromPrompt(input);
|
||||
expect(result).toBe('public end');
|
||||
});
|
||||
|
||||
it('should strip <persisted-output> tags', () => {
|
||||
const input = 'public <persisted-output>large output</persisted-output> after';
|
||||
const result = stripMemoryTagsFromPrompt(input);
|
||||
expect(result).toBe('public after');
|
||||
});
|
||||
});
|
||||
|
||||
describe('multiple tags handling', () => {
|
||||
@@ -230,6 +236,15 @@ finish`;
|
||||
const parsed = JSON.parse(result);
|
||||
expect(parsed.output).toBe('result ');
|
||||
});
|
||||
|
||||
it('should strip persisted-output tags from JSON', () => {
|
||||
const jsonContent = JSON.stringify({
|
||||
output: '<persisted-output>big output</persisted-output> keep'
|
||||
});
|
||||
const result = stripMemoryTagsFromJson(jsonContent);
|
||||
const parsed = JSON.parse(result);
|
||||
expect(parsed.output).toBe(' keep');
|
||||
});
|
||||
});
|
||||
|
||||
describe('edge cases', () => {
|
||||
|
||||
Reference in New Issue
Block a user