forked from Rockachopa/Timmy-time-dashboard
feat: code quality audit + autoresearch integration + infra hardening (#150)
This commit is contained in:
committed by
GitHub
parent
fd0ede0d51
commit
ae3bb1cc21
@@ -28,25 +28,27 @@ IMPORTANCE_HIGH = 0.8
|
||||
@dataclass
|
||||
class SparkEvent:
|
||||
"""A single captured swarm event."""
|
||||
|
||||
id: str
|
||||
event_type: str # task_posted, bid, assignment, completion, failure
|
||||
event_type: str # task_posted, bid, assignment, completion, failure
|
||||
agent_id: Optional[str]
|
||||
task_id: Optional[str]
|
||||
description: str
|
||||
data: str # JSON payload
|
||||
importance: float # 0.0–1.0
|
||||
data: str # JSON payload
|
||||
importance: float # 0.0–1.0
|
||||
created_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class SparkMemory:
|
||||
"""A consolidated memory distilled from event patterns."""
|
||||
|
||||
id: str
|
||||
memory_type: str # pattern, insight, anomaly
|
||||
subject: str # agent_id or "system"
|
||||
content: str # Human-readable insight
|
||||
confidence: float # 0.0–1.0
|
||||
source_events: int # How many events contributed
|
||||
memory_type: str # pattern, insight, anomaly
|
||||
subject: str # agent_id or "system"
|
||||
content: str # Human-readable insight
|
||||
confidence: float # 0.0–1.0
|
||||
source_events: int # How many events contributed
|
||||
created_at: str
|
||||
expires_at: Optional[str]
|
||||
|
||||
@@ -83,24 +85,17 @@ def _get_conn() -> sqlite3.Connection:
|
||||
)
|
||||
"""
|
||||
)
|
||||
conn.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_events_type ON spark_events(event_type)"
|
||||
)
|
||||
conn.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_events_agent ON spark_events(agent_id)"
|
||||
)
|
||||
conn.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_events_task ON spark_events(task_id)"
|
||||
)
|
||||
conn.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_memories_subject ON spark_memories(subject)"
|
||||
)
|
||||
conn.execute("CREATE INDEX IF NOT EXISTS idx_events_type ON spark_events(event_type)")
|
||||
conn.execute("CREATE INDEX IF NOT EXISTS idx_events_agent ON spark_events(agent_id)")
|
||||
conn.execute("CREATE INDEX IF NOT EXISTS idx_events_task ON spark_events(task_id)")
|
||||
conn.execute("CREATE INDEX IF NOT EXISTS idx_memories_subject ON spark_memories(subject)")
|
||||
conn.commit()
|
||||
return conn
|
||||
|
||||
|
||||
# ── Importance scoring ──────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def score_importance(event_type: str, data: dict) -> float:
|
||||
"""Compute importance score for an event (0.0–1.0).
|
||||
|
||||
@@ -132,6 +127,7 @@ def score_importance(event_type: str, data: dict) -> float:
|
||||
|
||||
# ── Event recording ─────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def record_event(
|
||||
event_type: str,
|
||||
description: str,
|
||||
@@ -142,6 +138,7 @@ def record_event(
|
||||
) -> str:
|
||||
"""Record a swarm event. Returns the event id."""
|
||||
import json
|
||||
|
||||
event_id = str(uuid.uuid4())
|
||||
now = datetime.now(timezone.utc).isoformat()
|
||||
|
||||
@@ -224,6 +221,7 @@ def count_events(event_type: Optional[str] = None) -> int:
|
||||
|
||||
# ── Memory consolidation ───────────────────────────────────────────────────
|
||||
|
||||
|
||||
def store_memory(
|
||||
memory_type: str,
|
||||
subject: str,
|
||||
|
||||
Reference in New Issue
Block a user