1
0
Fork 0
mirror of https://github.com/imjasonh/cnotes synced 2026-07-10 09:54:26 +00:00

Fix duplicate content in git notes by filtering since last commit

- Add ExtractContextSince method to filter conversation by timestamp
- Get previous commit time and only include activity since then
- Change labels to 'User prompts since last commit' and 'Tool interactions since last commit'
- Each commit now only captures its own unique conversation context
- Prevents accumulation of duplicate content across commits in same session
This commit is contained in:
Jason Hall 2025-07-21 13:38:30 -04:00
parent 6b338a76be
commit a6e6602bf8
Failed to extract signature
2 changed files with 55 additions and 16 deletions

View file

@ -7,6 +7,7 @@ import (
"io"
"log/slog"
"os"
"os/exec"
"strings"
"time"
@ -141,9 +142,12 @@ func processGitCommit(ctx context.Context, input HookInput, bashInput BashToolIn
return nil
}
// Extract conversation context
// Get the timestamp of the previous commit in this session
previousCommitTime := getLastCommitTimeForSession(ctx, notesManager, input.SessionID)
// Extract conversation context since the last commit
contextExtractor := conv.NewContextExtractor()
conversationContext, err := contextExtractor.ExtractRecentContext(input.TranscriptPath, input.SessionID)
conversationContext, err := contextExtractor.ExtractContextSince(input.TranscriptPath, input.SessionID, previousCommitTime)
if err != nil {
return fmt.Errorf("failed to extract conversation context: %w", err)
}
@ -238,6 +242,27 @@ func contains(slice []string, item string) bool {
return false
}
// getLastCommitTimeForSession finds the most recent commit time for this session
func getLastCommitTimeForSession(ctx context.Context, notesManager *notes.NotesManager, sessionID string) time.Time {
// For now, let's use a simpler approach - get the time of the previous commit
// This works well when commits are made sequentially in a session
cmd := exec.Command("git", "log", "-1", "--format=%cI", "HEAD~1")
output, err := cmd.Output()
if err != nil {
// No previous commit or error, return zero time
return time.Time{}
}
timeStr := strings.TrimSpace(string(output))
commitTime, err := time.Parse(time.RFC3339, timeStr)
if err != nil {
return time.Time{}
}
// Add a small buffer to ensure we don't miss events that happened right at commit time
return commitTime.Add(-5 * time.Second)
}
// readStdinWithTimeout reads from stdin with a timeout
func readStdinWithTimeout(timeout time.Duration) ([]byte, error) {
type result struct {