MCPcopy Create free account
hub / github.com/JordanCoin/codemap / getLastSessionEvents

Function getLastSessionEvents

cmd/hooks.go:472–524  ·  view source on GitHub ↗

getLastSessionEvents reads events.log for previous session context

(root string)

Source from the content-addressed store, hash-verified

470
471// getLastSessionEvents reads events.log for previous session context
472func getLastSessionEvents(root string) []string {
473 eventsFile := filepath.Join(root, ".codemap", "events.log")
474 f, err := os.Open(eventsFile)
475 if err != nil {
476 return nil
477 }
478 defer f.Close()
479
480 info, err := f.Stat()
481 if err != nil || info.Size() == 0 {
482 return nil
483 }
484
485 readBytes := info.Size()
486 maxTail := int64(limits.MaxEventLogReadBytes)
487 if maxTail > 0 && readBytes > maxTail {
488 readBytes = maxTail
489 }
490 if readBytes <= 0 {
491 return nil
492 }
493 start := info.Size() - readBytes
494
495 buf := make([]byte, int(readBytes))
496 n, err := f.ReadAt(buf, start)
497 if err != nil && err != io.EOF {
498 return nil
499 }
500 if n == 0 {
501 return nil
502 }
503
504 text := string(buf[:n])
505 if start > 0 {
506 if idx := strings.IndexByte(text, '\n'); idx >= 0 && idx+1 < len(text) {
507 text = text[idx+1:]
508 }
509 }
510
511 lines := strings.Split(text, "\n")
512 if len(lines) == 0 {
513 return nil
514 }
515
516 // Get last 20 non-empty lines
517 var recent []string
518 for i := len(lines) - 1; i >= 0 && len(recent) < 20; i-- {
519 if strings.TrimSpace(lines[i]) != "" {
520 recent = append([]string{lines[i]}, recent...)
521 }
522 }
523 return recent
524}
525
526// showLastSessionContext displays what was worked on in previous session
527func showLastSessionContext(root string, events []string) {

Callers 2

TestGetLastSessionEventsFunction · 0.85
hookSessionStartFunction · 0.85

Calls 2

CloseMethod · 0.80
SizeMethod · 0.80

Tested by 1

TestGetLastSessionEventsFunction · 0.68