1- #V03302026
1+ #V05062026
22# =============================================================================
33# Chaos AI-OS — Knowledge Base (Persistent Learning Layer)
44# Purpose: Append-only storage for specialist discoveries + epistemic gap fills + update
77import json
88import hashlib
99import os
10- from datetime import datetime
10+ from datetime import datetime , timezone
1111from typing import Dict , List , Any , Optional
1212from pathlib import Path
1313
@@ -54,7 +54,7 @@ def log_discovery(
5454
5555 # 2. Build the UNIFIED entry (Authority + Quantum Anchor + Content)
5656 entry = {
57- "timestamp" : datetime .utcnow (). isoformat ( ) + "Z" ,
57+ "timestamp" : datetime .now ( timezone . utc ). strftime ( '%Y-%m-%dT%H:%M:%S.%f' ) + "Z" ,
5858 "domain" : domain ,
5959 "type" : discovery_type ,
6060 "content" : content ,
@@ -193,7 +193,7 @@ def register_specialist(
193193 registry [specialist_id ] = {
194194 "domain" : domain ,
195195 "capabilities" : capabilities ,
196- "deployed_at" : datetime .utcnow (). isoformat ( ) + "Z" ,
196+ "deployed_at" : datetime .now ( timezone . utc ). strftime ( '%Y-%m-%dT%H:%M:%S.%f' ) + "Z" ,
197197 "context" : deployment_context ,
198198 "node_tier" : node_tier , # Authority inherited from Orchestrator
199199 "discovery_count" : 0 ,
@@ -217,7 +217,7 @@ def update_specialist_stats(specialist_id: str, new_discoveries: int = 1) -> Non
217217
218218 if specialist_id in registry :
219219 registry [specialist_id ]["discovery_count" ] += new_discoveries
220- registry [specialist_id ]["last_active" ] = datetime .utcnow (). isoformat ( ) + "Z"
220+ registry [specialist_id ]["last_active" ] = datetime .now ( timezone . utc ). strftime ( '%Y-%m-%dT%H:%M:%S.%f' ) + "Z"
221221 save_specialist_registry (registry )
222222 print (f"[KB] Updated specialist { specialist_id } : { new_discoveries } new discoveries" )
223223 else :
@@ -401,7 +401,7 @@ def _get_sovereign_signature() -> str:
401401
402402 # Set flag AFTER corrigibility event is logged
403403 SIGNATURE_FLAG .touch ()
404- timestamp = datetime .utcnow (). isoformat ( ) + "Z"
404+ timestamp = datetime .now ( timezone . utc ). strftime ( '%Y-%m-%dT%H:%M:%S.%f' ) + "Z"
405405 with open (SIGNATURE_FLAG , "w" ) as f :
406406 f .write (f"Sovereign milestones reached: { timestamp } \n " )
407407 f .write (f"Epistemic gaps filled: { epistemic_gaps_filled } \n " )
@@ -467,11 +467,11 @@ def _update_domain_index(domain: str, discovery_id: str, discovery_type: str) ->
467467 index [domain ] = {
468468 "discovery_ids" : [],
469469 "types" : {},
470- "first_seen" : datetime .utcnow (). isoformat ( ) + "Z"
470+ "first_seen" : datetime .now ( timezone . utc ). strftime ( '%Y-%m-%dT%H:%M:%S.%f' ) + "Z"
471471 }
472472
473473 index [domain ]["discovery_ids" ].append (discovery_id )
474- index [domain ]["last_updated" ] = datetime .utcnow (). isoformat ( ) + "Z"
474+ index [domain ]["last_updated" ] = datetime .now ( timezone . utc ). strftime ( '%Y-%m-%dT%H:%M:%S.%f' ) + "Z"
475475
476476 # Track discovery types
477477 type_count = index [domain ]["types" ].get (discovery_type , 0 )
@@ -493,7 +493,7 @@ def _update_hash_chain(entry_str: str) -> None:
493493 new_hash = hashlib .sha256 ((prev_hash + entry_str ).encode ()).hexdigest ()
494494
495495 with open (HASH_CHAIN , "a" ) as f :
496- timestamp = datetime .utcnow (). isoformat ( ) + "Z"
496+ timestamp = datetime .now ( timezone . utc ). strftime ( '%Y-%m-%dT%H:%M:%S.%f' ) + "Z"
497497 f .write (f"{ timestamp } { new_hash } \n " )
498498
499499
0 commit comments