-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.py
More file actions
93 lines (60 loc) · 1.88 KB
/
buffer.py
File metadata and controls
93 lines (60 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
buffer.py
Acts as TEMPORARY MEMORY before committing to GitHub.
Supports THREE channels:
✔ daily
✔ achievement
✔ failure
Design Goal:
- Safe
- Structured
- AI-friendly
"""
import os
from datetime import datetime
from config import BUFFER_FILE
# Ensure buffer exists
if not os.path.exists(BUFFER_FILE):
open(BUFFER_FILE, "w", encoding="utf-8").close()
def build_log_line(category: str, message: str):
"""
Creates a structured log entry.
Format (AI friendly):
ISO_TIMESTAMP || CATEGORY || MESSAGE
"""
timestamp = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
return f"{timestamp} || {category} || {message}\n"
def add_daily_log(message: str):
"""Adds a normal daily entry."""
if not message.strip():
return
log_line = build_log_line("DAILY", message)
with open(BUFFER_FILE, "a", encoding="utf-8") as file:
file.write(log_line)
def add_achievement(title: str, description: str, how: str):
"""
Adds a rich achievement entry.
Stored in one line for AI parsing.
"""
combined = f"{title} >> {description} >> HOW:{how}"
log_line = build_log_line("ACHIEVEMENT", combined)
with open(BUFFER_FILE, "a", encoding="utf-8") as file:
file.write(log_line)
def add_failure(title: str, reason: str, lesson: str):
"""
Logs failures with learning data.
This becomes EXTREMELY valuable later.
"""
combined = f"{title} >> {reason} >> LESSON:{lesson}"
log_line = build_log_line("FAILURE", combined)
with open(BUFFER_FILE, "a", encoding="utf-8") as file:
file.write(log_line)
def read_buffer():
try:
with open(BUFFER_FILE, "r", encoding="utf-8") as file:
return file.read()
except FileNotFoundError:
return ""
def clear_buffer():
"""Clears buffer AFTER successful commit."""
open(BUFFER_FILE, "w", encoding="utf-8").close()