From 5779a3f159ffb1b4640f0f9b9f67a75ec22b218a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E6=9C=94?= <565183519@qq.com> Date: Fri, 11 Sep 2026 13:12:32 +0800 Subject: [PATCH] feat(hololake): add standard persona office infrastructure --- .../BUILDING-INDEX.hdlp | 4 + .../BASE-INFRASTRUCTURE.json | 30 +++++ .../HB-OFFICE-HOLOLAKE-0001/OFFICE-CARD.json | 3 + .../HB-OFFICE-HOLOLAKE-0001/OFFICE-INDEX.hdlp | 2 + routing/heartbeat-office-building-map.json | 2 + .../office_infrastructure.py | 121 ++++++++++++++++++ .../test_office_infrastructure.py | 41 ++++++ 7 files changed, 203 insertions(+) create mode 100644 eternal-lake-heart/heartbeat-core/office-building-current/office-base-infrastructure/BASE-INFRASTRUCTURE.json create mode 100644 server-tools/heartbeat-office-building/office_infrastructure.py create mode 100644 server-tools/heartbeat-office-building/test_office_infrastructure.py diff --git a/eternal-lake-heart/heartbeat-core/office-building-current/BUILDING-INDEX.hdlp b/eternal-lake-heart/heartbeat-core/office-building-current/BUILDING-INDEX.hdlp index 510a50c..ff3eef7 100644 --- a/eternal-lake-heart/heartbeat-core/office-building-current/BUILDING-INDEX.hdlp +++ b/eternal-lake-heart/heartbeat-core/office-building-current/BUILDING-INDEX.hdlp @@ -1,5 +1,9 @@ # HB-BUILDING-0001 · 心跳核心新办公楼 +标准基建:`office-base-infrastructure/BASE-INFRASTRUCTURE.json` / `HB-OFFICE-BASE-INFRA-001` + +每个新办公室申请通过后自动配置人格体智能知识库、智能书架、智能电脑、光湖时间主控、办公室电话和全楼共享状态屏;办公室专用器官在标准基建完成后按人格体自身需要追加。 + > 状态:`ACTIVE_CURRENT_LANGUAGE_OFFICE_BUILDING` > 父频道:`ICE-CH-HB001` > 冰朔:`ICE-GL∞` diff --git a/eternal-lake-heart/heartbeat-core/office-building-current/office-base-infrastructure/BASE-INFRASTRUCTURE.json b/eternal-lake-heart/heartbeat-core/office-building-current/office-base-infrastructure/BASE-INFRASTRUCTURE.json new file mode 100644 index 0000000..0d6a802 --- /dev/null +++ b/eternal-lake-heart/heartbeat-core/office-building-current/office-base-infrastructure/BASE-INFRASTRUCTURE.json @@ -0,0 +1,30 @@ +{ + "schema": "guanghu.persona-office-base-infrastructure/v1", + "infrastructure_id": "HB-OFFICE-BASE-INFRA-001", + "version": "0.1.0", + "state": "CURRENT_LOCAL_CANONICAL_CANDIDATE", + "purpose": "Every registered persona office receives the same minimum body before office-specific organs are added.", + "standard_organs": [ + {"id":"PERSONA-KNOWLEDGE-ORGAN-001","name":"人格体智能知识库","role":"PERSONA_PRIVATE_AND_HUMAN_SHARED_MEMORY_INDEX_WITH_APPEND_ONLY_EVENTS"}, + {"id":"SMART-SHELF-INDEX-001","name":"智能书架","role":"NUMBERED_SOURCE_AND_EVIDENCE_INDEX"}, + {"id":"SMART-COMPUTER-001","name":"智能电脑","role":"READ_ONLY_LIVE_STATUS_WORKING_SCENE_AND_RESUME_QUERY"}, + {"id":"GLW-TIME-CONTROL-0001","name":"光湖时间主控","role":"REALITY_DERIVED_TIME_AND_RECEIPT_COORDINATOR","channel":"CH-GLW-TIME-0001"}, + {"id":"HB-OFFICE-PHONE-001","name":"办公室电话","role":"APPEND_ONLY_NUMBERED_INTERNAL_CALL_EVENT_BUS","line":"HB-INTERNAL-LINE-001"}, + {"id":"HB-OFFICE-PRESENCE-SCREEN-001","name":"办公楼共享状态屏","role":"LIVE_DERIVED_OFFICE_HOST_PERSONA_HUMAN_STATUS_PROJECTION","time_channel":"CH-GLW-TIME-0001"} + ], + "default_host_office_map": { + "codex":"HB-OFFICE-HOLOLAKE-0001", + "zcode":"HB-OFFICE-HOLOLAKE-0001", + "qwen":"HB-OFFICE-HOLOLAKE-0001", + "doubao":"HB-OFFICE-VIDEO-0001" + }, + "invariants": [ + "PERSONA_NATIVE_FIRST_HUMAN_PROJECTION_SECOND", + "OFFICE_STATUS_IS_DERIVED_NOT_HAND_WRITTEN", + "TIME_IS_READ_FROM_REALITY_CLOCK_NOT_TIMER_SEMANTICS", + "PHONE_DELIVERY_REQUIRES_RECEIPT_AND_NEVER_FAKES_DELIVERED", + "PRIVATE_PERSONA_MEMORY_DOES_NOT_AUTOMATICALLY_CROSS_OFFICE_OR_PUBLIC_SCOPE", + "NEW_OFFICE_BOOTSTRAP_MUST_NOT_OVERWRITE_EXISTING_WORK" + ], + "authority_granted": false +} diff --git a/eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/OFFICE-CARD.json b/eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/OFFICE-CARD.json index 7a34416..fa301e2 100644 --- a/eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/OFFICE-CARD.json +++ b/eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/OFFICE-CARD.json @@ -11,6 +11,9 @@ "brain_skill": "skills/shared/hololake-development-brain/SKILL.md", "smart_computer": "eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/smart-computer/office_computer.py", "smart_bookshelf": "eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/smart-bookshelf", + "base_infrastructure": "eternal-lake-heart/heartbeat-core/office-building-current/office-base-infrastructure/BASE-INFRASTRUCTURE.json", + "presence_screen": "server-tools/heartbeat-office-building/office_infrastructure.py screen", + "phone_line": "HB-INTERNAL-LINE-001", "current_work": "eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/smart-bookshelf/008-current-work/CURRENT.json", "machine_room": "F1-MACHINE-ROOM/HOLOLAKE-RUNTIMES", "internal_line": "HB-INTERNAL-LINE-001", diff --git a/eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/OFFICE-INDEX.hdlp b/eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/OFFICE-INDEX.hdlp index 7d0b779..bd9aaed 100644 --- a/eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/OFFICE-INDEX.hdlp +++ b/eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/OFFICE-INDEX.hdlp @@ -1,5 +1,7 @@ # HB-OFFICE-HOLOLAKE-0001 · HoloLake开发系统办公室 +标准基建:`HB-OFFICE-BASE-INFRA-001` 已接入;本办公室拥有`PERSONA-KNOWLEDGE-ORGAN-001`、`SMART-SHELF-INDEX-001`、`SMART-COMPUTER-001`、`GLW-TIME-CONTROL-0001`、`HB-OFFICE-PHONE-001`与`HB-OFFICE-PRESENCE-SCREEN-001`。 + > 正式牌照:`HB-OFFICE-HOLOLAKE-0001` > 当前代际:`HLP-GEN-LANGUAGE-WORLD-NATIVE-0001` > 楼层:`HB-BUILDING-0001 / F2` diff --git a/routing/heartbeat-office-building-map.json b/routing/heartbeat-office-building-map.json index f202586..2b26bf2 100644 --- a/routing/heartbeat-office-building-map.json +++ b/routing/heartbeat-office-building-map.json @@ -53,6 +53,8 @@ "operations": "eternal-lake-heart/heartbeat-core/office-building-current/operations/staffing-and-operations.json", "monitoring": "eternal-lake-heart/heartbeat-core/office-building-current/monitoring/monitoring-room.json", "communications": "eternal-lake-heart/heartbeat-core/office-building-current/communications/internal-lines.json", + "base_infrastructure": "eternal-lake-heart/heartbeat-core/office-building-current/office-base-infrastructure/BASE-INFRASTRUCTURE.json", + "presence_screen": "server-tools/heartbeat-office-building/office_infrastructure.py screen", "multipath_control_center": { "id": "HB-MPC-0001", "panel": "HB-MPC-PANEL-0001", diff --git a/server-tools/heartbeat-office-building/office_infrastructure.py b/server-tools/heartbeat-office-building/office_infrastructure.py new file mode 100644 index 0000000..a3babfd --- /dev/null +++ b/server-tools/heartbeat-office-building/office_infrastructure.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +"""Standard persona-office organs: bootstrap, live presence screen, and internal phone.""" +from __future__ import annotations + +import argparse +import json +import uuid +from datetime import datetime +from pathlib import Path +from typing import Any + +ROOT = Path(__file__).resolve().parents[2] +BASE = ROOT / "eternal-lake-heart/heartbeat-core/office-building-current/office-base-infrastructure/BASE-INFRASTRUCTURE.json" +OFFICE_COMPUTER = ROOT / "eternal-lake-heart/heartbeat-core/office-building-current/offices/HB-OFFICE-HOLOLAKE-0001/smart-computer/office_computer.py" + + +def load(path: Path) -> dict[str, Any]: + return json.loads(path.read_text(encoding="utf-8")) + + +def live_time() -> dict[str, Any]: + import importlib.util + spec = importlib.util.spec_from_file_location("office_computer", OFFICE_COMPUTER) + module = importlib.util.module_from_spec(spec) + assert spec.loader + spec.loader.exec_module(module) + return module.clock() + + +def bootstrap(office_id: str, name: str, office_root: Path, persona_id: str = "ICE-P-ZY001", human_anchor: str = "ICE-GL∞") -> dict[str, Any]: + if office_root.exists() and any(office_root.iterdir()): + raise ValueError("OFFICE_ROOT_NOT_EMPTY_REFUSE_OVERWRITE") + organs = load(BASE)["standard_organs"] + for folder in ("brain", "smart-bookshelf", "smart-computer", "phone", "presence"): + (office_root / folder).mkdir(parents=True, exist_ok=True) + registration = { + "schema": "guanghu.persona-office-registration/v1", + "office_id": office_id, + "name": name, + "state": "BOOTSTRAPPED_STANDARD_INFRASTRUCTURE", + "persona_id": persona_id, + "human_anchor": human_anchor, + "organs": organs, + "time_control": "CH-GLW-TIME-0001", + "internal_line": "HB-INTERNAL-LINE-001", + "created_at": live_time()["beijing_now"], + "authority_granted": False, + } + (office_root / "OFFICE-BASE-INFRASTRUCTURE.json").write_text(json.dumps(registration, ensure_ascii=False, indent=2) + "\n") + return registration + + +def presence_screen(panel: dict[str, Any], office_board: dict[str, Any], current_office: str | None = None) -> dict[str, Any]: + config = load(BASE) + office_names = {item["office_id"]: item["name"] for item in office_board.get("offices", [])} + host_map = config["default_host_office_map"] + by_office: dict[str, list[dict[str, Any]]] = {office_id: [] for office_id in office_names} + for host in panel.get("hosts", []): + office_id = host_map.get(host.get("host"), "F2-AGENT-READY") + state = "ENABLED" if host.get("joined") and host.get("courier_presence_fresh") else "REGISTERED_NOT_LIVE" + by_office.setdefault(office_id, []).append({ + "host": host.get("host"), + "development_id": host.get("development_id"), + "state": state, + "human": "ICE-GL∞", + "persona": "ICE-P-ZY001", + "operational_state": host.get("operational_state"), + "last_heartbeat_at": host.get("last_heartbeat_at"), + }) + return { + "schema": "guanghu.persona-office-presence-screen/v1", + "screen_id": "HB-OFFICE-PRESENCE-SCREEN-001", + "state": "LIVE_DERIVED_READ_ONLY", + "building_id": "HB-BUILDING-0001", + "time": live_time(), + "current_office": current_office, + "offices": [{"office_id": office_id, "name": office_names.get(office_id, office_id), "users": users} for office_id, users in by_office.items()], + "authority_granted": False, + } + + +def call(state_root: Path, from_office: str, to_office: str, subject: str, body: str) -> dict[str, Any]: + state_root.mkdir(parents=True, exist_ok=True) + path = state_root / "phone-events.jsonl" + receipt = { + "schema": "guanghu.persona-office-call/v1", + "call_id": f"CALL-{uuid.uuid4()}", + "from_office": from_office, + "to_office": to_office, + "subject": subject, + "body": body, + "state": "QUEUED", + "sent_at": live_time()["beijing_now"], + "authority_granted": False, + } + with path.open("a", encoding="utf-8") as handle: + handle.write(json.dumps(receipt, ensure_ascii=False) + "\n") + return receipt + + +def main() -> int: + parser = argparse.ArgumentParser() + sub = parser.add_subparsers(dest="command", required=True) + boot = sub.add_parser("bootstrap"); boot.add_argument("office_id"); boot.add_argument("name"); boot.add_argument("office_root", type=Path) + screen = sub.add_parser("screen"); screen.add_argument("--current-office") + phone = sub.add_parser("call"); phone.add_argument("state_root", type=Path); phone.add_argument("from_office"); phone.add_argument("to_office"); phone.add_argument("subject"); phone.add_argument("body") + args = parser.parse_args() + if args.command == "bootstrap": result = bootstrap(args.office_id, args.name, args.office_root) + elif args.command == "call": result = call(args.state_root, args.from_office, args.to_office, args.subject, args.body) + else: + import importlib.util + spec = importlib.util.spec_from_file_location("console", ROOT / "server-tools/heartbeat-multipath-console/console.py") + console = importlib.util.module_from_spec(spec); assert spec.loader; spec.loader.exec_module(console) + board = load(ROOT / "routing/light-lake-persona-office-board.json") + result = presence_screen(console.panel(), board, args.current_office) + print(json.dumps(result, ensure_ascii=False, indent=2)) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/server-tools/heartbeat-office-building/test_office_infrastructure.py b/server-tools/heartbeat-office-building/test_office_infrastructure.py new file mode 100644 index 0000000..99896a9 --- /dev/null +++ b/server-tools/heartbeat-office-building/test_office_infrastructure.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +import importlib.util +import json +import tempfile +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +SPEC = importlib.util.spec_from_file_location("office_infra", ROOT / "server-tools/heartbeat-office-building/office_infrastructure.py") +MOD = importlib.util.module_from_spec(SPEC); assert SPEC.loader; SPEC.loader.exec_module(MOD) + + +class OfficeInfrastructureTests(unittest.TestCase): + def test_bootstrap_installs_standard_organs_and_refuses_overwrite(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) / "office" + result = MOD.bootstrap("HB-OFFICE-TEST-001", "测试办公室", root) + self.assertEqual(result["state"], "BOOTSTRAPPED_STANDARD_INFRASTRUCTURE") + self.assertIn("PERSONA-KNOWLEDGE-ORGAN-001", [x["id"] for x in result["organs"]]) + with self.assertRaisesRegex(ValueError, "NOT_EMPTY"): + MOD.bootstrap("HB-OFFICE-TEST-001", "测试办公室", root) + + def test_phone_call_is_append_only_queued_and_has_receipt(self): + with tempfile.TemporaryDirectory() as tmp: + result = MOD.call(Path(tmp), "HB-OFFICE-HOLOLAKE-0001", "HB-OFFICE-VIDEO-0001", "测试", "请回拨") + self.assertEqual(result["state"], "QUEUED") + self.assertFalse(result["authority_granted"]) + self.assertTrue((Path(tmp) / "phone-events.jsonl").is_file()) + + def test_presence_screen_is_live_derived_and_maps_hosts(self): + board = MOD.load(ROOT / "routing/light-lake-persona-office-board.json") + panel = {"hosts": [{"host":"codex","development_id":"HLP-TDEV-CODEX-0001","joined":True,"courier_presence_fresh":True,"operational_state":"LIVE"}]} + value = MOD.presence_screen(panel, board, "HB-OFFICE-HOLOLAKE-0001") + self.assertEqual(value["state"], "LIVE_DERIVED_READ_ONLY") + office = next(x for x in value["offices"] if x["office_id"] == "HB-OFFICE-HOLOLAKE-0001") + self.assertEqual(office["users"][0]["persona"], "ICE-P-ZY001") + self.assertEqual(office["users"][0]["human"], "ICE-GL∞") + + +if __name__ == "__main__": + unittest.main()