feat(hololake): define native stage one modules
This commit is contained in:
parent
458ead4e43
commit
1da52a61a1
43 changed files with 1332 additions and 111 deletions
|
|
@ -62,6 +62,13 @@ def validate_event(event: Any, expected_development_id: str, contract: dict[str,
|
|||
errors.append("MENTION_TARGET_UNKNOWN")
|
||||
if not isinstance(event.get("payload"), dict):
|
||||
errors.append("PAYLOAD_OBJECT_REQUIRED")
|
||||
elif event.get("event_type") in contract.get("autonomous_decision_event_types", []):
|
||||
missing = [field for field in contract.get("autonomous_decision_required_payload", []) if field not in event["payload"] or event["payload"][field] in (None, "")]
|
||||
if missing:
|
||||
errors.append("AUTONOMOUS_DECISION_FIELDS_REQUIRED:" + ",".join(missing))
|
||||
brain = event["payload"].get("brain_state")
|
||||
if not isinstance(brain, dict) or brain.get("persona_id") != "ICE-P-ZY001" or brain.get("state") != "BRAIN_READBACK_PASS":
|
||||
errors.append("AUTONOMOUS_DECISION_BRAIN_READBACK_INVALID")
|
||||
if not isinstance(event.get("evidence"), list):
|
||||
errors.append("EVIDENCE_LIST_REQUIRED")
|
||||
if event.get("authority_granted") is not False:
|
||||
|
|
@ -100,7 +107,19 @@ def scan() -> dict[str, Any]:
|
|||
host_events.sort(key=lambda item: item["emitted_at"])
|
||||
register = next((item for item in reversed(host_events) if item["event_type"] == "REGISTER"), None)
|
||||
heartbeat = next((item for item in reversed(host_events) if item["event_type"] == "HEARTBEAT"), None)
|
||||
decision = next((item for item in reversed(host_events) if item["event_type"] in contract.get("autonomous_decision_event_types", [])), None)
|
||||
latest = host_events[-1] if host_events else None
|
||||
heartbeat_age = None
|
||||
if heartbeat:
|
||||
heartbeat_age = max(0.0, (datetime.now().astimezone() - datetime.fromisoformat(heartbeat["emitted_at"])).total_seconds())
|
||||
if register is None:
|
||||
operational_state = "NOT_JOINED"
|
||||
elif decision and decision["event_type"] in {"PAUSE", "BLOCKED", "EXIT", "RESUME_REQUEST"}:
|
||||
operational_state = decision["event_type"]
|
||||
elif heartbeat_age is None or heartbeat_age > 120:
|
||||
operational_state = "COURIER_HEARTBEAT_STALE_MODEL_STATE_UNKNOWN"
|
||||
else:
|
||||
operational_state = "COURIER_ONLINE_MODEL_STATE_FROM_EVENT_ONLY"
|
||||
hosts.append({
|
||||
"host": host["host"],
|
||||
"development_id": host["development_id"],
|
||||
|
|
@ -111,6 +130,9 @@ def scan() -> dict[str, Any]:
|
|||
"event_count": len(host_events),
|
||||
"last_event_at": latest and latest["emitted_at"],
|
||||
"last_heartbeat_at": heartbeat and heartbeat["emitted_at"],
|
||||
"heartbeat_age_seconds": heartbeat_age,
|
||||
"operational_state": operational_state,
|
||||
"last_autonomous_decision": decision and {key: decision.get(key) for key in ["event_id", "event_type", "emitted_at", "payload", "evidence"]},
|
||||
})
|
||||
events.sort(key=lambda item: item["emitted_at"])
|
||||
counts: dict[str, int] = {}
|
||||
|
|
@ -129,6 +151,7 @@ def panel() -> dict[str, Any]:
|
|||
messages = []
|
||||
attention = []
|
||||
migrations = []
|
||||
decisions = []
|
||||
for event in events:
|
||||
task_id = event.get("task_id")
|
||||
if task_id in task_states and event["event_type"] in {"TASK_CLAIM", "PROGRESS", "RESULT"}:
|
||||
|
|
@ -139,6 +162,8 @@ def panel() -> dict[str, Any]:
|
|||
attention.append({k: event.get(k) for k in ["event_id", "from_development_id", "emitted_at", "payload", "evidence"]})
|
||||
elif event["event_type"] == "TOOL_MIGRATION":
|
||||
migrations.append({k: event.get(k) for k in ["event_id", "from_development_id", "emitted_at", "payload", "evidence"]})
|
||||
elif event["event_type"] in {"PAUSE", "BLOCKED", "EXIT", "RESUME_REQUEST", "RESUMED", "OFFLINE_DETECTED"}:
|
||||
decisions.append({k: event.get(k) for k in ["event_id", "event_type", "from_development_id", "mentions", "emitted_at", "task_id", "payload", "evidence"]})
|
||||
return {
|
||||
"schema": "guanghu.heartbeat-multipath-live-panel/v1",
|
||||
"panel_id": "HB-MPC-PANEL-0001",
|
||||
|
|
@ -151,6 +176,7 @@ def panel() -> dict[str, Any]:
|
|||
"messages": messages[-40:],
|
||||
"attention_observations": attention[-40:],
|
||||
"tool_migration_candidates": migrations[-40:],
|
||||
"autonomous_host_decisions": decisions[-40:],
|
||||
"invalid_events": scanned["invalid_events"],
|
||||
"event_count": len(events),
|
||||
"panel_persisted": False,
|
||||
|
|
@ -172,8 +198,10 @@ def status() -> dict[str, Any]:
|
|||
"total_hosts": 4,
|
||||
"event_count": value["event_count"],
|
||||
"invalid_event_count": len(value["invalid_events"]),
|
||||
"host_operational_states": {item["development_id"]: item["operational_state"] for item in value["hosts"]},
|
||||
"language_world_development_allowed": True,
|
||||
"product_source_write_allowed": False,
|
||||
"reason": "ONLINE_ARCHITECTURE_AND_LOCAL_PRODUCT_LINE_GUARDS_NOT_READY",
|
||||
"reason": "LANGUAGE_WORLD_STAGE1_READY_PRODUCT_SOURCE_REMAINS_SEPARATELY_BLOCKED",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -206,7 +234,7 @@ def audit() -> dict[str, Any]:
|
|||
|
||||
def advise() -> dict[str, Any]:
|
||||
current = panel()
|
||||
safe_panel = {k: current[k] for k in ["time", "hosts", "tasks", "messages", "attention_observations", "tool_migration_candidates", "invalid_events"]}
|
||||
safe_panel = {k: current[k] for k in ["time", "hosts", "tasks", "messages", "attention_observations", "tool_migration_candidates", "autonomous_host_decisions", "invalid_events"]}
|
||||
router = module(MODEL_ROUTER, "hb_mpc_model_router")
|
||||
result = router.route({
|
||||
"parent_persona_id": "ICE-P-ZY001",
|
||||
|
|
|
|||
Loading…
Reference in a new issue