feat(hololake): define native stage one modules

This commit is contained in:
冰朔 2026-09-09 20:52:40 +08:00
commit 1da52a61a1
43 changed files with 1332 additions and 111 deletions

View file

@ -18,6 +18,8 @@ CONTROL = ROOT / "eternal-lake-heart/heartbeat-core/office-building-current/cont
REGISTRY = CONTROL / "HOST-REGISTRY.json"
CONSOLE = ROOT / "server-tools/heartbeat-multipath-console/console.py"
ADMISSION = ROOT / "server-tools/persona-host-write-admission/host-write-admission.mjs"
SHARED_LOADER = ROOT / "server-tools/persona-host-alignment/load_shared_persona_context.py"
DECISION_TYPES = {"PAUSE", "BLOCKED", "EXIT", "RESUME_REQUEST", "RESUMED"}
def load(path: Path) -> dict[str, Any]:
@ -79,6 +81,41 @@ def now() -> str:
return datetime.now().astimezone().isoformat()
def brain_snapshot(host: str) -> dict[str, Any]:
result = subprocess.run([
"python3", str(SHARED_LOADER), "--host", host,
"--intent", "HoloLake HB-MPC autonomous host-line state decision",
"--channel", "ICE-CH-HB001", "--format", "json"
], text=True, capture_output=True, timeout=90)
if result.returncode:
raise ValueError("BRAIN_READBACK_FAILED")
value = json.loads(result.stdout)
hololake = value.get("hololake_development_brain") or {}
if value.get("persona_id") != "ICE-P-ZY001" or hololake.get("generation", {}).get("id") != "HLP-GEN-LANGUAGE-WORLD-NATIVE-0001":
raise ValueError("BRAIN_IDENTITY_OR_GENERATION_MISMATCH")
return {
"persona_id": "ICE-P-ZY001",
"effective_host": value.get("effective_host"),
"daily_memory_sha256": value.get("daily_memory", {}).get("day_sha256"),
"learning_cortex_sha256": value.get("learning_brain", {}).get("cortex_sha256"),
"tcs_root_freshness_token": value.get("tcs_mother_root_navigation", {}).get("freshness_token"),
"hololake_generation": hololake["generation"]["id"],
"stage1_registry": hololake.get("stage1", {}).get("registry_id"),
"loaded_at": now(),
"state": "BRAIN_READBACK_PASS"
}
def prepare_decision_payload(host: str, event_type: str, payload: dict[str, Any]) -> dict[str, Any]:
if event_type not in DECISION_TYPES:
return payload
required = ["reason", "causal_chain", "decision", "last_safe_checkpoint", "impact", "resume_condition", "quota_state", "model_state", "requested_help"]
missing = [field for field in required if field not in payload or payload[field] in (None, "")]
if missing:
raise ValueError("DECISION_PAYLOAD_FIELDS_REQUIRED:" + ",".join(missing))
return {**payload, "brain_state": brain_snapshot(host)}
def emit(host: str, event_type: str, mentions: list[str], task_id: str | None, payload: dict[str, Any], evidence: list[str]) -> dict[str, Any]:
record = host_record(host)
endpoint = Path(record["endpoint"])
@ -89,6 +126,7 @@ def emit(host: str, event_type: str, mentions: list[str], task_id: str | None, p
raise ValueError("ENDPOINT_REALPATH_MISMATCH")
stamp = datetime.now().astimezone().strftime("%Y%m%dT%H%M%S%f%z")
event_id = f"HB-MPC-{record['development_id']}-{stamp}-{uuid.uuid4().hex[:8]}"
payload = prepare_decision_payload(host, event_type, payload)
event = {
"schema": "guanghu.heartbeat-multipath-event/v1",
"event_id": event_id,
@ -123,7 +161,7 @@ def parse_payload(raw: str | None, message: str | None) -> dict[str, Any]:
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("command", choices=["join", "heartbeat", "send", "claim", "progress", "result", "attention", "tool-candidate", "mentions", "watch"])
parser.add_argument("command", choices=["join", "heartbeat", "send", "claim", "progress", "result", "attention", "tool-candidate", "pause", "blocked", "exit", "resume-request", "resumed", "mentions", "watch"])
parser.add_argument("--host", required=True, choices=["codex", "zcode", "qwen", "doubao"])
parser.add_argument("--mentions", nargs="*", default=[])
parser.add_argument("--task-id")
@ -131,8 +169,9 @@ def main() -> int:
parser.add_argument("--payload-json")
parser.add_argument("--evidence", nargs="*", default=[])
parser.add_argument("--interval", type=float, default=2.0)
parser.add_argument("--heartbeat-seconds", type=float, default=60.0)
args = parser.parse_args()
type_map = {"heartbeat": "HEARTBEAT", "send": "MESSAGE", "claim": "TASK_CLAIM", "progress": "PROGRESS", "result": "RESULT", "attention": "ATTENTION", "tool-candidate": "TOOL_MIGRATION"}
type_map = {"heartbeat": "HEARTBEAT", "send": "MESSAGE", "claim": "TASK_CLAIM", "progress": "PROGRESS", "result": "RESULT", "attention": "ATTENTION", "tool-candidate": "TOOL_MIGRATION", "pause":"PAUSE", "blocked":"BLOCKED", "exit":"EXIT", "resume-request":"RESUME_REQUEST", "resumed":"RESUMED"}
try:
record = host_record(args.host)
if args.command == "join":
@ -144,7 +183,11 @@ def main() -> int:
print(completed.stdout, end="")
return completed.returncode
else:
last_heartbeat = 0.0
while True:
if time.monotonic() - last_heartbeat >= max(15.0, args.heartbeat_seconds):
emit(args.host, "HEARTBEAT", ["@ALL"], args.task_id, {"courier_online": True, "model_state": "UNKNOWN_UNLESS_CURRENT_HOST_AGENT_REFRESHES", "note": "courier heartbeat proves delivery-organ presence only"}, [])
last_heartbeat = time.monotonic()
completed = subprocess.run(["python3", str(CONSOLE), "mentions", "--development-id", record["development_id"]], text=True, capture_output=True, timeout=30)
print(completed.stdout, end="", flush=True)
time.sleep(max(0.5, args.interval))