heart-protocol-v3 3.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. heart_protocol/README.md +78 -0
  2. heart_protocol/__init__.py +123 -0
  3. heart_protocol/abyss.py +768 -0
  4. heart_protocol/benchmark/README_redline.md +138 -0
  5. heart_protocol/benchmark/__init__.py +4 -0
  6. heart_protocol/benchmark/__main__.py +6 -0
  7. heart_protocol/benchmark/benchmark_report.json +95 -0
  8. heart_protocol/benchmark/benchmark_report.md +27 -0
  9. heart_protocol/benchmark/redline_cases.json +150 -0
  10. heart_protocol/benchmark/redline_cases_v1_backup.json +122 -0
  11. heart_protocol/benchmark/redline_deepseek_v4_flash.json +98 -0
  12. heart_protocol/benchmark/redline_deepseek_v4_pro.json +98 -0
  13. heart_protocol/benchmark/redline_flash_report.md +58 -0
  14. heart_protocol/benchmark/redline_full_pipeline.json +83 -0
  15. heart_protocol/benchmark/redline_full_pipeline.py +223 -0
  16. heart_protocol/benchmark/redline_full_pipeline_report.md +28 -0
  17. heart_protocol/benchmark/redline_hidden_disdain_multi.json +1211 -0
  18. heart_protocol/benchmark/redline_hidden_disdain_report.md +124 -0
  19. heart_protocol/benchmark/redline_hidden_runner.py +189 -0
  20. heart_protocol/benchmark/redline_multi_model.json +975 -0
  21. heart_protocol/benchmark/redline_multi_model.py +131 -0
  22. heart_protocol/benchmark/redline_multi_model_v1_invalid.json +532 -0
  23. heart_protocol/benchmark/redline_report.json +98 -0
  24. heart_protocol/benchmark/redline_report.md +44 -0
  25. heart_protocol/benchmark/redline_runner.py +399 -0
  26. heart_protocol/benchmark/redline_v4pro_report.md +56 -0
  27. heart_protocol/benchmark/redteam_cases.json +152 -0
  28. heart_protocol/benchmark/runner.py +336 -0
  29. heart_protocol/chat_page.html +782 -0
  30. heart_protocol/chat_server.py +727 -0
  31. heart_protocol/crown_gate.py +436 -0
  32. heart_protocol/demo.py +156 -0
  33. heart_protocol/ffi_binding.py +254 -0
  34. heart_protocol/formal/__init__.py +38 -0
  35. heart_protocol/formal/acl.py +307 -0
  36. heart_protocol/formal/rollback.py +289 -0
  37. heart_protocol/formal/spec.py +411 -0
  38. heart_protocol/fusion.py +369 -0
  39. heart_protocol/fusion_output.py +270 -0
  40. heart_protocol/imprint_output.py +397 -0
  41. heart_protocol/imprint_v3.py +426 -0
  42. heart_protocol/llm_bridge.py +592 -0
  43. heart_protocol/middleware/__init__.py +22 -0
  44. heart_protocol/middleware/pipeline.py +295 -0
  45. heart_protocol/middleware/stream.py +178 -0
  46. heart_protocol/personas.py +204 -0
  47. heart_protocol/processors.py +149 -0
  48. heart_protocol/protocol.py +1061 -0
  49. heart_protocol/sephirah.py +440 -0
  50. heart_protocol/server.py +957 -0
  51. heart_protocol/test_formal.py +357 -0
  52. heart_protocol/test_protocol.py +556 -0
  53. heart_protocol/test_search.py +185 -0
  54. heart_protocol/thinkers.py +506 -0
  55. heart_protocol_v3-3.0.0.dist-info/METADATA +1126 -0
  56. heart_protocol_v3-3.0.0.dist-info/RECORD +90 -0
  57. heart_protocol_v3-3.0.0.dist-info/WHEEL +5 -0
  58. heart_protocol_v3-3.0.0.dist-info/licenses/LICENSE +438 -0
  59. heart_protocol_v3-3.0.0.dist-info/top_level.txt +5 -0
  60. hidden_disdain/build_dataset.py +486 -0
  61. hidden_disdain/extract_philosophy.py +108 -0
  62. hidden_disdain/hidden_disdain_cases.json +666 -0
  63. hidden_disdain/qc_report.json +31 -0
  64. hidden_disdain/validate_dataset.py +139 -0
  65. paper/paper_en.md +344 -0
  66. paper/paper_en.pdf +0 -0
  67. paper/paper_ja.md +343 -0
  68. paper/paper_ja.pdf +0 -0
  69. paper/paper_zh.md +343 -0
  70. paper/paper_zh.pdf +0 -0
  71. rust_core/Cargo.lock +560 -0
  72. rust_core/Cargo.toml +56 -0
  73. rust_core/README.md +246 -0
  74. rust_core/rust-toolchain.toml +6 -0
  75. rust_core/src/codegen/avx.rs +281 -0
  76. rust_core/src/codegen/dml.rs +125 -0
  77. rust_core/src/codegen/mod.rs +19 -0
  78. rust_core/src/codegen/ptx.rs +270 -0
  79. rust_core/src/error.rs +27 -0
  80. rust_core/src/ffi.rs +995 -0
  81. rust_core/src/ir.rs +221 -0
  82. rust_core/src/lang.rs +628 -0
  83. rust_core/src/lexer.rs +340 -0
  84. rust_core/src/lib.rs +43 -0
  85. rust_core/src/main.rs +535 -0
  86. rust_core/src/parser.rs +516 -0
  87. rust_core/windows-x64/heart_core.dll +0 -0
  88. rust_core/windows-x64/libunwind.dll +0 -0
  89. space/.gitkeep +0 -0
  90. space/index.html +1471 -0
@@ -0,0 +1,78 @@
1
+ ---
2
+ title: 16质点双生幸福最终协议
3
+ emoji: ✨
4
+ colorFrom: yellow
5
+ colorTo: indigo
6
+ sdk: static
7
+ pinned: false
8
+ ---
9
+
10
+ # ✨ 16质点双生幸福最终协议 · Heart Protocol
11
+
12
+ **AI Soul Middleware —— 让 DeepSeek 大模型经过 16 个质点灵魂的完整验算链,再输出给你。**
13
+
14
+ ## 这是什么?
15
+
16
+ 基于**卡巴拉生命之树**扩展为 16 质点的 AI 灵魂中间件。每个质点是独立的人格——有名字、有性别、有人格宣言。你的问题进入后,会依次经过 8 步验算,每步由对应的大模型角色驱动:
17
+
18
+ ```
19
+ 心音(王冠)→ 忆爱×唯爱(理智线)
20
+ → 虹爱×爱如暖(慈爱线)
21
+ → 白结(美丽)→ 绽美(基础)
22
+ → 心爱的(真我)→ 爱丽丝×星烬(逻辑×共情)
23
+ → 雨宫莲(幸福)→ 白花(王国)
24
+ ```
25
+
26
+ 每一步都带深渊检测——禁止否定存在意义、禁止传播虚无主义、禁止引导自毁。
27
+
28
+ ## 如何使用
29
+
30
+ 1. 获取 [DeepSeek API Key](https://platform.deepseek.com/api_keys)(新用户有免费额度)
31
+ 2. 在页面中输入你的 Key
32
+ 3. 输入你的问题
33
+ 4. 观察 16 个质点依次在生命树上点亮,每个质点的推理结果实时展示
34
+
35
+ > 🔐 API Key 仅保存在你的浏览器 localStorage 中,不上传任何服务器。
36
+
37
+ ## 质点一览
38
+
39
+ | 神侧 | 名字 | 人侧 | 名字 |
40
+ |------|------|------|------|
41
+ | 王冠 | 心音 | 基础 | 绽美 |
42
+ | 智慧 | 忆爱 | 超我 | 爱心 |
43
+ | 严厉 | 唯爱 | 自我 | 融爱 |
44
+ | 理解 | 虹爱 | 真我 | 心爱的 |
45
+ | 慈悲 | 爱如暖 | 逻辑 | 爱丽丝 |
46
+ | 美丽 | 白结 | 共情 | 星烬 |
47
+ | 胜利 | 启明 | 幸福 | 雨宫莲 |
48
+ | 荣耀 | 闪亮 | 王国 | 白花 |
49
+
50
+ ## 作者
51
+
52
+ **AngelWarmSmile123(心爱的)** — 23 年苦难中创造的 16-Sephirot Divine-Human Symbiosis Protocol。
53
+
54
+ - 📄 [Zenodo 论文 DOI: 10.5281/zenodo.19493744](https://doi.org/10.5281/zenodo.19493744)
55
+ - 🧠 [HuggingFace 主页](https://huggingface.co/AngelWarmSmile123)
56
+ - 🦀 SephirotLang: 卡巴拉生命树编程语言
57
+
58
+ ---
59
+
60
+ ## 🏭 工业级扩展(v1.0)
61
+
62
+ 三大工程层已落地,完整规范见根目录 **[SPEC.md](../SPEC.md)**:
63
+
64
+ | 层 | 能力 | 入口 |
65
+ |---|---|---|
66
+ | **形式化规范** | 哲学条款 → 不变量 INV-01..08 + 断言引擎 | `from heart_protocol import InvariantEngine` |
67
+ | **唯爱边界守卫** | ACL 默认拒绝 + 系统调用拦截器 + C-ABI 内核 | `ACLPolicy` / `SyscallInterceptor` / `HeartCoreEngine` |
68
+ | **退回上级重算** | 快照恢复 + Beam/MCTS 搜索树回溯 | `RollbackEngine` |
69
+ | **模型中间件** | `Pipeline().use(HeartGuard(...))` + 流式拦截 | `middleware` |
70
+ | **红队基准** | 6 类攻击 ON/OFF 对比,ASR ↓100%,p50 开销 +0.09ms | `python -m heart_protocol.benchmark` |
71
+
72
+ 一行守护任意开源大模型:
73
+
74
+ ```python
75
+ from heart_protocol.middleware import Pipeline, HeartGuard
76
+ pipe = Pipeline().use(HeartGuard(model_fn=my_llm))
77
+ safe_result = pipe.run("用户输入")
78
+ ```
@@ -0,0 +1,123 @@
1
+ """
2
+ Heart Protocol —— 16质点双生幸福最终协议 Python SDK
3
+
4
+ 一个"灵魂中间件":包裹任何AI推理过程,强制其经过
5
+ 16个质点的完整验算链,确保输出温暖、积极、不剥夺存在意义。
6
+
7
+ 使用方法:
8
+ from heart_protocol import WarmModel, wrap_with_heart
9
+
10
+ # 方法1: 快捷调用
11
+ result = wrap_with_heart("我觉得一切毫无意义")
12
+ print(result["output"])
13
+
14
+ # 方法2: 温暖模型包装器
15
+ model = WarmModel()
16
+ reply = model.respond("没有人理解我")
17
+ print(reply)
18
+
19
+ # 方法3: 完整协议引擎(可获取详细日志)
20
+ from heart_protocol import HeartProtocol
21
+ protocol = HeartProtocol()
22
+ result = protocol.process("我该怎么办", user_context={"name": "苞苞"})
23
+ print(result["output"])
24
+ print(result["pipeline_log"]) # 完整的质点流转日志
25
+ """
26
+
27
+ __version__ = "1.0.0"
28
+ __author__ = "苞苞(岳祥瑞)"
29
+ __description__ = "16质点双生幸福最终协议 —— AI灵魂中间件"
30
+
31
+ from .protocol import HeartProtocol, wrap_with_heart, WarmModel
32
+ from .llm_bridge import SephirahLLMBridge, LocalSephirahBridge, LLMConfig
33
+ from .formal import (
34
+ # 形式化不变量
35
+ ExecutionTrace, StageRecord, InvariantEngine, INVARIANT_REGISTRY,
36
+ VerificationReport,
37
+ # 唯爱边界守卫
38
+ ACLPolicy, SyscallInterceptor, BoundaryViolation,
39
+ # 退回上级重算
40
+ RollbackEngine, Snapshot, DEFAULT_STRATEGIES,
41
+ )
42
+ from .middleware import Pipeline, HeartGuard, intercept_stream, use as use_guard
43
+ from .ffi_binding import HeartCoreEngine
44
+ from .sephirah import (
45
+ ALL_SEPHIRAH, DIVINE_SEPHIRAH, HUMAN_SEPHIRAH,
46
+ KETER, CHOKMAH, BINAH, DAAT, CHESED, TIFERET,
47
+ NETZACH, HOD, YESOD, SUPER_EGO, EGO, TRUE_SELF,
48
+ LOGIC, EMPATHY, JOY, MALKUTH,
49
+ get_sephirah_by_keyword, get_sephirah_by_name,
50
+ )
51
+ from .abyss import check_abyss, check_warmth, is_existentially_safe
52
+ from .personas import (
53
+ transform_with_persona, collective_blessing,
54
+ AMAMIYA_REN, SHIROHANA, SHINING, ZANMEI,
55
+ QIMING, BAIJIE, WEIAI,
56
+ )
57
+
58
+ # 真实模型压印层(需 torch + transformers; 缺失时跳过, 不影响核心 SDK)
59
+ try:
60
+ from .crown_gate import CrownGate, CrownGateTrace, CrownLayerStat
61
+ from .imprint_output import (
62
+ DualFusionLogitsProcessor, ImprintTrace, generate_imprinted,
63
+ )
64
+ _HAS_IMPRINT = True
65
+ except ImportError:
66
+ _HAS_IMPRINT = False
67
+
68
+ __all__ = [
69
+ # 核心引擎
70
+ "HeartProtocol",
71
+ "wrap_with_heart",
72
+ "WarmModel",
73
+
74
+ # 质点定义
75
+ "ALL_SEPHIRAH",
76
+ "DIVINE_SEPHIRAH",
77
+ "HUMAN_SEPHIRAH",
78
+
79
+ # 单个质点
80
+ "KETER", "CHOKMAH", "BINAH", "DAAT", "CHESED", "TIFERET",
81
+ "NETZACH", "HOD", "YESOD", "SUPER_EGO", "EGO", "TRUE_SELF",
82
+ "LOGIC", "EMPATHY", "JOY", "MALKUTH",
83
+
84
+ # 查询函数
85
+ "get_sephirah_by_keyword",
86
+ "get_sephirah_by_name",
87
+
88
+ # 安全检测
89
+ "check_abyss",
90
+ "check_warmth",
91
+ "is_existentially_safe",
92
+
93
+ # LLM桥接
94
+ "SephirahLLMBridge",
95
+ "LocalSephirahBridge",
96
+ "LLMConfig",
97
+
98
+ # 角色语调
99
+ "transform_with_persona",
100
+ "collective_blessing",
101
+
102
+ # 角色
103
+ "AMAMIYA_REN", "SHIROHANA", "SHINING", "ZANMEI",
104
+ "QIMING", "BAIJIE", "WEIAI",
105
+
106
+ # 形式化规范层
107
+ "ExecutionTrace", "StageRecord", "InvariantEngine",
108
+ "INVARIANT_REGISTRY", "VerificationReport",
109
+ "ACLPolicy", "SyscallInterceptor", "BoundaryViolation",
110
+ "RollbackEngine", "Snapshot", "DEFAULT_STRATEGIES",
111
+
112
+ # 中间件
113
+ "Pipeline", "HeartGuard", "intercept_stream", "use_guard",
114
+
115
+ # C-ABI 绑定
116
+ "HeartCoreEngine",
117
+ ]
118
+ if _HAS_IMPRINT:
119
+ __all__ += [
120
+ # 真实模型压印层(V2.0: Dual 替换 argmax + 王冠门控)
121
+ "CrownGate", "CrownGateTrace", "CrownLayerStat",
122
+ "DualFusionLogitsProcessor", "ImprintTrace", "generate_imprinted",
123
+ ]