Files
syntaxbullet 91e5f44cc8 feat(memory): add memory extension with core functionality and tests
- Implemented MemoryStore class for managing concepts with YAML frontmatter.
- Added methods for creating, reading, updating, and deleting concepts.
- Introduced locking mechanism for concurrent access.
- Developed search and hinting capabilities for concept retrieval.
- Created tests for access control and store functionality.
- Added long-term memory skill documentation and operational guidelines.
- Included package.json and package-lock.json for dependency management.
2026-07-23 20:35:08 +02:00

51 lines
1.3 KiB
JavaScript

export class MemoryTurnAccess {
constructor() {
this.reset();
}
reset() {
this.searched = false;
this.searchResultIds = new Set();
this.readIds = new Set();
}
recordSearch(ids) {
this.searched = true;
for (const id of ids) this.searchResultIds.add(id);
}
requireSearchedId(id) {
if (!this.searched) {
throw new Error("Memory workflow blocked: call memory_search in this user turn before reading or mutating memory.");
}
if (!this.searchResultIds.has(id)) {
throw new Error(`Memory workflow blocked: search for the exact concept '${id}' in this user turn first.`);
}
}
recordRead(ids) {
for (const id of ids) {
this.requireSearchedId(id);
this.readIds.add(id);
}
}
requireWrite(id, exists) {
if (!this.searched) {
throw new Error("Memory workflow blocked: call memory_search for duplicates in this user turn before writing.");
}
if (!exists) return;
this.requireSearchedId(id);
if (!this.readIds.has(id)) {
throw new Error(`Memory workflow blocked: read existing concept '${id}' in this user turn before updating it.`);
}
}
requireForget(id) {
this.requireSearchedId(id);
if (!this.readIds.has(id)) {
throw new Error(`Memory workflow blocked: read concept '${id}' in this user turn before forgetting it.`);
}
}
}