@yamo/memory-mesh 2.3.2 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +8 -2
  2. package/bin/memory_mesh.js +1 -1
  3. package/lib/llm/client.d.ts +86 -0
  4. package/lib/llm/client.js +300 -357
  5. package/lib/llm/client.ts +334 -0
  6. package/lib/llm/index.d.ts +17 -0
  7. package/lib/llm/index.js +16 -8
  8. package/lib/llm/index.ts +18 -0
  9. package/lib/memory/adapters/client.d.ts +120 -0
  10. package/lib/memory/adapters/client.js +519 -0
  11. package/lib/memory/adapters/client.ts +519 -0
  12. package/lib/memory/adapters/config.d.ts +130 -0
  13. package/lib/memory/adapters/config.js +190 -0
  14. package/lib/memory/adapters/config.ts +190 -0
  15. package/lib/memory/adapters/errors.d.ts +84 -0
  16. package/lib/memory/adapters/errors.js +129 -0
  17. package/lib/memory/adapters/errors.ts +129 -0
  18. package/lib/memory/context-manager.d.ts +41 -0
  19. package/lib/memory/context-manager.js +345 -0
  20. package/lib/memory/context-manager.ts +345 -0
  21. package/lib/memory/embeddings/factory.d.ts +57 -0
  22. package/lib/memory/embeddings/factory.js +149 -0
  23. package/lib/memory/embeddings/factory.ts +149 -0
  24. package/lib/memory/embeddings/index.d.ts +2 -0
  25. package/lib/memory/embeddings/index.js +3 -0
  26. package/lib/memory/embeddings/index.ts +3 -0
  27. package/lib/memory/embeddings/service.d.ts +134 -0
  28. package/lib/memory/embeddings/service.js +516 -0
  29. package/lib/memory/embeddings/service.ts +516 -0
  30. package/lib/memory/index.d.ts +9 -0
  31. package/lib/memory/index.js +10 -1
  32. package/lib/memory/index.ts +10 -0
  33. package/lib/memory/memory-mesh.d.ts +332 -0
  34. package/lib/memory/memory-mesh.js +1470 -678
  35. package/lib/memory/memory-mesh.ts +1517 -0
  36. package/lib/memory/memory-translator.d.ts +14 -0
  37. package/lib/memory/memory-translator.js +126 -0
  38. package/lib/memory/memory-translator.ts +126 -0
  39. package/lib/memory/schema.d.ts +130 -0
  40. package/lib/memory/schema.js +184 -0
  41. package/lib/memory/schema.ts +184 -0
  42. package/lib/memory/scorer.d.ts +25 -0
  43. package/lib/memory/scorer.js +78 -0
  44. package/lib/memory/scorer.ts +78 -0
  45. package/lib/memory/search/index.d.ts +1 -0
  46. package/lib/memory/search/index.js +2 -0
  47. package/lib/memory/search/index.ts +2 -0
  48. package/lib/memory/search/keyword-search.d.ts +46 -0
  49. package/lib/memory/search/keyword-search.js +136 -0
  50. package/lib/memory/search/keyword-search.ts +136 -0
  51. package/lib/scrubber/config/defaults.d.ts +46 -0
  52. package/lib/scrubber/config/defaults.js +50 -57
  53. package/lib/scrubber/config/defaults.ts +55 -0
  54. package/lib/scrubber/errors/scrubber-error.d.ts +22 -0
  55. package/lib/scrubber/errors/scrubber-error.js +28 -32
  56. package/lib/scrubber/errors/scrubber-error.ts +44 -0
  57. package/lib/scrubber/index.d.ts +5 -0
  58. package/lib/scrubber/index.js +4 -23
  59. package/lib/scrubber/index.ts +6 -0
  60. package/lib/scrubber/scrubber.d.ts +44 -0
  61. package/lib/scrubber/scrubber.js +100 -121
  62. package/lib/scrubber/scrubber.ts +109 -0
  63. package/lib/scrubber/stages/chunker.d.ts +25 -0
  64. package/lib/scrubber/stages/chunker.js +74 -91
  65. package/lib/scrubber/stages/chunker.ts +104 -0
  66. package/lib/scrubber/stages/metadata-annotator.d.ts +17 -0
  67. package/lib/scrubber/stages/metadata-annotator.js +55 -65
  68. package/lib/scrubber/stages/metadata-annotator.ts +75 -0
  69. package/lib/scrubber/stages/normalizer.d.ts +16 -0
  70. package/lib/scrubber/stages/normalizer.js +42 -50
  71. package/lib/scrubber/stages/normalizer.ts +60 -0
  72. package/lib/scrubber/stages/semantic-filter.d.ts +16 -0
  73. package/lib/scrubber/stages/semantic-filter.js +42 -52
  74. package/lib/scrubber/stages/semantic-filter.ts +62 -0
  75. package/lib/scrubber/stages/structural-cleaner.d.ts +18 -0
  76. package/lib/scrubber/stages/structural-cleaner.js +66 -75
  77. package/lib/scrubber/stages/structural-cleaner.ts +83 -0
  78. package/lib/scrubber/stages/validator.d.ts +17 -0
  79. package/lib/scrubber/stages/validator.js +46 -56
  80. package/lib/scrubber/stages/validator.ts +67 -0
  81. package/lib/scrubber/telemetry.d.ts +29 -0
  82. package/lib/scrubber/telemetry.js +54 -58
  83. package/lib/scrubber/telemetry.ts +62 -0
  84. package/lib/scrubber/utils/hash.d.ts +14 -0
  85. package/lib/scrubber/utils/hash.js +30 -32
  86. package/lib/scrubber/utils/hash.ts +40 -0
  87. package/lib/scrubber/utils/html-parser.d.ts +14 -0
  88. package/lib/scrubber/utils/html-parser.js +32 -39
  89. package/lib/scrubber/utils/html-parser.ts +46 -0
  90. package/lib/scrubber/utils/pattern-matcher.d.ts +12 -0
  91. package/lib/scrubber/utils/pattern-matcher.js +48 -57
  92. package/lib/scrubber/utils/pattern-matcher.ts +64 -0
  93. package/lib/scrubber/utils/token-counter.d.ts +18 -0
  94. package/lib/scrubber/utils/token-counter.js +24 -25
  95. package/lib/scrubber/utils/token-counter.ts +32 -0
  96. package/lib/utils/logger.d.ts +19 -0
  97. package/lib/utils/logger.js +65 -0
  98. package/lib/utils/logger.ts +65 -0
  99. package/lib/utils/skill-metadata.d.ts +24 -0
  100. package/lib/utils/skill-metadata.js +133 -0
  101. package/lib/utils/skill-metadata.ts +133 -0
  102. package/lib/yamo/emitter.d.ts +46 -0
  103. package/lib/yamo/emitter.js +79 -143
  104. package/lib/yamo/emitter.ts +171 -0
  105. package/lib/yamo/index.d.ts +14 -0
  106. package/lib/yamo/index.js +6 -7
  107. package/lib/yamo/index.ts +16 -0
  108. package/lib/yamo/schema.d.ts +56 -0
  109. package/lib/yamo/schema.js +82 -108
  110. package/lib/yamo/schema.ts +133 -0
  111. package/package.json +13 -8
  112. package/index.d.ts +0 -111
  113. package/lib/embeddings/factory.js +0 -151
  114. package/lib/embeddings/index.js +0 -2
  115. package/lib/embeddings/service.js +0 -586
  116. package/lib/index.js +0 -6
  117. package/lib/lancedb/client.js +0 -633
  118. package/lib/lancedb/config.js +0 -215
  119. package/lib/lancedb/errors.js +0 -144
  120. package/lib/lancedb/index.js +0 -4
  121. package/lib/lancedb/schema.js +0 -217
  122. package/lib/search/index.js +0 -1
  123. package/lib/search/keyword-search.js +0 -144
  124. package/lib/utils/index.js +0 -1
@@ -0,0 +1,133 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Structured skill-identity extraction.
4
+ *
5
+ * Reads ONLY the YAML frontmatter block (between --- delimiters) or
6
+ * root-level identity declarations in legacy v0.4 compact format.
7
+ * The body of .yamo files is LLM-interpreted and MUST NOT be machine-parsed.
8
+ */
9
+ import crypto from "crypto";
10
+ /** Fields safe to extract for indexing and display. */
11
+ const IDENTITY_FIELDS = new Set(["name", "intent", "description"]);
12
+ /** Pre-computed regexes for legacy root-level identity declarations. */
13
+ const LEGACY_REGEXES = {
14
+ name: /^name[;:]\s*([^;\n]+);?/m,
15
+ intent: /^intent[;:]\s*([^;\n]+);?/m,
16
+ description: /^description[;:]\s*([^;\n]+);?/m,
17
+ };
18
+ /**
19
+ * Parse flat key: value or key; value lines from a text block.
20
+ * Only extracts whitelisted identity fields.
21
+ */
22
+ function parseFlatBlock(block) {
23
+ const result = {};
24
+ for (const line of block.split("\n")) {
25
+ const trimmed = line.trim();
26
+ if (!trimmed || trimmed.startsWith("#")) {
27
+ continue;
28
+ }
29
+ const colonIdx = trimmed.indexOf(":");
30
+ const semiIdx = trimmed.indexOf(";");
31
+ let sepIdx;
32
+ if (colonIdx > 0 && semiIdx > 0) {
33
+ sepIdx = Math.min(colonIdx, semiIdx);
34
+ }
35
+ else if (colonIdx > 0) {
36
+ sepIdx = colonIdx;
37
+ }
38
+ else if (semiIdx > 0) {
39
+ sepIdx = semiIdx;
40
+ }
41
+ else {
42
+ continue;
43
+ }
44
+ const key = trimmed.substring(0, sepIdx).trim();
45
+ let value = trimmed.substring(sepIdx + 1).trim();
46
+ // Strip trailing semicolon (legacy compact format)
47
+ if (value.endsWith(";")) {
48
+ value = value.slice(0, -1).trim();
49
+ }
50
+ if (IDENTITY_FIELDS.has(key) && value) {
51
+ result[key] = value;
52
+ }
53
+ }
54
+ return result;
55
+ }
56
+ /**
57
+ * Extract identity fields (name, intent, description) from .yamo content.
58
+ *
59
+ * Priority:
60
+ * 1. YAML frontmatter (--- … --- block at file start)
61
+ * 2. Legacy v0.4 root-level compact declarations
62
+ * 3. Content-hash fallback — deterministic and idempotent
63
+ */
64
+ export function extractSkillIdentity(content) {
65
+ // 1. YAML frontmatter
66
+ if (content.startsWith("---")) {
67
+ const endIdx = content.indexOf("---", 3);
68
+ if (endIdx !== -1) {
69
+ const fields = parseFlatBlock(content.substring(3, endIdx));
70
+ if (fields.name) {
71
+ return {
72
+ name: fields.name,
73
+ intent: fields.intent || "general_procedure",
74
+ description: fields.description || "",
75
+ };
76
+ }
77
+ }
78
+ }
79
+ // 2. Legacy v0.4 root-level identity declarations.
80
+ // Safe: name/intent/description do not appear as body section headers.
81
+ const legacyFields = {};
82
+ for (const field of IDENTITY_FIELDS) {
83
+ const match = content.match(LEGACY_REGEXES[field]);
84
+ if (match) {
85
+ legacyFields[field] = match[1].trim();
86
+ }
87
+ }
88
+ if (legacyFields.name) {
89
+ return {
90
+ name: legacyFields.name,
91
+ intent: legacyFields.intent || "general_procedure",
92
+ description: legacyFields.description || "",
93
+ };
94
+ }
95
+ // 3. Content-hash fallback
96
+ const shortHash = crypto
97
+ .createHash("sha256")
98
+ .update(content)
99
+ .digest("hex")
100
+ .substring(0, 12);
101
+ return {
102
+ name: `Unnamed_${shortHash}`,
103
+ intent: "general_procedure",
104
+ description: "",
105
+ };
106
+ }
107
+ /**
108
+ * Extract tags from YAML frontmatter.
109
+ * Returns an array of tag strings, or empty array if no tags found.
110
+ *
111
+ * Tags are expected in the format:
112
+ * tags: tag1, tag2, tag3
113
+ *
114
+ * This function ONLY reads the YAML frontmatter block and does NOT parse
115
+ * the skill body, following the same safety constraints as extractSkillIdentity.
116
+ */
117
+ export function extractSkillTags(content) {
118
+ // Only parse YAML frontmatter (between --- delimiters)
119
+ if (content.startsWith("---")) {
120
+ const endIdx = content.indexOf("---", 3);
121
+ if (endIdx !== -1) {
122
+ const frontmatter = content.substring(3, endIdx);
123
+ const tagsMatch = frontmatter.match(/^tags:\s*(.+)$/m);
124
+ if (tagsMatch) {
125
+ return tagsMatch[1]
126
+ .split(",")
127
+ .map((t) => t.trim())
128
+ .filter((t) => t.length > 0);
129
+ }
130
+ }
131
+ }
132
+ return [];
133
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * YAMO Emitter - Constructs structured YAMO blocks for auditability
3
+ *
4
+ * Based on YAMO Protocol specification:
5
+ * - Semicolon-terminated key-value pairs
6
+ * - Agent/Intent/Context/Constraints/Meta/Output structure
7
+ * - Supports reflect, retain, recall operations
8
+ *
9
+ * Reference: Hindsight project's yamo_integration.py
10
+ */
11
+ /**
12
+ * YamoEmitter class for building YAMO protocol blocks
13
+ * YAMO (Yet Another Multi-agent Orchestration) blocks provide
14
+ * structured reasoning traces for AI agent operations.
15
+ */
16
+ export declare class YamoEmitter {
17
+ /**
18
+ * Build a YAMO block for reflect operation
19
+ * Reflect operations synthesize insights from existing memories
20
+ */
21
+ static buildReflectBlock(params: any): string;
22
+ /**
23
+ * Build a YAMO block for retain (add) operation
24
+ * Retain operations store new memories into the system
25
+ */
26
+ static buildRetainBlock(params: any): string;
27
+ /**
28
+ * Build a YAMO block for recall (search) operation
29
+ * Recall operations retrieve memories based on semantic similarity
30
+ */
31
+ static buildRecallBlock(params: any): string;
32
+ /**
33
+ * Build a YAMO block for delete operation (optional)
34
+ * Delete operations remove memories from the system
35
+ */
36
+ static buildDeleteBlock(params: any): string;
37
+ /**
38
+ * Validate a YAMO block structure
39
+ * Checks for required sections and proper formatting
40
+ */
41
+ static validateBlock(yamoBlock: any): {
42
+ valid: boolean;
43
+ errors: any[];
44
+ };
45
+ }
46
+ export default YamoEmitter;
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * YAMO Emitter - Constructs structured YAMO blocks for auditability
3
4
  *
@@ -8,40 +9,23 @@
8
9
  *
9
10
  * Reference: Hindsight project's yamo_integration.py
10
11
  */
11
-
12
12
  /**
13
13
  * YamoEmitter class for building YAMO protocol blocks
14
14
  * YAMO (Yet Another Multi-agent Orchestration) blocks provide
15
15
  * structured reasoning traces for AI agent operations.
16
16
  */
17
17
  export class YamoEmitter {
18
- /**
19
- * Build a YAMO block for reflect operation
20
- * Reflect operations synthesize insights from existing memories
21
- *
22
- * @param {Object} params - Block parameters
23
- * @param {string} [params.topic] - Topic of reflection
24
- * @param {number} params.memoryCount - Number of memories considered
25
- * @param {string} [params.agentId='default'] - Agent identifier
26
- * @param {string} params.reflection - Generated reflection text
27
- * @param {number} [params.confidence=0.8] - Confidence score (0-1)
28
- * @returns {string} Formatted YAMO block
29
- */
30
- static buildReflectBlock(params) {
31
- const {
32
- topic,
33
- memoryCount,
34
- agentId = 'default',
35
- reflection,
36
- confidence = 0.8
37
- } = params;
38
-
39
- const timestamp = new Date().toISOString();
40
-
41
- return `agent: MemoryMesh_${agentId};
18
+ /**
19
+ * Build a YAMO block for reflect operation
20
+ * Reflect operations synthesize insights from existing memories
21
+ */
22
+ static buildReflectBlock(params) {
23
+ const { topic, memoryCount, agentId = "default", reflection, confidence = 0.8, } = params;
24
+ const timestamp = new Date().toISOString();
25
+ return `agent: MemoryMesh_${agentId};
42
26
  intent: synthesize_insights_from_context;
43
27
  context:
44
- topic;${topic || 'general'};
28
+ topic;${topic || "general"};
45
29
  memory_count;${memoryCount};
46
30
  timestamp;${timestamp};
47
31
  constraints:
@@ -57,38 +41,18 @@ meta:
57
41
  log: reflection_generated;timestamp;${timestamp};memories;${memoryCount};
58
42
  handoff: End;
59
43
  `;
60
- }
61
-
62
- /**
63
- * Build a YAMO block for retain (add) operation
64
- * Retain operations store new memories into the system
65
- *
66
- * @param {Object} params - Block parameters
67
- * @param {string} params.content - Memory content
68
- * @param {Object} [params.metadata={}] - Memory metadata
69
- * @param {string} params.id - Memory ID
70
- * @param {string} [params.agentId='default'] - Agent identifier
71
- * @param {string} [params.memoryType='event'] - Type of memory
72
- * @returns {string} Formatted YAMO block
73
- */
74
- static buildRetainBlock(params) {
75
- const {
76
- content,
77
- metadata = {},
78
- id,
79
- agentId = 'default',
80
- memoryType = 'event'
81
- } = params;
82
-
83
- const timestamp = new Date().toISOString();
84
- const contentPreview = content.length > 100
85
- ? content.substring(0, 100) + '...'
86
- : content;
87
-
88
- // Escape semicolons in content for YAMO format
89
- const escapedContent = contentPreview.replace(/;/g, ',');
90
-
91
- return `agent: MemoryMesh_${agentId};
44
+ }
45
+ /**
46
+ * Build a YAMO block for retain (add) operation
47
+ * Retain operations store new memories into the system
48
+ */
49
+ static buildRetainBlock(params) {
50
+ const { content, metadata: _metadata = {}, id, agentId = "default", memoryType = "event", } = params;
51
+ const timestamp = new Date().toISOString();
52
+ const contentPreview = content.length > 100 ? `${content.substring(0, 100)}...` : content;
53
+ // Escape semicolons in content for YAMO format
54
+ const escapedContent = contentPreview.replace(/;/g, ",");
55
+ return `agent: MemoryMesh_${agentId};
92
56
  intent: store_memory_for_future_retrieval;
93
57
  context:
94
58
  memory_id;${id};
@@ -108,33 +72,16 @@ meta:
108
72
  log: memory_retained;timestamp;${timestamp};id;${id};type;${memoryType};
109
73
  handoff: End;
110
74
  `;
111
- }
112
-
113
- /**
114
- * Build a YAMO block for recall (search) operation
115
- * Recall operations retrieve memories based on semantic similarity
116
- *
117
- * @param {Object} params - Block parameters
118
- * @param {string} params.query - Search query
119
- * @param {number} params.resultCount - Number of results returned
120
- * @param {number} [params.limit=10] - Maximum requested results
121
- * @param {string} [params.agentId='default'] - Agent identifier
122
- * @param {string} [params.searchType='semantic'] - Type of search
123
- * @returns {string} Formatted YAMO block
124
- */
125
- static buildRecallBlock(params) {
126
- const {
127
- query,
128
- resultCount,
129
- limit = 10,
130
- agentId = 'default',
131
- searchType = 'semantic'
132
- } = params;
133
-
134
- const timestamp = new Date().toISOString();
135
- const recallRatio = resultCount > 0 ? (resultCount / limit).toFixed(2) : '0.00';
136
-
137
- return `agent: MemoryMesh_${agentId};
75
+ }
76
+ /**
77
+ * Build a YAMO block for recall (search) operation
78
+ * Recall operations retrieve memories based on semantic similarity
79
+ */
80
+ static buildRecallBlock(params) {
81
+ const { query, resultCount, limit = 10, agentId = "default", searchType = "semantic", } = params;
82
+ const timestamp = new Date().toISOString();
83
+ const recallRatio = resultCount > 0 ? (resultCount / limit).toFixed(2) : "0.00";
84
+ return `agent: MemoryMesh_${agentId};
138
85
  intent: retrieve_relevant_memories;
139
86
  context:
140
87
  query;${query};
@@ -150,32 +97,19 @@ output:
150
97
  meta:
151
98
  rationale;Semantic search finds similar content by vector similarity;
152
99
  observation;${resultCount} memories found matching query;
153
- confidence;${resultCount > 0 ? '0.9' : '0.5'};
100
+ confidence;${resultCount > 0 ? "0.9" : "0.5"};
154
101
  log: memory_recalled;timestamp;${timestamp};results;${resultCount};query;${query};
155
102
  handoff: End;
156
103
  `;
157
- }
158
-
159
- /**
160
- * Build a YAMO block for delete operation (optional)
161
- * Delete operations remove memories from the system
162
- *
163
- * @param {Object} params - Block parameters
164
- * @param {string} params.id - Memory ID being deleted
165
- * @param {string} [params.agentId='default'] - Agent identifier
166
- * @param {string} [params.reason='user_request'] - Reason for deletion
167
- * @returns {string} Formatted YAMO block
168
- */
169
- static buildDeleteBlock(params) {
170
- const {
171
- id,
172
- agentId = 'default',
173
- reason = 'user_request'
174
- } = params;
175
-
176
- const timestamp = new Date().toISOString();
177
-
178
- return `agent: MemoryMesh_${agentId};
104
+ }
105
+ /**
106
+ * Build a YAMO block for delete operation (optional)
107
+ * Delete operations remove memories from the system
108
+ */
109
+ static buildDeleteBlock(params) {
110
+ const { id, agentId = "default", reason = "user_request" } = params;
111
+ const timestamp = new Date().toISOString();
112
+ return `agent: MemoryMesh_${agentId};
179
113
  intent: remove_memory_from_storage;
180
114
  context:
181
115
  memory_id;${id};
@@ -193,43 +127,45 @@ meta:
193
127
  log: memory_deleted;timestamp;${timestamp};id;${id};
194
128
  handoff: End;
195
129
  `;
196
- }
197
-
198
- /**
199
- * Validate a YAMO block structure
200
- * Checks for required sections and proper formatting
201
- *
202
- * @param {string} yamoBlock - YAMO block to validate
203
- * @returns {Object} Validation result { valid, errors }
204
- */
205
- static validateBlock(yamoBlock) {
206
- const errors = [];
207
-
208
- // Check for required sections
209
- const requiredSections = ['agent:', 'intent:', 'context:', 'output:', 'log:'];
210
- for (const section of requiredSections) {
211
- if (!yamoBlock.includes(section)) {
212
- errors.push(`Missing required section: ${section}`);
213
- }
214
130
  }
215
-
216
- // Check for semicolon termination
217
- const lines = yamoBlock.split('\n');
218
- for (const line of lines) {
219
- const trimmed = line.trim();
220
- if (trimmed.length > 0 && !trimmed.startsWith('//') && !trimmed.endsWith(';')) {
221
- // Allow empty lines and comments
222
- if (trimmed && !trimmed.startsWith('agent:') && !trimmed.startsWith('handoff:')) {
223
- errors.push(`Line not semicolon-terminated: ${trimmed.substring(0, 50)}`);
131
+ /**
132
+ * Validate a YAMO block structure
133
+ * Checks for required sections and proper formatting
134
+ */
135
+ static validateBlock(yamoBlock) {
136
+ const errors = [];
137
+ // Check for required sections
138
+ const requiredSections = [
139
+ "agent:",
140
+ "intent:",
141
+ "context:",
142
+ "output:",
143
+ "log:",
144
+ ];
145
+ for (const section of requiredSections) {
146
+ if (!yamoBlock.includes(section)) {
147
+ errors.push(`Missing required section: ${section}`);
148
+ }
149
+ }
150
+ // Check for semicolon termination
151
+ const lines = yamoBlock.split("\n");
152
+ for (const line of lines) {
153
+ const trimmed = line.trim();
154
+ if (trimmed.length > 0 &&
155
+ !trimmed.startsWith("//") &&
156
+ !trimmed.endsWith(";")) {
157
+ // Allow empty lines and comments
158
+ if (trimmed &&
159
+ !trimmed.startsWith("agent:") &&
160
+ !trimmed.startsWith("handoff:")) {
161
+ errors.push(`Line not semicolon-terminated: ${trimmed.substring(0, 50)}`);
162
+ }
163
+ }
224
164
  }
225
- }
165
+ return {
166
+ valid: errors.length === 0,
167
+ errors,
168
+ };
226
169
  }
227
-
228
- return {
229
- valid: errors.length === 0,
230
- errors
231
- };
232
- }
233
170
  }
234
-
235
171
  export default YamoEmitter;
@@ -0,0 +1,171 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * YAMO Emitter - Constructs structured YAMO blocks for auditability
4
+ *
5
+ * Based on YAMO Protocol specification:
6
+ * - Semicolon-terminated key-value pairs
7
+ * - Agent/Intent/Context/Constraints/Meta/Output structure
8
+ * - Supports reflect, retain, recall operations
9
+ *
10
+ * Reference: Hindsight project's yamo_integration.py
11
+ */
12
+ /**
13
+ * YamoEmitter class for building YAMO protocol blocks
14
+ * YAMO (Yet Another Multi-agent Orchestration) blocks provide
15
+ * structured reasoning traces for AI agent operations.
16
+ */
17
+ export class YamoEmitter {
18
+ /**
19
+ * Build a YAMO block for reflect operation
20
+ * Reflect operations synthesize insights from existing memories
21
+ */
22
+ static buildReflectBlock(params) {
23
+ const { topic, memoryCount, agentId = "default", reflection, confidence = 0.8, } = params;
24
+ const timestamp = new Date().toISOString();
25
+ return `agent: MemoryMesh_${agentId};
26
+ intent: synthesize_insights_from_context;
27
+ context:
28
+ topic;${topic || "general"};
29
+ memory_count;${memoryCount};
30
+ timestamp;${timestamp};
31
+ constraints:
32
+ hypothesis;Reflection generates new insights from existing facts;
33
+ priority: high;
34
+ output:
35
+ reflection;${reflection};
36
+ confidence;${confidence};
37
+ meta:
38
+ rationale;Synthesized from ${memoryCount} relevant memories;
39
+ observation;High-level belief formed from pattern recognition;
40
+ confidence;${confidence};
41
+ log: reflection_generated;timestamp;${timestamp};memories;${memoryCount};
42
+ handoff: End;
43
+ `;
44
+ }
45
+ /**
46
+ * Build a YAMO block for retain (add) operation
47
+ * Retain operations store new memories into the system
48
+ */
49
+ static buildRetainBlock(params) {
50
+ const { content, metadata: _metadata = {}, id, agentId = "default", memoryType = "event", } = params;
51
+ const timestamp = new Date().toISOString();
52
+ const contentPreview = content.length > 100 ? `${content.substring(0, 100)}...` : content;
53
+ // Escape semicolons in content for YAMO format
54
+ const escapedContent = contentPreview.replace(/;/g, ",");
55
+ return `agent: MemoryMesh_${agentId};
56
+ intent: store_memory_for_future_retrieval;
57
+ context:
58
+ memory_id;${id};
59
+ memory_type;${memoryType};
60
+ timestamp;${timestamp};
61
+ content_length;${content.length};
62
+ constraints:
63
+ hypothesis;New information should be integrated into world model;
64
+ priority: medium;
65
+ output:
66
+ memory_stored;${id};
67
+ content_preview;${escapedContent};
68
+ meta:
69
+ rationale;Memory persisted for semantic search and retrieval;
70
+ observation;Content vectorized and stored in LanceDB;
71
+ confidence;1.0;
72
+ log: memory_retained;timestamp;${timestamp};id;${id};type;${memoryType};
73
+ handoff: End;
74
+ `;
75
+ }
76
+ /**
77
+ * Build a YAMO block for recall (search) operation
78
+ * Recall operations retrieve memories based on semantic similarity
79
+ */
80
+ static buildRecallBlock(params) {
81
+ const { query, resultCount, limit = 10, agentId = "default", searchType = "semantic", } = params;
82
+ const timestamp = new Date().toISOString();
83
+ const recallRatio = resultCount > 0 ? (resultCount / limit).toFixed(2) : "0.00";
84
+ return `agent: MemoryMesh_${agentId};
85
+ intent: retrieve_relevant_memories;
86
+ context:
87
+ query;${query};
88
+ search_type;${searchType};
89
+ requested_limit;${limit};
90
+ timestamp;${timestamp};
91
+ constraints:
92
+ hypothesis;Relevant memories retrieved based on query;
93
+ priority: high;
94
+ output:
95
+ results_count;${resultCount};
96
+ recall_ratio;${recallRatio};
97
+ meta:
98
+ rationale;Semantic search finds similar content by vector similarity;
99
+ observation;${resultCount} memories found matching query;
100
+ confidence;${resultCount > 0 ? "0.9" : "0.5"};
101
+ log: memory_recalled;timestamp;${timestamp};results;${resultCount};query;${query};
102
+ handoff: End;
103
+ `;
104
+ }
105
+ /**
106
+ * Build a YAMO block for delete operation (optional)
107
+ * Delete operations remove memories from the system
108
+ */
109
+ static buildDeleteBlock(params) {
110
+ const { id, agentId = "default", reason = "user_request" } = params;
111
+ const timestamp = new Date().toISOString();
112
+ return `agent: MemoryMesh_${agentId};
113
+ intent: remove_memory_from_storage;
114
+ context:
115
+ memory_id;${id};
116
+ reason;${reason};
117
+ timestamp;${timestamp};
118
+ constraints:
119
+ hypothesis;Memory removal should be traceable for audit;
120
+ priority: low;
121
+ output:
122
+ deleted;${id};
123
+ meta:
124
+ rationale;Memory removed from vector store;
125
+ observation;Deletion recorded for provenance;
126
+ confidence;1.0;
127
+ log: memory_deleted;timestamp;${timestamp};id;${id};
128
+ handoff: End;
129
+ `;
130
+ }
131
+ /**
132
+ * Validate a YAMO block structure
133
+ * Checks for required sections and proper formatting
134
+ */
135
+ static validateBlock(yamoBlock) {
136
+ const errors = [];
137
+ // Check for required sections
138
+ const requiredSections = [
139
+ "agent:",
140
+ "intent:",
141
+ "context:",
142
+ "output:",
143
+ "log:",
144
+ ];
145
+ for (const section of requiredSections) {
146
+ if (!yamoBlock.includes(section)) {
147
+ errors.push(`Missing required section: ${section}`);
148
+ }
149
+ }
150
+ // Check for semicolon termination
151
+ const lines = yamoBlock.split("\n");
152
+ for (const line of lines) {
153
+ const trimmed = line.trim();
154
+ if (trimmed.length > 0 &&
155
+ !trimmed.startsWith("//") &&
156
+ !trimmed.endsWith(";")) {
157
+ // Allow empty lines and comments
158
+ if (trimmed &&
159
+ !trimmed.startsWith("agent:") &&
160
+ !trimmed.startsWith("handoff:")) {
161
+ errors.push(`Line not semicolon-terminated: ${trimmed.substring(0, 50)}`);
162
+ }
163
+ }
164
+ }
165
+ return {
166
+ valid: errors.length === 0,
167
+ errors,
168
+ };
169
+ }
170
+ }
171
+ export default YamoEmitter;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * YAMO Module - YAMO Protocol support for yamo-memory-mesh
3
+ * Exports YAMO block construction, validation, and schema utilities
4
+ */
5
+ export { YamoEmitter } from './emitter.js';
6
+ export * from './schema.js';
7
+ declare const _default: {
8
+ YamoEmitter: typeof import("./emitter.js").YamoEmitter;
9
+ createYamoSchema: typeof import("./schema.js").createYamoSchema;
10
+ createYamoTable: typeof import("./schema.js").createYamoTable;
11
+ validateYamoRecord: typeof import("./schema.js").validateYamoRecord;
12
+ generateYamoId: typeof import("./schema.js").generateYamoId;
13
+ };
14
+ export default _default;
package/lib/yamo/index.js CHANGED
@@ -1,15 +1,14 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * YAMO Module - YAMO Protocol support for yamo-memory-mesh
3
4
  * Exports YAMO block construction, validation, and schema utilities
4
5
  */
5
-
6
6
  export { YamoEmitter } from './emitter.js';
7
7
  export * from './schema.js';
8
-
9
8
  export default {
10
- YamoEmitter: (await import('./emitter.js')).YamoEmitter,
11
- createYamoSchema: (await import('./schema.js')).createYamoSchema,
12
- createYamoTable: (await import('./schema.js')).createYamoTable,
13
- validateYamoRecord: (await import('./schema.js')).validateYamoRecord,
14
- generateYamoId: (await import('./schema.js')).generateYamoId
9
+ YamoEmitter: (await import('./emitter.js')).YamoEmitter,
10
+ createYamoSchema: (await import('./schema.js')).createYamoSchema,
11
+ createYamoTable: (await import('./schema.js')).createYamoTable,
12
+ validateYamoRecord: (await import('./schema.js')).validateYamoRecord,
13
+ generateYamoId: (await import('./schema.js')).generateYamoId
15
14
  };
@@ -0,0 +1,16 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * YAMO Module - YAMO Protocol support for yamo-memory-mesh
4
+ * Exports YAMO block construction, validation, and schema utilities
5
+ */
6
+
7
+ export { YamoEmitter } from './emitter.js';
8
+ export * from './schema.js';
9
+
10
+ export default {
11
+ YamoEmitter: (await import('./emitter.js')).YamoEmitter,
12
+ createYamoSchema: (await import('./schema.js')).createYamoSchema,
13
+ createYamoTable: (await import('./schema.js')).createYamoTable,
14
+ validateYamoRecord: (await import('./schema.js')).validateYamoRecord,
15
+ generateYamoId: (await import('./schema.js')).generateYamoId
16
+ };