@holoscript/framework 6.0.3 → 6.0.4

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 (160) hide show
  1. package/CHANGELOG.md +1 -2
  2. package/ROADMAP.md +68 -66
  3. package/dist/{InvisibleWallet-BB6tFvRA.d.cts → InvisibleWallet-EFiuaLn3.d.cts} +1 -1
  4. package/dist/{OrchestratorAgent-BvWgf9uw.d.cts → OrchestratorAgent-CrLDGNL6.d.cts} +1 -1
  5. package/dist/agents/index.cjs +11 -10
  6. package/dist/agents/index.d.cts +4 -16
  7. package/dist/ai/index.cjs +2 -2
  8. package/dist/behavior.cjs +10 -0
  9. package/dist/economy/index.cjs +4 -4
  10. package/dist/economy/index.d.cts +2 -2
  11. package/dist/index.cjs +33 -11
  12. package/dist/index.d.cts +3 -3
  13. package/dist/swarm/index.cjs +3 -0
  14. package/package.json +14 -9
  15. package/src/__tests__/bounty-marketplace.test.ts +53 -21
  16. package/src/__tests__/delegation.test.ts +1 -4
  17. package/src/__tests__/done-log-audit.test.ts +38 -46
  18. package/src/__tests__/framework.test.ts +172 -53
  19. package/src/__tests__/goal-synthesizer.test.ts +9 -6
  20. package/src/__tests__/presence.test.ts +1 -1
  21. package/src/__tests__/protocol-agent.test.ts +12 -11
  22. package/src/__tests__/revenue-splitter.test.ts +22 -15
  23. package/src/__tests__/scenario-driven-todo.test.ts +55 -35
  24. package/src/__tests__/self-improve.test.ts +28 -9
  25. package/src/__tests__/service-lifecycle.test.ts +9 -3
  26. package/src/__tests__/skill-router.test.ts +3 -3
  27. package/src/agents/CulturalMemory.ts +6 -6
  28. package/src/agents/DelegationTraceHooks.ts +560 -0
  29. package/src/agents/FederatedRegistryAdapter.ts +1 -1
  30. package/src/agents/NormEngine.ts +3 -8
  31. package/src/agents/OrchestratorAgent.ts +1 -1
  32. package/src/agents/TaskDelegationService.ts +5 -9
  33. package/src/agents/__tests__/AgentWalletRegistry.test.ts +5 -4
  34. package/src/agents/__tests__/CrossRealityHandoff.test.ts +9 -3
  35. package/src/agents/__tests__/DelegationTraceHooks.test.ts +390 -0
  36. package/src/agents/__tests__/TaskDelegationService.test.ts +4 -2
  37. package/src/agents/spatial-comms/Layer1RealTime.ts +36 -19
  38. package/src/agents/spatial-comms/Layer2A2A.ts +1 -3
  39. package/src/agents/spatial-comms/Layer3MCP.ts +13 -4
  40. package/src/agents/spatial-comms/ProtocolTypes.ts +5 -2
  41. package/src/agents/spatial-comms/examples/multi-agent-world-creation.ts +2 -2
  42. package/src/ai/HoloScriptGenerator.ts +2 -2
  43. package/src/ai/__tests__/PerceptionSystem.prod.test.ts +1 -1
  44. package/src/ai/__tests__/PerceptionSystem.test.ts +14 -14
  45. package/src/ai/__tests__/SteeringBehaviors.prod.test.ts +1 -1
  46. package/src/ai/index.ts +5 -1
  47. package/src/board/audit.ts +17 -6
  48. package/src/board/board-ops.ts +45 -15
  49. package/src/board/board-types.ts +94 -20
  50. package/src/delegation.ts +5 -3
  51. package/src/distributed-claimer.ts +13 -2
  52. package/src/economy/BountyManager.ts +40 -18
  53. package/src/economy/KnowledgeMarketplace.ts +27 -8
  54. package/src/economy/PaymentWebhookService.ts +0 -1
  55. package/src/economy/RevenueSplitter.ts +2 -4
  56. package/src/economy/UnifiedBudgetOptimizer.ts +8 -9
  57. package/src/economy/_core-stubs.ts +1 -1
  58. package/src/economy/x402-facilitator.ts +17 -8
  59. package/src/index.ts +16 -12
  60. package/src/knowledge/__tests__/knowledge-consolidator.test.ts +138 -89
  61. package/src/knowledge/__tests__/knowledge-store-vector.test.ts +59 -16
  62. package/src/knowledge/brain.ts +7 -7
  63. package/src/knowledge/consolidation.ts +16 -16
  64. package/src/knowledge/knowledge-consolidator.ts +60 -30
  65. package/src/knowledge/knowledge-store.ts +83 -45
  66. package/src/learning/ProceduralCompiler.ts +6 -1
  67. package/src/learning/learning/MemoryConsolidator.ts +102 -0
  68. package/src/learning/learning/MemoryScorer.ts +69 -0
  69. package/src/learning/learning/ProceduralCompiler.ts +45 -0
  70. package/src/learning/learning/SemanticClusterer.ts +66 -0
  71. package/src/llm/llm-adapter.ts +24 -10
  72. package/src/mesh/index.ts +37 -17
  73. package/src/protocol/goal-synthesizer.ts +24 -34
  74. package/src/protocol/implementations.ts +91 -22
  75. package/src/protocol/micro-phase-decomposer.ts +25 -17
  76. package/src/protocol/micro-step-decomposer.test.ts +104 -39
  77. package/src/protocol-agent.test.ts +17 -7
  78. package/src/protocol-agent.ts +45 -42
  79. package/src/self-improve/absorb-scanner.ts +9 -6
  80. package/src/self-improve/evolution-engine.ts +36 -18
  81. package/src/self-improve/framework-absorber.ts +21 -16
  82. package/src/self-improve/index.ts +2 -10
  83. package/src/self-improve/prompt-optimizer.ts +31 -19
  84. package/src/self-improve/test-generator.ts +16 -12
  85. package/src/skill-router.ts +7 -6
  86. package/src/swarm/messaging/GossipProtocol.ts +1 -1
  87. package/src/swarm/messaging/__tests__/BroadcastChannel.prod.test.ts +31 -9
  88. package/src/swarm/messaging/__tests__/GossipProtocol.prod.test.ts +21 -7
  89. package/src/swarm/messaging/__tests__/SwarmEventBus.prod.test.ts +24 -8
  90. package/src/swarm/messaging/__tests__/SwarmEventBus.test.ts +6 -2
  91. package/src/team.ts +277 -122
  92. package/src/training/scripts/generate-spatial-dataset.ts +1 -1
  93. package/src/training/training/LRScheduler.ts +377 -0
  94. package/src/training/training/QualityScoringPipeline.ts +139 -0
  95. package/src/training/training/SoftDedup.ts +461 -0
  96. package/src/training/training/SparsityMonitor.ts +685 -0
  97. package/src/training/training/SparsityMonitorTypes.ts +209 -0
  98. package/src/training/training/SpatialTrainingDataGenerator.ts +1526 -0
  99. package/src/training/training/SpatialTrainingDataTypes.ts +216 -0
  100. package/src/training/training/TrainingPipelineConfig.ts +215 -0
  101. package/src/training/training/__tests__/CorpusValidation.test.ts +87 -0
  102. package/src/training/training/__tests__/LRScheduler.test.ts +592 -0
  103. package/src/training/training/__tests__/SoftDedup.test.ts +415 -0
  104. package/src/training/training/__tests__/SparsityMonitor.test.ts +1623 -0
  105. package/src/training/training/__tests__/SpatialCorpusValidation.test.ts +72 -0
  106. package/src/training/training/__tests__/SpatialTrainingDataGenerator.test.ts +1244 -0
  107. package/src/training/training/__tests__/TrainingMonkeyIntegration.test.ts +897 -0
  108. package/src/training/training/__tests__/TrainingPipelineConfig.test.ts +202 -0
  109. package/src/training/training/__tests__/schema.test.ts +72 -0
  110. package/src/training/training/__tests__/training-constants.test.ts +106 -0
  111. package/src/training/training/__tests__/trait-mappings.test.ts +81 -0
  112. package/src/training/training/constants.ts +94 -0
  113. package/src/training/training/index.ts +17 -0
  114. package/src/training/training/schema.ts +147 -0
  115. package/src/training/training/scripts/generate-novel-use-cases-dataset.ts +272 -0
  116. package/src/training/training/scripts/generate-spatial-dataset.ts +521 -0
  117. package/src/training/training/trainingmonkey/TrainingMonkeyIntegration.ts +477 -0
  118. package/src/training/training/trainingmonkey/TrainingMonkeyTypes.ts +230 -0
  119. package/src/training/training/trainingmonkey/index.ts +26 -0
  120. package/src/training/training/trait-mappings.ts +157 -0
  121. package/src/types.ts +2 -7
  122. package/ALL-test-results.json +0 -1
  123. package/LICENSE +0 -21
  124. package/dist/AgentManifest-CB4xM-Ma.d.ts +0 -704
  125. package/dist/BehaviorTree-BrBFECv5.d.ts +0 -103
  126. package/dist/InvisibleWallet-rtRrBOA8.d.ts +0 -1732
  127. package/dist/OrchestratorAgent-Q_CbVTmO.d.ts +0 -798
  128. package/dist/agents/index.d.ts +0 -1788
  129. package/dist/agents/index.js +0 -4695
  130. package/dist/ai/index.d.ts +0 -1753
  131. package/dist/ai/index.js +0 -5244
  132. package/dist/behavior.d.ts +0 -130
  133. package/dist/behavior.js +0 -407
  134. package/dist/economy/index.d.ts +0 -747
  135. package/dist/economy/index.js +0 -3617
  136. package/dist/implementations-D9T3un9D.d.ts +0 -236
  137. package/dist/index.d.ts +0 -1729
  138. package/dist/index.js +0 -24277
  139. package/dist/learning/index.d.ts +0 -104
  140. package/dist/learning/index.js +0 -189
  141. package/dist/negotiation/index.d.ts +0 -610
  142. package/dist/negotiation/index.js +0 -931
  143. package/dist/skills/index.d.ts +0 -289
  144. package/dist/skills/index.js +0 -1079
  145. package/dist/swarm/index.d.ts +0 -2433
  146. package/dist/swarm/index.js +0 -5221
  147. package/dist/training/index.d.ts +0 -1734
  148. package/dist/training/index.js +0 -2687
  149. package/extract-failures.js +0 -10
  150. package/src/training/training/data/novel-use-cases.jsonl +0 -153
  151. package/src/training/training/data/spatial-reasoning-10k.jsonl +0 -9354
  152. package/src/types/core-stubs.d.ts +0 -113
  153. package/test-output.txt +0 -0
  154. package/test-result.json +0 -1
  155. package/tsc-errors.txt +0 -4
  156. package/tsc_output.txt +0 -0
  157. package/typescript-errors-2.txt +0 -0
  158. package/typescript-errors.txt +0 -22
  159. package/vitest-log-utf8.txt +0 -268
  160. package/vitest-log.txt +0 -0
@@ -71,8 +71,14 @@ describe('KnowledgeConsolidator', () => {
71
71
  describe('importFromStore', () => {
72
72
  it('imports all entries from a KnowledgeStore', () => {
73
73
  const store = new KnowledgeStore({ persist: false });
74
- store.publish({ type: 'wisdom', content: 'Entry A', domain: 'security', confidence: 0.9, source: 'test' }, 'agent-a');
75
- store.publish({ type: 'pattern', content: 'Entry B', domain: 'agents', confidence: 0.8, source: 'test' }, 'agent-b');
74
+ store.publish(
75
+ { type: 'wisdom', content: 'Entry A', domain: 'security', confidence: 0.9, source: 'test' },
76
+ 'agent-a'
77
+ );
78
+ store.publish(
79
+ { type: 'pattern', content: 'Entry B', domain: 'agents', confidence: 0.8, source: 'test' },
80
+ 'agent-b'
81
+ );
76
82
 
77
83
  const imported = consolidator.importFromStore(store);
78
84
  expect(imported).toBe(2);
@@ -81,7 +87,10 @@ describe('KnowledgeConsolidator', () => {
81
87
 
82
88
  it('skips already-imported entries', () => {
83
89
  const store = new KnowledgeStore({ persist: false });
84
- store.publish({ type: 'wisdom', content: 'Entry A', domain: 'general', confidence: 0.9, source: 'test' }, 'agent-a');
90
+ store.publish(
91
+ { type: 'wisdom', content: 'Entry A', domain: 'general', confidence: 0.9, source: 'test' },
92
+ 'agent-a'
93
+ );
85
94
 
86
95
  consolidator.importFromStore(store);
87
96
  const second = consolidator.importFromStore(store);
@@ -219,40 +228,50 @@ describe('KnowledgeConsolidator', () => {
219
228
 
220
229
  describe('surfaceCrossDomainPatterns', () => {
221
230
  it('finds patterns shared across domains', () => {
222
- consolidator.addEntry(makeEntry({
223
- id: 'W.SEC.001',
224
- content: 'WebSocket connections require authentication tokens',
225
- domain: 'security',
226
- }));
227
- consolidator.addEntry(makeEntry({
228
- id: 'W.AGENT.001',
229
- content: 'Agent WebSocket connections drop after timeout',
230
- domain: 'agents',
231
- }));
231
+ consolidator.addEntry(
232
+ makeEntry({
233
+ id: 'W.SEC.001',
234
+ content: 'WebSocket connections require authentication tokens',
235
+ domain: 'security',
236
+ })
237
+ );
238
+ consolidator.addEntry(
239
+ makeEntry({
240
+ id: 'W.AGENT.001',
241
+ content: 'Agent WebSocket connections drop after timeout',
242
+ domain: 'agents',
243
+ })
244
+ );
232
245
 
233
246
  const patterns = consolidator.surfaceCrossDomainPatterns();
234
- const wsPattern = patterns.find(p => p.pattern === 'websocket');
247
+ const wsPattern = patterns.find((p) => p.pattern === 'websocket');
235
248
  expect(wsPattern).toBeDefined();
236
249
  expect(wsPattern!.domains).toContain('security');
237
250
  expect(wsPattern!.domains).toContain('agents');
238
251
  });
239
252
 
240
253
  it('filters by specified domains', () => {
241
- consolidator.addEntry(makeEntry({
242
- id: 'W.SEC.F1',
243
- content: 'Authentication tokens expire after timeout',
244
- domain: 'security',
245
- }));
246
- consolidator.addEntry(makeEntry({
247
- id: 'W.AGENT.F1',
248
- content: 'Agent tokens refresh automatically',
249
- domain: 'agents',
250
- }));
251
- consolidator.addEntry(makeEntry({
252
- id: 'W.COMP.F1',
253
- content: 'Compiler tokens are parsed differently',
254
- domain: 'compilation',
255
- }));
254
+ consolidator.addEntry(
255
+ makeEntry({
256
+ id: 'W.SEC.F1',
257
+ content: 'Authentication tokens expire after timeout',
258
+ domain: 'security',
259
+ })
260
+ );
261
+ consolidator.addEntry(
262
+ makeEntry({
263
+ id: 'W.AGENT.F1',
264
+ content: 'Agent tokens refresh automatically',
265
+ domain: 'agents',
266
+ })
267
+ );
268
+ consolidator.addEntry(
269
+ makeEntry({
270
+ id: 'W.COMP.F1',
271
+ content: 'Compiler tokens are parsed differently',
272
+ domain: 'compilation',
273
+ })
274
+ );
256
275
 
257
276
  const patterns = consolidator.surfaceCrossDomainPatterns(['security', 'agents']);
258
277
  // Should not include compilation domain
@@ -262,15 +281,17 @@ describe('KnowledgeConsolidator', () => {
262
281
  });
263
282
 
264
283
  it('returns empty for single-domain entries', () => {
265
- consolidator.addEntry(makeEntry({
266
- id: 'W.ONLY.001',
267
- content: 'Only security concern here',
268
- domain: 'security',
269
- }));
284
+ consolidator.addEntry(
285
+ makeEntry({
286
+ id: 'W.ONLY.001',
287
+ content: 'Only security concern here',
288
+ domain: 'security',
289
+ })
290
+ );
270
291
 
271
292
  const patterns = consolidator.surfaceCrossDomainPatterns();
272
293
  // No pattern can span 2+ domains with only 1 domain present
273
- expect(patterns.every(p => p.domains.length >= 2)).toBe(true);
294
+ expect(patterns.every((p) => p.domains.length >= 2)).toBe(true);
274
295
  });
275
296
  });
276
297
 
@@ -278,16 +299,20 @@ describe('KnowledgeConsolidator', () => {
278
299
 
279
300
  describe('detectContradictions', () => {
280
301
  it('detects negation-based contradictions', () => {
281
- consolidator.addEntry(makeEntry({
282
- id: 'W.CON.A',
283
- content: 'You should always validate input before processing',
284
- domain: 'security',
285
- }));
286
- consolidator.addEntry(makeEntry({
287
- id: 'W.CON.B',
288
- content: 'You should never validate input in the render loop',
289
- domain: 'security',
290
- }));
302
+ consolidator.addEntry(
303
+ makeEntry({
304
+ id: 'W.CON.A',
305
+ content: 'You should always validate input before processing',
306
+ domain: 'security',
307
+ })
308
+ );
309
+ consolidator.addEntry(
310
+ makeEntry({
311
+ id: 'W.CON.B',
312
+ content: 'You should never validate input in the render loop',
313
+ domain: 'security',
314
+ })
315
+ );
291
316
 
292
317
  const contradictions = consolidator.detectContradictions();
293
318
  expect(contradictions.length).toBeGreaterThanOrEqual(1);
@@ -297,32 +322,40 @@ describe('KnowledgeConsolidator', () => {
297
322
  });
298
323
 
299
324
  it('detects should/should not contradictions', () => {
300
- consolidator.addEntry(makeEntry({
301
- id: 'W.REC.A',
302
- content: 'Agents should enable caching for performance',
303
- domain: 'agents',
304
- }));
305
- consolidator.addEntry(makeEntry({
306
- id: 'W.REC.B',
307
- content: 'Agents should not enable caching in tests',
308
- domain: 'agents',
309
- }));
325
+ consolidator.addEntry(
326
+ makeEntry({
327
+ id: 'W.REC.A',
328
+ content: 'Agents should enable caching for performance',
329
+ domain: 'agents',
330
+ })
331
+ );
332
+ consolidator.addEntry(
333
+ makeEntry({
334
+ id: 'W.REC.B',
335
+ content: 'Agents should not enable caching in tests',
336
+ domain: 'agents',
337
+ })
338
+ );
310
339
 
311
340
  const contradictions = consolidator.detectContradictions();
312
341
  expect(contradictions.length).toBeGreaterThanOrEqual(1);
313
342
  });
314
343
 
315
344
  it('returns empty for non-contradicting entries', () => {
316
- consolidator.addEntry(makeEntry({
317
- id: 'W.OK.A',
318
- content: 'Use TypeScript for type safety',
319
- domain: 'compilation',
320
- }));
321
- consolidator.addEntry(makeEntry({
322
- id: 'W.OK.B',
323
- content: 'Prefer vitest over jest for testing',
324
- domain: 'compilation',
325
- }));
345
+ consolidator.addEntry(
346
+ makeEntry({
347
+ id: 'W.OK.A',
348
+ content: 'Use TypeScript for type safety',
349
+ domain: 'compilation',
350
+ })
351
+ );
352
+ consolidator.addEntry(
353
+ makeEntry({
354
+ id: 'W.OK.B',
355
+ content: 'Prefer vitest over jest for testing',
356
+ domain: 'compilation',
357
+ })
358
+ );
326
359
 
327
360
  const contradictions = consolidator.detectContradictions();
328
361
  expect(contradictions.length).toBe(0);
@@ -330,8 +363,16 @@ describe('KnowledgeConsolidator', () => {
330
363
 
331
364
  it('accepts external entry array', () => {
332
365
  const entries: StoredEntry[] = [
333
- makeEntry({ id: 'W.EXT.A', content: 'Feature is deprecated and removed', domain: 'general' }),
334
- makeEntry({ id: 'W.EXT.B', content: 'Feature is recommended and added recently', domain: 'general' }),
366
+ makeEntry({
367
+ id: 'W.EXT.A',
368
+ content: 'Feature is deprecated and removed',
369
+ domain: 'general',
370
+ }),
371
+ makeEntry({
372
+ id: 'W.EXT.B',
373
+ content: 'Feature is recommended and added recently',
374
+ domain: 'general',
375
+ }),
335
376
  ];
336
377
 
337
378
  const contradictions = consolidator.detectContradictions(entries);
@@ -339,30 +380,38 @@ describe('KnowledgeConsolidator', () => {
339
380
  });
340
381
 
341
382
  it('assigns higher confidence to same-domain contradictions', () => {
342
- consolidator.addEntry(makeEntry({
343
- id: 'W.CONF.A',
344
- content: 'Always enable debug logging in production',
345
- domain: 'security',
346
- }));
347
- consolidator.addEntry(makeEntry({
348
- id: 'W.CONF.B',
349
- content: 'Never enable debug logging anywhere',
350
- domain: 'security',
351
- }));
352
- consolidator.addEntry(makeEntry({
353
- id: 'W.CONF.C',
354
- content: 'Always enable verbose logging modes',
355
- domain: 'agents',
356
- }));
357
- consolidator.addEntry(makeEntry({
358
- id: 'W.CONF.D',
359
- content: 'Never enable verbose logging modes',
360
- domain: 'rendering',
361
- }));
383
+ consolidator.addEntry(
384
+ makeEntry({
385
+ id: 'W.CONF.A',
386
+ content: 'Always enable debug logging in production',
387
+ domain: 'security',
388
+ })
389
+ );
390
+ consolidator.addEntry(
391
+ makeEntry({
392
+ id: 'W.CONF.B',
393
+ content: 'Never enable debug logging anywhere',
394
+ domain: 'security',
395
+ })
396
+ );
397
+ consolidator.addEntry(
398
+ makeEntry({
399
+ id: 'W.CONF.C',
400
+ content: 'Always enable verbose logging modes',
401
+ domain: 'agents',
402
+ })
403
+ );
404
+ consolidator.addEntry(
405
+ makeEntry({
406
+ id: 'W.CONF.D',
407
+ content: 'Never enable verbose logging modes',
408
+ domain: 'rendering',
409
+ })
410
+ );
362
411
 
363
412
  const contradictions = consolidator.detectContradictions();
364
- const sameDomain = contradictions.filter(c => c.entryA.domain === c.entryB.domain);
365
- const crossDomain = contradictions.filter(c => c.entryA.domain !== c.entryB.domain);
413
+ const sameDomain = contradictions.filter((c) => c.entryA.domain === c.entryB.domain);
414
+ const crossDomain = contradictions.filter((c) => c.entryA.domain !== c.entryB.domain);
366
415
 
367
416
  if (sameDomain.length > 0 && crossDomain.length > 0) {
368
417
  expect(sameDomain[0].confidence).toBeGreaterThan(crossDomain[0].confidence);
@@ -14,10 +14,12 @@ import type { KnowledgeConfig, KnowledgeInsight } from '../../types';
14
14
  function makeConfig(remote = true): KnowledgeConfig {
15
15
  return {
16
16
  persist: false,
17
- ...(remote ? {
18
- remoteUrl: 'https://mcp-orchestrator-production-45f9.up.railway.app',
19
- remoteApiKey: 'test-api-key',
20
- } : {}),
17
+ ...(remote
18
+ ? {
19
+ remoteUrl: 'https://mcp-orchestrator-production-45f9.up.railway.app',
20
+ remoteApiKey: 'test-api-key',
21
+ }
22
+ : {}),
21
23
  };
22
24
  }
23
25
 
@@ -159,8 +161,18 @@ describe('KnowledgeStore — Vector Embedding Pipeline', () => {
159
161
  describe('semanticSearch', () => {
160
162
  it('returns remote results when available', async () => {
161
163
  const remoteEntries = [
162
- { id: 'r1', type: 'wisdom', content: 'Use strict mode', metadata: { domain: 'compilation', confidence: 0.8 } },
163
- { id: 'r2', type: 'pattern', content: 'Pattern matching', metadata: { domain: 'compilation', confidence: 0.7 } },
164
+ {
165
+ id: 'r1',
166
+ type: 'wisdom',
167
+ content: 'Use strict mode',
168
+ metadata: { domain: 'compilation', confidence: 0.8 },
169
+ },
170
+ {
171
+ id: 'r2',
172
+ type: 'pattern',
173
+ content: 'Pattern matching',
174
+ metadata: { domain: 'compilation', confidence: 0.7 },
175
+ },
164
176
  ];
165
177
  globalThis.fetch = mockFetchOk(remoteEntries);
166
178
 
@@ -218,8 +230,18 @@ describe('KnowledgeStore — Vector Embedding Pipeline', () => {
218
230
 
219
231
  it('filters by minConfidence', async () => {
220
232
  const remoteEntries = [
221
- { id: 'r1', type: 'wisdom', content: 'High confidence', metadata: { confidence: 0.9, domain: 'general' } },
222
- { id: 'r2', type: 'wisdom', content: 'Low confidence', metadata: { confidence: 0.3, domain: 'general' } },
233
+ {
234
+ id: 'r1',
235
+ type: 'wisdom',
236
+ content: 'High confidence',
237
+ metadata: { confidence: 0.9, domain: 'general' },
238
+ },
239
+ {
240
+ id: 'r2',
241
+ type: 'wisdom',
242
+ content: 'Low confidence',
243
+ metadata: { confidence: 0.3, domain: 'general' },
244
+ },
223
245
  ];
224
246
  globalThis.fetch = mockFetchOk(remoteEntries);
225
247
 
@@ -247,19 +269,35 @@ describe('KnowledgeStore — Vector Embedding Pipeline', () => {
247
269
 
248
270
  it('hybrid search merges remote + local, deduped by ID', async () => {
249
271
  const remoteEntries = [
250
- { id: 'r1', type: 'wisdom', content: 'Remote only', metadata: { domain: 'general', confidence: 0.9 } },
251
- { id: 'shared', type: 'wisdom', content: 'Remote version', metadata: { domain: 'general', confidence: 0.8 } },
272
+ {
273
+ id: 'r1',
274
+ type: 'wisdom',
275
+ content: 'Remote only',
276
+ metadata: { domain: 'general', confidence: 0.9 },
277
+ },
278
+ {
279
+ id: 'shared',
280
+ type: 'wisdom',
281
+ content: 'Remote version',
282
+ metadata: { domain: 'general', confidence: 0.8 },
283
+ },
252
284
  ];
253
285
  globalThis.fetch = mockFetchOk(remoteEntries);
254
286
 
255
287
  const store = new KnowledgeStore(makeConfig());
256
288
  // Publish a local entry that has the same ID as a remote entry
257
- const local = store.publish(makeInsight({ content: 'Local entry about general topics' }), 'agent-a');
258
-
259
- const results = await store.semanticSearch('general topics', { hybridSearch: true, limit: 10 });
289
+ const local = store.publish(
290
+ makeInsight({ content: 'Local entry about general topics' }),
291
+ 'agent-a'
292
+ );
293
+
294
+ const results = await store.semanticSearch('general topics', {
295
+ hybridSearch: true,
296
+ limit: 10,
297
+ });
260
298
 
261
299
  // Should contain remote entries + local entries, no duplicate IDs
262
- const ids = results.map(r => r.id);
300
+ const ids = results.map((r) => r.id);
263
301
  const uniqueIds = new Set(ids);
264
302
  expect(ids.length).toBe(uniqueIds.size);
265
303
 
@@ -275,14 +313,19 @@ describe('KnowledgeStore — Vector Embedding Pipeline', () => {
275
313
 
276
314
  // Remote returns an entry with the same ID but different content
277
315
  const remoteEntries = [
278
- { id: localId, type: 'wisdom', content: 'Remote version of knowledge', metadata: { domain: 'compilation', confidence: 0.95 } },
316
+ {
317
+ id: localId,
318
+ type: 'wisdom',
319
+ content: 'Remote version of knowledge',
320
+ metadata: { domain: 'compilation', confidence: 0.95 },
321
+ },
279
322
  ];
280
323
  globalThis.fetch = mockFetchOk(remoteEntries);
281
324
 
282
325
  const results = await store.semanticSearch('knowledge', { hybridSearch: true });
283
326
 
284
327
  // The entry with localId should appear exactly once
285
- const matching = results.filter(r => r.id === localId);
328
+ const matching = results.filter((r) => r.id === localId);
286
329
  expect(matching).toHaveLength(1);
287
330
  // Remote wins (appears first in merge)
288
331
  expect(matching[0].content).toBe('Remote version of knowledge');
@@ -50,7 +50,7 @@ export const DOMAIN_CONSOLIDATION: Record<KnowledgeDomain, DomainConsolidationCo
50
50
  sleepFrequencyMs: 12 * 60 * 60 * 1000,
51
51
  maxEntries: 150,
52
52
  competitionMetric: 'query_frequency',
53
- downscaleFactor: 0.90,
53
+ downscaleFactor: 0.9,
54
54
  minCorroborations: 1,
55
55
  },
56
56
  compilation: {
@@ -58,7 +58,7 @@ export const DOMAIN_CONSOLIDATION: Record<KnowledgeDomain, DomainConsolidationCo
58
58
  sleepFrequencyMs: 12 * 60 * 60 * 1000,
59
59
  maxEntries: 100,
60
60
  competitionMetric: 'citation_count',
61
- downscaleFactor: 0.90,
61
+ downscaleFactor: 0.9,
62
62
  minCorroborations: 1,
63
63
  },
64
64
  general: {
@@ -74,11 +74,11 @@ export const DOMAIN_CONSOLIDATION: Record<KnowledgeDomain, DomainConsolidationCo
74
74
  // ── Half-Lives ──
75
75
 
76
76
  export const DOMAIN_HALF_LIVES: Record<KnowledgeDomain, number> = {
77
- security: 2 * 24 * 60 * 60 * 1000, // 2 days
78
- rendering: 14 * 24 * 60 * 60 * 1000, // 14 days
79
- agents: 7 * 24 * 60 * 60 * 1000, // 7 days
80
- compilation: 21 * 24 * 60 * 60 * 1000, // 21 days
81
- general: 7 * 24 * 60 * 60 * 1000, // 7 days
77
+ security: 2 * 24 * 60 * 60 * 1000, // 2 days
78
+ rendering: 14 * 24 * 60 * 60 * 1000, // 14 days
79
+ agents: 7 * 24 * 60 * 60 * 1000, // 7 days
80
+ compilation: 21 * 24 * 60 * 60 * 1000, // 21 days
81
+ general: 7 * 24 * 60 * 60 * 1000, // 7 days
82
82
  };
83
83
 
84
84
  // ── Hot Buffer ──
@@ -68,9 +68,15 @@ function defaultExcitability(): ExcitabilityMetadata {
68
68
  function containsInjectionPattern(content: string): boolean {
69
69
  if (!content || typeof content !== 'string') return false;
70
70
 
71
- if (/["'];?\s*(import|require|exec|system|Process|eval|Function)\s*[.(]/i.test(content)) return true;
71
+ if (/["'];?\s*(import|require|exec|system|Process|eval|Function)\s*[.(]/i.test(content))
72
+ return true;
72
73
  if (/<script[\s>]/i.test(content)) return true;
73
- if (/\b(os\.execute|os\.system|Runtime\.getRuntime|child_process|Process\.Start)\s*\(/i.test(content)) return true;
74
+ if (
75
+ /\b(os\.execute|os\.system|Runtime\.getRuntime|child_process|Process\.Start)\s*\(/i.test(
76
+ content
77
+ )
78
+ )
79
+ return true;
74
80
  if (/#\s*(include|pragma|define)\b/i.test(content)) return true;
75
81
  if (content.includes('\0')) return true;
76
82
  if (/OS\.(execute|shell_open)\s*\(/i.test(content)) return true;
@@ -155,7 +161,7 @@ export class ConsolidationEngine {
155
161
  */
156
162
  corroborate(domain: KnowledgeDomain, entryId: string, peerDid: string): boolean {
157
163
  const buffer = this.hotBuffers.get(domain) || [];
158
- const entry = buffer.find(e => e.id === entryId);
164
+ const entry = buffer.find((e) => e.id === entryId);
159
165
  if (!entry) return false;
160
166
  if (!entry.corroborations.includes(peerDid)) {
161
167
  entry.corroborations.push(peerDid);
@@ -230,8 +236,8 @@ export class ConsolidationEngine {
230
236
  // Phase 2 & 3: CLUSTER + MERGE — deduplicate by content+type equality
231
237
  const uniqueEntries: HotBufferEntry[] = [];
232
238
  for (const entry of sanitized) {
233
- const duplicate = uniqueEntries.find(e =>
234
- e.content === entry.content && e.type === entry.type
239
+ const duplicate = uniqueEntries.find(
240
+ (e) => e.content === entry.content && e.type === entry.type
235
241
  );
236
242
  if (duplicate) {
237
243
  // Merge corroborations from duplicate
@@ -333,7 +339,7 @@ export class ConsolidationEngine {
333
339
  */
334
340
  needsConsolidation(): { domain: KnowledgeDomain; overdue: boolean; bufferSize: number }[] {
335
341
  const now = Date.now();
336
- return KNOWLEDGE_DOMAINS.map(domain => {
342
+ return KNOWLEDGE_DOMAINS.map((domain) => {
337
343
  const config = DOMAIN_CONSOLIDATION[domain];
338
344
  const lastRun = this.lastConsolidation.get(domain) || 0;
339
345
  const elapsed = now - lastRun;
@@ -392,11 +398,7 @@ export class ConsolidationEngine {
392
398
  * Update an entry during its reconsolidation window.
393
399
  * Returns false if the window is closed or entry not found.
394
400
  */
395
- reconsolidateEntry(
396
- domain: KnowledgeDomain,
397
- entryId: string,
398
- updatedContent: string
399
- ): boolean {
401
+ reconsolidateEntry(domain: KnowledgeDomain, entryId: string, updatedContent: string): boolean {
400
402
  const window = this.reconsolidationWindows.get(entryId);
401
403
  if (!window || !window.windowOpen || Date.now() > window.windowClosesAt) {
402
404
  return false;
@@ -488,7 +490,7 @@ export class ConsolidationEngine {
488
490
 
489
491
  /** Get hot buffer size across all domains. */
490
492
  getHotBufferStats(): { domain: string; count: number }[] {
491
- return KNOWLEDGE_DOMAINS.map(domain => ({
493
+ return KNOWLEDGE_DOMAINS.map((domain) => ({
492
494
  domain,
493
495
  count: (this.hotBuffers.get(domain) || []).length,
494
496
  }));
@@ -496,7 +498,7 @@ export class ConsolidationEngine {
496
498
 
497
499
  /** Get cold store size across all domains. */
498
500
  getColdStoreStats(): { domain: string; count: number }[] {
499
- return KNOWLEDGE_DOMAINS.map(domain => ({
501
+ return KNOWLEDGE_DOMAINS.map((domain) => ({
500
502
  domain,
501
503
  count: (this.coldStores.get(domain) || new Map()).size,
502
504
  }));
@@ -566,9 +568,7 @@ export interface CrossDomainMatch {
566
568
 
567
569
  /** Tokenize content into a set of lowercase words (3+ chars). */
568
570
  function tokenize(content: string): Set<string> {
569
- return new Set(
570
- content.toLowerCase().match(/[a-z0-9]{3,}/g) || []
571
- );
571
+ return new Set(content.toLowerCase().match(/[a-z0-9]{3,}/g) || []);
572
572
  }
573
573
 
574
574
  /** Jaccard overlap between two sets. */