Skip to content

Commit ce8fc8c

Browse files
committed
feat: enhanced memory system with yaad deep integration
- EnhancedMemoryManager: unified facade for all memory subsystems - Auto-capture: extracts memories from tool results (Write, Bash, Read) - Proactive context: injects file-relevant memories without explicit recall - Confidence tracker: boosts/penalizes from session outcomes - Retrieval metrics: tracks hit rate, tokens saved, auto-persists - Code-memory links: graph edges between code chunks and memories - Session diff: git-based memory extraction at session end - Continuity score: measures memory effectiveness (0-100) - Cross-project: global preferences transfer across projects - Shared memory: real-time agent-to-agent for mission mode - Graph-aware budget: priority-based context allocation - Wired into engine/stream.go agent loop (post-tool + session-end) - All ecosystem deps pinned to v0.1.0
1 parent f54d37d commit ce8fc8c

20 files changed

Lines changed: 3249 additions & 13 deletions

‎cmd/options.go‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"os"
99
"strings"
10+
"time"
1011

1112
hawkconfig "github.com/GrayCodeAI/hawk/config"
1213
"github.com/GrayCodeAI/hawk/engine"
@@ -172,11 +173,13 @@ func configureSession(sess *engine.Session, settings hawkconfig.Settings) error
172173
sess.Snapshots = snap
173174
}
174175

175-
// Initialize yaad memory bridge
176-
yaadMem := memory.NewYaadBridge()
177-
if yaadMem.Ready() {
178-
sess.Memory = yaadMem
179-
sess.YaadBridge = yaadMem
176+
// Initialize enhanced memory system (yaad bridge + auto-capture + proactive + metrics)
177+
enhancedMem := memory.NewEnhancedMemoryManager(cwd)
178+
if enhancedMem.Yaad.Ready() {
179+
sess.Memory = enhancedMem
180+
sess.YaadBridge = enhancedMem.Yaad
181+
sess.EnhancedMemory = enhancedMem
182+
enhancedMem.StartSession(fmt.Sprintf("session_%d", time.Now().UnixNano()))
180183
}
181184
// Herm-style: API keys from environment only
182185
normalizedProvider := hawkconfig.NormalizeProviderForEngine(settings.Provider)

‎engine/session.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ type Session struct {
5353
PermissionFn func(PermissionRequest) // use Perm.PromptFn
5454
AgentSpawnFn func(ctx context.Context, prompt string) (string, error)
5555
AskUserFn func(question string) (string, error)
56-
Memory MemoryRecaller
57-
YaadBridge *memory.YaadBridge
56+
Memory MemoryRecaller
57+
YaadBridge *memory.YaadBridge
58+
EnhancedMemory *memory.EnhancedMemoryManager
5859

5960
PinnedMessages int // messages to protect from compaction (from /pin)
6061
AutoCompactThresholdPct int // token % to trigger auto-compact (default 85)

‎engine/stream.go‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ func (s *Session) agentLoop(ctx context.Context, ch chan<- StreamEvent) {
3838

3939
// Self-improvement: run OnSessionEnd when the loop exits (regardless of how)
4040
defer func() {
41+
success := ctx.Err() == nil
4142
if s.Lifecycle != nil {
4243
outcome := SessionOutcome{
43-
Success: ctx.Err() == nil,
44+
Success: success,
4445
Duration: time.Since(sessionStart),
4546
}
4647
if len(s.messages) > 0 {
@@ -52,6 +53,10 @@ func (s *Session) agentLoop(ctx context.Context, ch chan<- StreamEvent) {
5253
}
5354
_ = s.Lifecycle.OnSessionEnd(ctx, s, outcome)
5455
}
56+
// Enhanced memory: session-end processing (confidence, diff, continuity)
57+
if s.EnhancedMemory != nil {
58+
s.EnhancedMemory.EndSession(success)
59+
}
5560
}()
5661

5762
// Session start hook
@@ -655,6 +660,15 @@ func (s *Session) agentLoop(ctx context.Context, ch chan<- StreamEvent) {
655660
s.Beliefs.Record("file_purpose", subject, contentSummary, turnCount)
656661
}
657662

663+
// Proactive context: inject relevant memories when reading files
664+
if s.EnhancedMemory != nil && (canonical == "Read" || canonical == "Edit" || canonical == "Write") {
665+
if p, ok := pathArgument(tc.Arguments); ok && p != "" {
666+
if proactiveCtx := s.EnhancedMemory.ProactiveContextForFile(p); proactiveCtx != "" {
667+
s.AppendSystemContext(proactiveCtx)
668+
}
669+
}
670+
}
671+
658672
// Beliefs: invalidate beliefs when files are modified
659673
if s.Beliefs != nil && (canonical == "Write" || canonical == "Edit") {
660674
if p, ok := pathArgument(tc.Arguments); ok {
@@ -738,6 +752,11 @@ func (s *Session) agentLoop(ctx context.Context, ch chan<- StreamEvent) {
738752
s.metrics.Counter("tools.errors").Inc()
739753
}
740754

755+
// Enhanced memory: auto-capture from tool results + proactive context
756+
if s.EnhancedMemory != nil {
757+
s.EnhancedMemory.OnToolResult(tc.Name, tc.Arguments, output, isErr)
758+
}
759+
741760
hooks.ExecuteAsync(ctx, hooks.EventPostTool, map[string]interface{}{
742761
"tool": tc.Name,
743762
"output": output,

‎go.mod‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ module github.com/GrayCodeAI/hawk
33
go 1.26.1
44

55
require (
6-
github.com/GrayCodeAI/eyrie v0.5.0
7-
github.com/GrayCodeAI/inspect v0.5.0
8-
github.com/GrayCodeAI/sight v0.5.0
9-
github.com/GrayCodeAI/tok v0.5.1
10-
github.com/GrayCodeAI/yaad v0.5.0
6+
github.com/GrayCodeAI/eyrie v0.1.0
7+
github.com/GrayCodeAI/inspect v0.1.0
8+
github.com/GrayCodeAI/sight v0.1.0
9+
github.com/GrayCodeAI/tok v0.1.0
10+
github.com/GrayCodeAI/yaad v0.1.0
1111
github.com/charmbracelet/bubbles v1.0.0
1212
github.com/charmbracelet/bubbletea v1.3.10
1313
github.com/charmbracelet/lipgloss v1.1.0

0 commit comments

Comments
 (0)