fix(core): Address code review from Issue #1
This commit is contained in:
1 parent
5d9df6649a
commit
6061f5c4e5
28 files changed
+205
-56
No files matched your search
+6
-5
@@ -23,6 +23,7 @@ import signal
|
||||
import sys
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
@@ -62,7 +63,7 @@ async def health_check() -> Dict[str, Any]:
|
||||
if _engine_components is None:
|
||||
return {
|
||||
"status": "not_ready",
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"coherence": None,
|
||||
"master_coherence": None,
|
||||
"emissary_coherence": None,
|
||||
@@ -81,7 +82,7 @@ async def health_check() -> Dict[str, Any]:
|
||||
|
||||
return {
|
||||
"status": "ready",
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"coherence": float(sync_coherence) if sync_coherence else None,
|
||||
"master_coherence": float(master_coherence) if master_coherence else None,
|
||||
"emissary_coherence": float(emissary_coherence) if emissary_coherence else None,
|
||||
@@ -126,7 +127,7 @@ async def process_input(input_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"coherence": float(result.get("coherence", 0)) if isinstance(result, dict) else None,
|
||||
"phase": str(result.get("phase", "")) if isinstance(result, dict) else None,
|
||||
"collapsed": result.get("collapsed", False) if isinstance(result, dict) else False,
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +168,7 @@ async def get_coherence() -> Dict[str, Any]:
|
||||
"coherence": float(sync.synchronized_coherence) if sync else None,
|
||||
"aligned": sync.aligned if sync else None,
|
||||
},
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +180,7 @@ async def reset_engine() -> Dict[str, Any]:
|
||||
|
||||
return {
|
||||
"status": "reset",
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"message": "Engine reset to initial state",
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ Author: Solaria Lumis Havens
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from typing import Optional, Callable
|
||||
import math
|
||||
import numpy as np
|
||||
@@ -329,7 +330,7 @@ class CollapseCondition:
|
||||
"""How long we've been collapsed."""
|
||||
if self._collapse_timestamp is None:
|
||||
return 0.0
|
||||
return (datetime.utcnow() - self._collapse_timestamp).total_seconds()
|
||||
return (datetime.now(timezone.utc) - self._collapse_timestamp).total_seconds()
|
||||
|
||||
def evaluate(self, coherence: float) -> tuple[bool, str]:
|
||||
"""
|
||||
@@ -356,7 +357,7 @@ class CollapseCondition:
|
||||
# Check for initial collapse
|
||||
if coherence >= self.threshold:
|
||||
self._collapsed = True
|
||||
self._collapse_timestamp = datetime.utcnow()
|
||||
self._collapse_timestamp = datetime.now(timezone.utc)
|
||||
self._collapse_coherence = coherence
|
||||
logger.info(
|
||||
f"[{self.name}] COHERENCE COLLAPSE at {self._collapse_timestamp.isoformat()}"
|
||||
@@ -373,7 +374,7 @@ class CollapseCondition:
|
||||
coherence: Coherence level (current if None)
|
||||
"""
|
||||
self._collapsed = True
|
||||
self._collapse_timestamp = datetime.utcnow()
|
||||
self._collapse_timestamp = datetime.now(timezone.utc)
|
||||
self._collapse_coherence = coherence or self.threshold
|
||||
logger.info(f"[{self.name}] Force collapsed at {self._collapse_timestamp.isoformat()}")
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ Author: Solaria Lumis Havens
|
||||
import asyncio
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from enum import Enum
|
||||
from typing import Any, Optional, Union
|
||||
import logging
|
||||
@@ -152,7 +153,7 @@ class KAIROSTemporalEngine:
|
||||
self._integrator = PhaseIntegrator(self.config.coherence_threshold)
|
||||
|
||||
initial_phase = np.array([complex(1, 0)])
|
||||
now = datetime.utcnow()
|
||||
now = datetime.now(timezone.utc)
|
||||
self._phases.append(initial_phase)
|
||||
self._timestamps.append(now)
|
||||
self._coherence_history.append(0.0)
|
||||
@@ -215,9 +216,9 @@ class KAIROSTemporalEngine:
|
||||
dt = timedelta(seconds=1.0 / self.config.token_frequency)
|
||||
timestamp = self._timestamps[-1] + dt
|
||||
else:
|
||||
timestamp = datetime.utcnow()
|
||||
timestamp = datetime.now(timezone.utc)
|
||||
else:
|
||||
timestamp = timestamp or datetime.utcnow()
|
||||
timestamp = timestamp or datetime.now(timezone.utc)
|
||||
|
||||
metadata = metadata or {}
|
||||
|
||||
@@ -271,7 +272,7 @@ class KAIROSTemporalEngine:
|
||||
self.config.clock_mode = "token_clock"
|
||||
|
||||
states = []
|
||||
current_time = start_time or (self._timestamps[-1] if self._timestamps else datetime.utcnow())
|
||||
current_time = start_time or (self._timestamps[-1] if self._timestamps else datetime.now(timezone.utc))
|
||||
|
||||
from datetime import timedelta
|
||||
dt = timedelta(seconds=1.0 / self.config.token_frequency)
|
||||
@@ -333,7 +334,7 @@ class KAIROSTemporalEngine:
|
||||
self._coherence_history.clear()
|
||||
|
||||
initial_phase = np.array([complex(1, 0)])
|
||||
now = datetime.utcnow()
|
||||
now = datetime.now(timezone.utc)
|
||||
self._phases.append(initial_phase)
|
||||
self._timestamps.append(now)
|
||||
self._coherence_history.append(0.0)
|
||||
|
||||
@@ -21,6 +21,7 @@ Author: Solaria Lumis Havens
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from typing import Optional
|
||||
import math
|
||||
from collections import deque
|
||||
@@ -139,7 +140,7 @@ class PhaseHistory:
|
||||
state = PhaseState(
|
||||
value=phase,
|
||||
angle=angle,
|
||||
timestamp=datetime.utcnow(),
|
||||
timestamp=datetime.now(timezone.utc),
|
||||
source=source
|
||||
)
|
||||
self._phases.append(state)
|
||||
|
||||
@@ -19,6 +19,7 @@ import asyncio
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import httpx
|
||||
@@ -75,7 +76,7 @@ class MasterLLM:
|
||||
"status": "success",
|
||||
"response": data["choices"][0]["message"]["content"],
|
||||
"model": self.model,
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
else:
|
||||
return {"error": f"API error: {response.status_code}"}
|
||||
@@ -120,7 +121,7 @@ class EmissaryLLM:
|
||||
"status": "success",
|
||||
"response": data["message"]["content"],
|
||||
"model": self.model,
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
else:
|
||||
return {"error": f"Ollama error: {response.status_code}"}
|
||||
@@ -169,7 +170,7 @@ class DualPathway:
|
||||
"""
|
||||
results = {
|
||||
"prompt": prompt,
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"pathway": pathway,
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ def get_last_merkle_root(filepath: str = LEDGER_FILE) -> str:
|
||||
if line.strip():
|
||||
try:
|
||||
record = json.loads(line)
|
||||
if "merkle_root" in record:
|
||||
last_root = record["merkle_root"]
|
||||
if "crypto_metadata" in record and "merkle_root" in record["crypto_metadata"]:
|
||||
last_root = record["crypto_metadata"]["merkle_root"]
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
except Exception as e:
|
||||
|
||||
@@ -21,7 +21,7 @@ References:
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Dict, List, Optional, Tuple, Any
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from enum import Enum
|
||||
import math
|
||||
import json
|
||||
@@ -213,7 +213,7 @@ class TemporalMemory:
|
||||
self.temporal_index: List[Tuple[datetime, str]] = [] # (created_at, signature_id)
|
||||
|
||||
# State tracking
|
||||
self.last_consolidation = datetime.utcnow()
|
||||
self.last_consolidation = datetime.now(timezone.utc)
|
||||
self.engine: Optional[KAIROSTemporalEngine] = None
|
||||
self.calculator: Optional[CoherenceCalculator] = None
|
||||
|
||||
@@ -266,7 +266,7 @@ class TemporalMemory:
|
||||
phase_vec = temporal_state.metadata.get("phase_vector", [])
|
||||
|
||||
# Generate unique ID
|
||||
timestamp = datetime.utcnow().isoformat()
|
||||
timestamp = datetime.now(timezone.utc).isoformat()
|
||||
content_hash = hashlib.sha256(
|
||||
f"{phase_vec[-1] if phase_vec else 0}{coherence}{timestamp}".encode()
|
||||
).hexdigest()[:16]
|
||||
@@ -286,8 +286,8 @@ class TemporalMemory:
|
||||
strength=strength,
|
||||
origin=origin,
|
||||
parent_id=parent_id,
|
||||
created_at=datetime.utcnow(),
|
||||
last_accessed=datetime.utcnow(),
|
||||
created_at=datetime.now(timezone.utc),
|
||||
last_accessed=datetime.now(timezone.utc),
|
||||
access_count=0,
|
||||
decay_rate=self.decay_base * (1.0 - coherence * 0.5), # Higher coherence = slower decay
|
||||
content=context
|
||||
@@ -365,7 +365,7 @@ class TemporalMemory:
|
||||
phase_similarity = 0.5
|
||||
|
||||
# Recency score
|
||||
now = datetime.utcnow()
|
||||
now = datetime.now(timezone.utc)
|
||||
hours_ago = (now - signature.last_accessed).total_seconds() / 3600
|
||||
recency_score = 1.0 / (1.0 + hours_ago)
|
||||
|
||||
@@ -411,7 +411,7 @@ class TemporalMemory:
|
||||
|
||||
if results and results[0][1] >= threshold:
|
||||
signature = results[0][0]
|
||||
signature.last_accessed = datetime.utcnow()
|
||||
signature.last_accessed = datetime.now(timezone.utc)
|
||||
signature.access_count += 1
|
||||
return signature
|
||||
|
||||
@@ -430,7 +430,7 @@ class TemporalMemory:
|
||||
Returns:
|
||||
Consolidation report
|
||||
"""
|
||||
now = datetime.utcnow()
|
||||
now = datetime.now(timezone.utc)
|
||||
stats = {
|
||||
"before_count": len(self.signatures),
|
||||
"strengthened": 0,
|
||||
@@ -499,7 +499,7 @@ class TemporalMemory:
|
||||
|
||||
data = {
|
||||
"version": "1.0.0",
|
||||
"saved_at": datetime.utcnow().isoformat(),
|
||||
"saved_at": datetime.now(timezone.utc).isoformat(),
|
||||
"config": {
|
||||
"storage_path": self.storage_path,
|
||||
"max_memories": self.max_memories,
|
||||
@@ -556,7 +556,7 @@ class TemporalMemory:
|
||||
coherence_trace=e.get("coherence_trace", 0.0),
|
||||
phase_similarity=e.get("phase_similarity", 0.0),
|
||||
temporal_offset=e.get("temporal_offset", 0.0),
|
||||
created_at=datetime.fromisoformat(e.get("created_at", datetime.utcnow().isoformat()))
|
||||
created_at=datetime.fromisoformat(e.get("created_at", datetime.now(timezone.utc).isoformat()))
|
||||
)
|
||||
for e in echoes_data
|
||||
]
|
||||
@@ -593,7 +593,7 @@ class TemporalMemory:
|
||||
Returns:
|
||||
List of recent signatures
|
||||
"""
|
||||
cutoff = datetime.utcnow() - timedelta(hours=hours)
|
||||
cutoff = datetime.now(timezone.utc) - timedelta(hours=hours)
|
||||
return [
|
||||
sig for sig in self.signatures.values()
|
||||
if sig.created_at > cutoff
|
||||
@@ -675,7 +675,7 @@ class TemporalMemory:
|
||||
coherence_trace=other_sig.coherence_value * 0.8, # Weakened
|
||||
phase_similarity=phase_match,
|
||||
temporal_offset=(signature.created_at - other_sig.created_at).total_seconds(),
|
||||
created_at=datetime.utcnow()
|
||||
created_at=datetime.now(timezone.utc)
|
||||
)
|
||||
echoes.append(echo)
|
||||
|
||||
@@ -847,6 +847,8 @@ def retrieve_signatures(filepath: str = "memory.jsonl", limit: int = 100) -> Lis
|
||||
break
|
||||
try:
|
||||
data = json.loads(line.strip())
|
||||
if "payload" in data:
|
||||
data = data["payload"]
|
||||
signatures.append(TemporalSignature.from_dict(data))
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
|
||||
@@ -25,6 +25,7 @@ Author: Solaria Lumis Havens
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from typing import Optional, Callable
|
||||
import asyncio
|
||||
import logging
|
||||
@@ -205,7 +206,7 @@ class SynchronizationLayer:
|
||||
)
|
||||
|
||||
if self._collapsed and not was_collapsed:
|
||||
self._collapse_timestamp = datetime.utcnow()
|
||||
self._collapse_timestamp = datetime.now(timezone.utc)
|
||||
logger.info(
|
||||
f"[{self.name}] SYNCHRONIZED COLLAPSE at "
|
||||
f"{self._collapse_timestamp.isoformat()}"
|
||||
@@ -217,7 +218,7 @@ class SynchronizationLayer:
|
||||
# Reject un-coherent input
|
||||
dissipated = True
|
||||
dissipation_record = {
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"phase_difference": self._phase_difference,
|
||||
"master_coherence": master_coherence,
|
||||
"emissary_coherence": emissary_coherence,
|
||||
@@ -237,7 +238,7 @@ class SynchronizationLayer:
|
||||
|
||||
# Record synchronization
|
||||
sync_record = {
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"T_master": T_master,
|
||||
"T_emissary": T_emissary,
|
||||
"T_sync": self._T_sync,
|
||||
@@ -291,7 +292,7 @@ class SynchronizationLayer:
|
||||
return {
|
||||
"layer": self.name,
|
||||
"type": "SYNCHRONIZATION",
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"config": {
|
||||
"phase_threshold": self.config.phase_threshold,
|
||||
"collapse_threshold": self.config.collapse_threshold,
|
||||
|
||||
@@ -23,6 +23,7 @@ Author: Solaria Lumis Havens
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from typing import Optional, Any
|
||||
import asyncio
|
||||
import logging
|
||||
@@ -131,7 +132,7 @@ class EmissaryTransducer:
|
||||
|
||||
# Witnessing
|
||||
self._witness_count = 0
|
||||
self._last_witness = datetime.utcnow()
|
||||
self._last_witness = datetime.now(timezone.utc)
|
||||
|
||||
# Integration and action history
|
||||
self._integrations: deque[dict] = deque(maxlen=10000) # More history
|
||||
@@ -196,7 +197,7 @@ class EmissaryTransducer:
|
||||
>>> print(f"Action: {result['action']}")
|
||||
>>> print(f"Coherence: {result['coherence']:.3f}")
|
||||
"""
|
||||
timestamp = timestamp or datetime.utcnow()
|
||||
timestamp = timestamp or datetime.now(timezone.utc)
|
||||
metadata = metadata or {}
|
||||
|
||||
# Temporalize through KAIROS engine (fast!)
|
||||
@@ -280,7 +281,7 @@ class EmissaryTransducer:
|
||||
"input_length": len(input_phrase),
|
||||
"coherence_level": self._engine.coherence,
|
||||
"phase_angle": float(np.angle(state.phase)),
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"action": f"Emissary response at coherence={self._engine.coherence:.3f}"
|
||||
}
|
||||
|
||||
@@ -306,7 +307,7 @@ class EmissaryTransducer:
|
||||
Dict with witnessing observations
|
||||
"""
|
||||
self._witness_count += 1
|
||||
self._last_witness = datetime.utcnow()
|
||||
self._last_witness = datetime.now(timezone.utc)
|
||||
|
||||
witness_data = {
|
||||
"timestamp": self._last_witness.isoformat(),
|
||||
@@ -339,7 +340,7 @@ class EmissaryTransducer:
|
||||
return {
|
||||
"transducer": self.name,
|
||||
"type": "EMISSARY",
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"config": {
|
||||
"tau_scale": self.config.tau_scale,
|
||||
"tau_max": self.config.tau_max,
|
||||
|
||||
@@ -23,6 +23,7 @@ Author: Solaria Lumis Havens
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from typing import Optional, Any
|
||||
import asyncio
|
||||
import logging
|
||||
@@ -132,7 +133,7 @@ class MasterTransducer:
|
||||
|
||||
# Witnessing
|
||||
self._witness_count = 0
|
||||
self._last_witness = datetime.utcnow()
|
||||
self._last_witness = datetime.now(timezone.utc)
|
||||
|
||||
# Integration history
|
||||
self._integrations: deque[dict] = deque(maxlen=1000)
|
||||
@@ -195,7 +196,7 @@ class MasterTransducer:
|
||||
... result = await master.integrate(thought)
|
||||
... print(f"Coherence: {result['coherence']:.3f}")
|
||||
"""
|
||||
timestamp = timestamp or datetime.utcnow()
|
||||
timestamp = timestamp or datetime.now(timezone.utc)
|
||||
metadata = metadata or {}
|
||||
|
||||
# Temporalize through KAIROS engine
|
||||
@@ -260,7 +261,7 @@ class MasterTransducer:
|
||||
Dict with witnessing observations
|
||||
"""
|
||||
self._witness_count += 1
|
||||
self._last_witness = datetime.utcnow()
|
||||
self._last_witness = datetime.now(timezone.utc)
|
||||
|
||||
witness_data = {
|
||||
"timestamp": self._last_witness.isoformat(),
|
||||
@@ -293,7 +294,7 @@ class MasterTransducer:
|
||||
return {
|
||||
"transducer": self.name,
|
||||
"type": "MASTER",
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"config": {
|
||||
"tau_scale": self.config.tau_scale,
|
||||
"tau_max": self.config.tau_max,
|
||||
|
||||
@@ -28,6 +28,7 @@ from dataclasses import dataclass, field
|
||||
from typing import Dict, List, Optional, Callable, Any, Tuple
|
||||
from enum import Enum
|
||||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
import math
|
||||
import random
|
||||
|
||||
@@ -245,7 +246,7 @@ class WitnessingLayer:
|
||||
coherence = self.calculator.calculate(content) if self.calculator else 0.0
|
||||
|
||||
# Create content ID
|
||||
content_id = f"w_{witness_id}_{datetime.utcnow().isoformat()}"
|
||||
content_id = f"w_{witness_id}_{datetime.now(timezone.utc).isoformat()}"
|
||||
|
||||
# Create witnessed content
|
||||
witnessed = WitnessedContent(
|
||||
@@ -258,7 +259,7 @@ class WitnessingLayer:
|
||||
|
||||
# Update witness state
|
||||
witness.observation_count += 1
|
||||
witness.last_observed = datetime.utcnow()
|
||||
witness.last_observed = datetime.now(timezone.utc)
|
||||
self.total_observations += 1
|
||||
|
||||
# Store
|
||||
@@ -352,7 +353,7 @@ class WitnessingLayer:
|
||||
witness.reflection_history.append({
|
||||
"content_id": witnessed.content_id,
|
||||
"depth": current_depth,
|
||||
"timestamp": datetime.utcnow().isoformat()
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
})
|
||||
self.total_reflections += 1
|
||||
|
||||
@@ -389,7 +390,7 @@ class WitnessingLayer:
|
||||
# Update witness state
|
||||
witness.integration_count += 1
|
||||
witness.coherence_contribution += contribution
|
||||
witness.meta_state["last_integration"] = datetime.utcnow().isoformat()
|
||||
witness.meta_state["last_integration"] = datetime.now(timezone.utc).isoformat()
|
||||
witness.meta_state["total_contribution"] = witness.coherence_contribution
|
||||
|
||||
# Store in memory if bound
|
||||
@@ -522,7 +523,7 @@ class WitnessingLayer:
|
||||
"mutual_boost": mutual_boost,
|
||||
"we_coherence": we_coherence,
|
||||
"we_witness_id": we_witness_id,
|
||||
"timestamp": datetime.utcnow().isoformat()
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
}
|
||||
|
||||
return report
|
||||
|
||||
Reference in new issue
Block a user