Files
Agent-System/internal/supplementimpact/mem_store.go
T
weichen 4e0e6a1418 feat(notification): digest aggregates, supplement-impact batch, and free-collab hooks
Add notification digests with ON CONFLICT DO UPDATE, migrations 00068-00070,
supplementimpact module (analyze → confirm → claim-aware split), and wire
coordinator/mutate hooks plus proposal_required digests.
2026-09-24 11:44:20 +00:00

75 lines
1.6 KiB
Go

package supplementimpact
import (
"context"
"fmt"
"sync"
)
type MemStore struct {
mu sync.Mutex
batches map[string]*Batch
}
func NewMemStore() *MemStore {
return &MemStore{batches: map[string]*Batch{}}
}
func (m *MemStore) InsertBatch(_ context.Context, b *Batch) error {
m.mu.Lock()
defer m.mu.Unlock()
cp := *b
cp.Items = append([]Item{}, b.Items...)
m.batches[b.BatchID] = &cp
return nil
}
func (m *MemStore) GetBatch(_ context.Context, batchID string) (*Batch, error) {
m.mu.Lock()
defer m.mu.Unlock()
b, ok := m.batches[batchID]
if !ok {
return nil, fmt.Errorf("supplementimpact: batch not found")
}
cp := *b
cp.Items = append([]Item{}, b.Items...)
return &cp, nil
}
func (m *MemStore) SaveDecision(_ context.Context, batchID string, revision int64, nonce, digest, status string, selected map[string]bool) error {
m.mu.Lock()
defer m.mu.Unlock()
b, ok := m.batches[batchID]
if !ok {
return fmt.Errorf("supplementimpact: batch not found")
}
b.Status = status
b.DecisionNonce = nonce
b.DecisionDigest = digest
b.Revision = revision
for i := range b.Items {
if selected != nil {
b.Items[i].Selected = selected[b.Items[i].DocID]
}
}
return nil
}
func (m *MemStore) UpdateItemOutcome(_ context.Context, batchID, docID, outcome, proposalID, runID string) error {
m.mu.Lock()
defer m.mu.Unlock()
b, ok := m.batches[batchID]
if !ok {
return fmt.Errorf("supplementimpact: batch not found")
}
for i := range b.Items {
if b.Items[i].DocID == docID {
b.Items[i].Outcome = outcome
b.Items[i].ProposalID = proposalID
b.Items[i].RunID = runID
return nil
}
}
return fmt.Errorf("supplementimpact: item not found")
}