Feature/memory pr (#889)

* feat: multi-turn context and conversation arc memory

PR 2E - Section 2.9, 2.10:
- Add multiTurnContext.ts with turn tracking and state preservation
- Add conversationArc.ts with goal/decision/milestone tracking
- Wire into query.ts after tool execution
- Feature-flags: MULTI_TURN_CONTEXT, CONVERSATION_ARC
- Add comprehensive tests (22 passing)

* feat(memory): resolve review blockers and integrate native Knowledge Graph into Conversation Arcs

- Fix: Extract text from production block arrays in phase detector\n- Fix: Ensure proper turn segmentation in query loop\n- Fix: Respect options in multi-turn context tracker\n- Feat: Add native Knowledge Graph (Entities/Relations) to ConversationArc architecture\n- Test: Comprehensive test suite for all fixes and new graph features

* test(perf): add automated performance benchmarks for Knowledge Graph extraction and summary

---------

Co-authored-by: LifeJiggy <Bloomtonjovish@gmail.com>
This commit is contained in:
3kin0x
2026-04-24 20:26:02 +02:00
committed by GitHub
parent 64b1014b9a
commit b5f7047358
6 changed files with 933 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
import { describe, expect, it, beforeEach } from 'bun:test'
import {
initializeArc,
updateArcPhase,
getArcSummary,
resetArc
} from './conversationArc.js'
function createMessage(content: string): any {
return {
message: { role: 'user', content, id: 'test', type: 'message', created_at: Date.now() },
sender: 'user',
}
}
describe('Conversation Arc Performance Benchmarks', () => {
beforeEach(() => {
resetArc()
initializeArc()
})
it('performs automatic fact extraction in sub-millisecond time', () => {
const iterations = 100
const complexContent = 'Deploying version v1.2.3 to /opt/prod/server on https://api.prod.local with JIRA_URL=https://jira.corp'
const startTime = performance.now()
for (let i = 0; i < iterations; i++) {
updateArcPhase([createMessage(complexContent)])
}
const duration = performance.now() - startTime
const averageTime = duration / iterations
console.log(`[Benchmark] Avg extraction time: ${averageTime.toFixed(4)}ms`)
// Performance guard: should definitely be under 0.5ms per message on any modern CI
expect(averageTime).toBeLessThan(0.5)
})
it('generates summaries quickly even with a populated graph', () => {
// Populate graph with 50 facts
for (let i = 0; i < 50; i++) {
updateArcPhase([createMessage(`Var_${i}=Value_${i} in /path/to/file_${i}`)])
}
const startTime = performance.now()
const summary = getArcSummary()
const duration = performance.now() - startTime
console.log(`[Benchmark] Summary generation time (50 entities): ${duration.toFixed(4)}ms`)
expect(summary).toContain('Knowledge Graph:')
// Summary generation should be extremely fast
expect(duration).toBeLessThan(10)
})
it('maintains a compact memory footprint', () => {
const arc = initializeArc()
for (let i = 0; i < 100; i++) {
updateArcPhase([createMessage(`Fact_${i}=Value_${i}`)])
}
const serialized = JSON.stringify(arc)
const sizeKB = serialized.length / 1024
console.log(`[Benchmark] Memory footprint (100 facts): ${sizeKB.toFixed(2)}KB`)
// Should be well under 100KB for 100 simple facts
expect(sizeKB).toBeLessThan(100)
})
})