@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.
- package/CHANGELOG.md +1 -2
- package/ROADMAP.md +68 -66
- package/dist/{InvisibleWallet-BB6tFvRA.d.cts → InvisibleWallet-EFiuaLn3.d.cts} +1 -1
- package/dist/{OrchestratorAgent-BvWgf9uw.d.cts → OrchestratorAgent-CrLDGNL6.d.cts} +1 -1
- package/dist/agents/index.cjs +11 -10
- package/dist/agents/index.d.cts +4 -16
- package/dist/ai/index.cjs +2 -2
- package/dist/behavior.cjs +10 -0
- package/dist/economy/index.cjs +4 -4
- package/dist/economy/index.d.cts +2 -2
- package/dist/index.cjs +33 -11
- package/dist/index.d.cts +3 -3
- package/dist/swarm/index.cjs +3 -0
- package/package.json +14 -9
- package/src/__tests__/bounty-marketplace.test.ts +53 -21
- package/src/__tests__/delegation.test.ts +1 -4
- package/src/__tests__/done-log-audit.test.ts +38 -46
- package/src/__tests__/framework.test.ts +172 -53
- package/src/__tests__/goal-synthesizer.test.ts +9 -6
- package/src/__tests__/presence.test.ts +1 -1
- package/src/__tests__/protocol-agent.test.ts +12 -11
- package/src/__tests__/revenue-splitter.test.ts +22 -15
- package/src/__tests__/scenario-driven-todo.test.ts +55 -35
- package/src/__tests__/self-improve.test.ts +28 -9
- package/src/__tests__/service-lifecycle.test.ts +9 -3
- package/src/__tests__/skill-router.test.ts +3 -3
- package/src/agents/CulturalMemory.ts +6 -6
- package/src/agents/DelegationTraceHooks.ts +560 -0
- package/src/agents/FederatedRegistryAdapter.ts +1 -1
- package/src/agents/NormEngine.ts +3 -8
- package/src/agents/OrchestratorAgent.ts +1 -1
- package/src/agents/TaskDelegationService.ts +5 -9
- package/src/agents/__tests__/AgentWalletRegistry.test.ts +5 -4
- package/src/agents/__tests__/CrossRealityHandoff.test.ts +9 -3
- package/src/agents/__tests__/DelegationTraceHooks.test.ts +390 -0
- package/src/agents/__tests__/TaskDelegationService.test.ts +4 -2
- package/src/agents/spatial-comms/Layer1RealTime.ts +36 -19
- package/src/agents/spatial-comms/Layer2A2A.ts +1 -3
- package/src/agents/spatial-comms/Layer3MCP.ts +13 -4
- package/src/agents/spatial-comms/ProtocolTypes.ts +5 -2
- package/src/agents/spatial-comms/examples/multi-agent-world-creation.ts +2 -2
- package/src/ai/HoloScriptGenerator.ts +2 -2
- package/src/ai/__tests__/PerceptionSystem.prod.test.ts +1 -1
- package/src/ai/__tests__/PerceptionSystem.test.ts +14 -14
- package/src/ai/__tests__/SteeringBehaviors.prod.test.ts +1 -1
- package/src/ai/index.ts +5 -1
- package/src/board/audit.ts +17 -6
- package/src/board/board-ops.ts +45 -15
- package/src/board/board-types.ts +94 -20
- package/src/delegation.ts +5 -3
- package/src/distributed-claimer.ts +13 -2
- package/src/economy/BountyManager.ts +40 -18
- package/src/economy/KnowledgeMarketplace.ts +27 -8
- package/src/economy/PaymentWebhookService.ts +0 -1
- package/src/economy/RevenueSplitter.ts +2 -4
- package/src/economy/UnifiedBudgetOptimizer.ts +8 -9
- package/src/economy/_core-stubs.ts +1 -1
- package/src/economy/x402-facilitator.ts +17 -8
- package/src/index.ts +16 -12
- package/src/knowledge/__tests__/knowledge-consolidator.test.ts +138 -89
- package/src/knowledge/__tests__/knowledge-store-vector.test.ts +59 -16
- package/src/knowledge/brain.ts +7 -7
- package/src/knowledge/consolidation.ts +16 -16
- package/src/knowledge/knowledge-consolidator.ts +60 -30
- package/src/knowledge/knowledge-store.ts +83 -45
- package/src/learning/ProceduralCompiler.ts +6 -1
- package/src/learning/learning/MemoryConsolidator.ts +102 -0
- package/src/learning/learning/MemoryScorer.ts +69 -0
- package/src/learning/learning/ProceduralCompiler.ts +45 -0
- package/src/learning/learning/SemanticClusterer.ts +66 -0
- package/src/llm/llm-adapter.ts +24 -10
- package/src/mesh/index.ts +37 -17
- package/src/protocol/goal-synthesizer.ts +24 -34
- package/src/protocol/implementations.ts +91 -22
- package/src/protocol/micro-phase-decomposer.ts +25 -17
- package/src/protocol/micro-step-decomposer.test.ts +104 -39
- package/src/protocol-agent.test.ts +17 -7
- package/src/protocol-agent.ts +45 -42
- package/src/self-improve/absorb-scanner.ts +9 -6
- package/src/self-improve/evolution-engine.ts +36 -18
- package/src/self-improve/framework-absorber.ts +21 -16
- package/src/self-improve/index.ts +2 -10
- package/src/self-improve/prompt-optimizer.ts +31 -19
- package/src/self-improve/test-generator.ts +16 -12
- package/src/skill-router.ts +7 -6
- package/src/swarm/messaging/GossipProtocol.ts +1 -1
- package/src/swarm/messaging/__tests__/BroadcastChannel.prod.test.ts +31 -9
- package/src/swarm/messaging/__tests__/GossipProtocol.prod.test.ts +21 -7
- package/src/swarm/messaging/__tests__/SwarmEventBus.prod.test.ts +24 -8
- package/src/swarm/messaging/__tests__/SwarmEventBus.test.ts +6 -2
- package/src/team.ts +277 -122
- package/src/training/scripts/generate-spatial-dataset.ts +1 -1
- package/src/training/training/LRScheduler.ts +377 -0
- package/src/training/training/QualityScoringPipeline.ts +139 -0
- package/src/training/training/SoftDedup.ts +461 -0
- package/src/training/training/SparsityMonitor.ts +685 -0
- package/src/training/training/SparsityMonitorTypes.ts +209 -0
- package/src/training/training/SpatialTrainingDataGenerator.ts +1526 -0
- package/src/training/training/SpatialTrainingDataTypes.ts +216 -0
- package/src/training/training/TrainingPipelineConfig.ts +215 -0
- package/src/training/training/__tests__/CorpusValidation.test.ts +87 -0
- package/src/training/training/__tests__/LRScheduler.test.ts +592 -0
- package/src/training/training/__tests__/SoftDedup.test.ts +415 -0
- package/src/training/training/__tests__/SparsityMonitor.test.ts +1623 -0
- package/src/training/training/__tests__/SpatialCorpusValidation.test.ts +72 -0
- package/src/training/training/__tests__/SpatialTrainingDataGenerator.test.ts +1244 -0
- package/src/training/training/__tests__/TrainingMonkeyIntegration.test.ts +897 -0
- package/src/training/training/__tests__/TrainingPipelineConfig.test.ts +202 -0
- package/src/training/training/__tests__/schema.test.ts +72 -0
- package/src/training/training/__tests__/training-constants.test.ts +106 -0
- package/src/training/training/__tests__/trait-mappings.test.ts +81 -0
- package/src/training/training/constants.ts +94 -0
- package/src/training/training/index.ts +17 -0
- package/src/training/training/schema.ts +147 -0
- package/src/training/training/scripts/generate-novel-use-cases-dataset.ts +272 -0
- package/src/training/training/scripts/generate-spatial-dataset.ts +521 -0
- package/src/training/training/trainingmonkey/TrainingMonkeyIntegration.ts +477 -0
- package/src/training/training/trainingmonkey/TrainingMonkeyTypes.ts +230 -0
- package/src/training/training/trainingmonkey/index.ts +26 -0
- package/src/training/training/trait-mappings.ts +157 -0
- package/src/types.ts +2 -7
- package/ALL-test-results.json +0 -1
- package/LICENSE +0 -21
- package/dist/AgentManifest-CB4xM-Ma.d.ts +0 -704
- package/dist/BehaviorTree-BrBFECv5.d.ts +0 -103
- package/dist/InvisibleWallet-rtRrBOA8.d.ts +0 -1732
- package/dist/OrchestratorAgent-Q_CbVTmO.d.ts +0 -798
- package/dist/agents/index.d.ts +0 -1788
- package/dist/agents/index.js +0 -4695
- package/dist/ai/index.d.ts +0 -1753
- package/dist/ai/index.js +0 -5244
- package/dist/behavior.d.ts +0 -130
- package/dist/behavior.js +0 -407
- package/dist/economy/index.d.ts +0 -747
- package/dist/economy/index.js +0 -3617
- package/dist/implementations-D9T3un9D.d.ts +0 -236
- package/dist/index.d.ts +0 -1729
- package/dist/index.js +0 -24277
- package/dist/learning/index.d.ts +0 -104
- package/dist/learning/index.js +0 -189
- package/dist/negotiation/index.d.ts +0 -610
- package/dist/negotiation/index.js +0 -931
- package/dist/skills/index.d.ts +0 -289
- package/dist/skills/index.js +0 -1079
- package/dist/swarm/index.d.ts +0 -2433
- package/dist/swarm/index.js +0 -5221
- package/dist/training/index.d.ts +0 -1734
- package/dist/training/index.js +0 -2687
- package/extract-failures.js +0 -10
- package/src/training/training/data/novel-use-cases.jsonl +0 -153
- package/src/training/training/data/spatial-reasoning-10k.jsonl +0 -9354
- package/src/types/core-stubs.d.ts +0 -113
- package/test-output.txt +0 -0
- package/test-result.json +0 -1
- package/tsc-errors.txt +0 -4
- package/tsc_output.txt +0 -0
- package/typescript-errors-2.txt +0 -0
- package/typescript-errors.txt +0 -22
- package/vitest-log-utf8.txt +0 -268
- 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(
|
|
75
|
-
|
|
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(
|
|
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(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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({
|
|
334
|
-
|
|
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(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
|
|
19
|
-
|
|
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
|
-
{
|
|
163
|
-
|
|
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
|
-
{
|
|
222
|
-
|
|
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
|
-
{
|
|
251
|
-
|
|
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(
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
{
|
|
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');
|
package/src/knowledge/brain.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
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,
|
|
78
|
-
rendering: 14 * 24 * 60 * 60 * 1000,
|
|
79
|
-
agents: 7 * 24 * 60 * 60 * 1000,
|
|
80
|
-
compilation: 21 * 24 * 60 * 60 * 1000,
|
|
81
|
-
general: 7 * 24 * 60 * 60 * 1000,
|
|
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))
|
|
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 (
|
|
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(
|
|
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. */
|