mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Clean up and enhance memory plugin (#151)
* refactor storage to use worker-based vector operations * update memory service and agent implementations * update opencode plugin sdk * update memory plugin documentation * add tests for memory service and injection hook * update lockfile for dependency changes * Add memory plugin v0.0.13 with message deduplication and config UI * Remove planning state feature from memory plugin
This commit is contained in:
1 parent
47ef830cbb
commit
6ef68774d8
53 files changed
+1683
-1885
No files matched your search
@@ -1,13 +1,11 @@
|
||||
import { describe, test, expect } from 'bun:test'
|
||||
import {
|
||||
buildCustomCompactionPrompt,
|
||||
formatPlanningState,
|
||||
formatCompactionDiagnostics,
|
||||
estimateTokens,
|
||||
trimToTokenBudget,
|
||||
extractCompactionSummary,
|
||||
} from '../src/hooks/compaction-utils'
|
||||
import type { PlanningState } from '../src/types'
|
||||
|
||||
describe('buildCustomCompactionPrompt', () => {
|
||||
test('returns a non-empty string', () => {
|
||||
@@ -21,82 +19,15 @@ describe('buildCustomCompactionPrompt', () => {
|
||||
const prompt = buildCustomCompactionPrompt()
|
||||
expect(prompt).toContain('## CRITICAL - Preserve These Verbatim')
|
||||
expect(prompt).toContain('### Active Task')
|
||||
expect(prompt).toContain('### Planning State')
|
||||
expect(prompt).toContain('### Key Context')
|
||||
expect(prompt).toContain('### Active Files')
|
||||
expect(prompt).toContain('### Next Steps')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatPlanningState', () => {
|
||||
test('returns null for null input', () => {
|
||||
const result = formatPlanningState(null)
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
|
||||
test('formats basic planning state', () => {
|
||||
const planningState: PlanningState = {
|
||||
objective: 'Implement feature X',
|
||||
current: 'Writing code',
|
||||
next: 'Run tests',
|
||||
}
|
||||
|
||||
const result = formatPlanningState(planningState)
|
||||
|
||||
expect(result).toContain('**Objective:** Implement feature X')
|
||||
expect(result).toContain('**Current:** Writing code')
|
||||
expect(result).toContain('**Next:** Run tests')
|
||||
})
|
||||
|
||||
test('formats phases with status', () => {
|
||||
const planningState: PlanningState = {
|
||||
objective: 'Test',
|
||||
phases: [
|
||||
{ title: 'Phase 1', status: 'completed', notes: 'Done' },
|
||||
{ title: 'Phase 2', status: 'in_progress' },
|
||||
{ title: 'Phase 3', status: 'pending' },
|
||||
],
|
||||
}
|
||||
|
||||
const result = formatPlanningState(planningState)
|
||||
|
||||
expect(result).toContain('### Phases:')
|
||||
expect(result).toContain('[x] Phase 1 - Done')
|
||||
expect(result).toContain('[~] Phase 2')
|
||||
expect(result).toContain('[ ] Phase 3')
|
||||
})
|
||||
|
||||
test('formats findings', () => {
|
||||
const planningState: PlanningState = {
|
||||
objective: 'Test',
|
||||
findings: ['Found bug A', 'Performance issue'],
|
||||
}
|
||||
|
||||
const result = formatPlanningState(planningState)
|
||||
|
||||
expect(result).toContain('### Key Findings:')
|
||||
expect(result).toContain('- Found bug A')
|
||||
expect(result).toContain('- Performance issue')
|
||||
})
|
||||
|
||||
test('formats errors to avoid', () => {
|
||||
const planningState: PlanningState = {
|
||||
objective: 'Test',
|
||||
errors: ['Memory leak', 'Race condition'],
|
||||
}
|
||||
|
||||
const result = formatPlanningState(planningState)
|
||||
|
||||
expect(result).toContain('### Errors to Avoid:')
|
||||
expect(result).toContain('- Memory leak')
|
||||
expect(result).toContain('- Race condition')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatCompactionDiagnostics', () => {
|
||||
test('returns empty string for zero counts', () => {
|
||||
const result = formatCompactionDiagnostics({
|
||||
planningPhases: 0,
|
||||
conventions: 0,
|
||||
decisions: 0,
|
||||
tokensInjected: 0,
|
||||
@@ -106,23 +37,20 @@ describe('formatCompactionDiagnostics', () => {
|
||||
|
||||
test('formats single items correctly', () => {
|
||||
const result = formatCompactionDiagnostics({
|
||||
planningPhases: 1,
|
||||
conventions: 0,
|
||||
conventions: 1,
|
||||
decisions: 0,
|
||||
tokensInjected: 100,
|
||||
})
|
||||
expect(result).toContain('1 planning phase')
|
||||
expect(result).toContain('1 convention')
|
||||
expect(result).toContain('~100 tokens injected')
|
||||
})
|
||||
|
||||
test('formats multiple items correctly', () => {
|
||||
const result = formatCompactionDiagnostics({
|
||||
planningPhases: 3,
|
||||
conventions: 5,
|
||||
decisions: 2,
|
||||
tokensInjected: 800,
|
||||
})
|
||||
expect(result).toContain('3 planning phases')
|
||||
expect(result).toContain('5 conventions')
|
||||
expect(result).toContain('2 decisions')
|
||||
expect(result).toContain('~800 tokens injected')
|
||||
@@ -215,6 +143,3 @@ describe('extractCompactionSummary', () => {
|
||||
expect(result).toBe('Latest summary')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user