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.
This commit is contained in:
50
extensions/memory/access.mjs
Normal file
50
extensions/memory/access.mjs
Normal file
@@ -0,0 +1,50 @@
|
||||
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.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user