nyx-memory 3.4.2__tar.gz

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 (99) hide show
  1. nyx_memory-3.4.2/LICENSE +21 -0
  2. nyx_memory-3.4.2/PKG-INFO +444 -0
  3. nyx_memory-3.4.2/README.md +410 -0
  4. nyx_memory-3.4.2/nexsandglass/__init__.py +113 -0
  5. nyx_memory-3.4.2/nexsandglass/core/__init__.py +67 -0
  6. nyx_memory-3.4.2/nexsandglass/core/embedding_provider.py +176 -0
  7. nyx_memory-3.4.2/nexsandglass/core/emotion_vocab.py +186 -0
  8. nyx_memory-3.4.2/nexsandglass/core/l0_buffer.py +75 -0
  9. nyx_memory-3.4.2/nexsandglass/core/llm_extract.py +81 -0
  10. nyx_memory-3.4.2/nexsandglass/core/memory_provider.py +591 -0
  11. nyx_memory-3.4.2/nexsandglass/core/sandglass.py +75 -0
  12. nyx_memory-3.4.2/nexsandglass/core/sandglass_archive.py +149 -0
  13. nyx_memory-3.4.2/nexsandglass/core/sandglass_log.py +124 -0
  14. nyx_memory-3.4.2/nexsandglass/core/sandglass_paths.py +41 -0
  15. nyx_memory-3.4.2/nexsandglass/core/sandglass_sqlite.py +163 -0
  16. nyx_memory-3.4.2/nexsandglass/core/search_router.py +304 -0
  17. nyx_memory-3.4.2/nexsandglass/core/vector_search.py +94 -0
  18. nyx_memory-3.4.2/nexsandglass/core/vector_store.py +227 -0
  19. nyx_memory-3.4.2/nexsandglass/engram/__init__.py +126 -0
  20. nyx_memory-3.4.2/nexsandglass/engram/bridge.py +272 -0
  21. nyx_memory-3.4.2/nexsandglass/engram/context.py +194 -0
  22. nyx_memory-3.4.2/nexsandglass/engram/decay.py +278 -0
  23. nyx_memory-3.4.2/nexsandglass/engram/dream_pipeline.py +242 -0
  24. nyx_memory-3.4.2/nexsandglass/engram/evolve.py +143 -0
  25. nyx_memory-3.4.2/nexsandglass/engram/loops/__init__.py +67 -0
  26. nyx_memory-3.4.2/nexsandglass/engram/loops/dream_engram.py +160 -0
  27. nyx_memory-3.4.2/nexsandglass/engram/loops/fact_thread.py +195 -0
  28. nyx_memory-3.4.2/nexsandglass/engram/loops/persona_ctx.py +137 -0
  29. nyx_memory-3.4.2/nexsandglass/engram/loops/recall_writer.py +173 -0
  30. nyx_memory-3.4.2/nexsandglass/engram/loops/temporal_fact.py +272 -0
  31. nyx_memory-3.4.2/nexsandglass/engram/types.py +295 -0
  32. nyx_memory-3.4.2/nexsandglass/engram/writer.py +240 -0
  33. nyx_memory-3.4.2/nexsandglass/features/__init__.py +112 -0
  34. nyx_memory-3.4.2/nexsandglass/features/decision_particles.py +715 -0
  35. nyx_memory-3.4.2/nexsandglass/features/multi_analysis.py +264 -0
  36. nyx_memory-3.4.2/nexsandglass/features/nightwatch.py +151 -0
  37. nyx_memory-3.4.2/nexsandglass/features/pulse.py +328 -0
  38. nyx_memory-3.4.2/nexsandglass/features/sandglass_chroma.py +103 -0
  39. nyx_memory-3.4.2/nexsandglass/features/sandglass_think.py +1505 -0
  40. nyx_memory-3.4.2/nexsandglass/features/sandglass_vault.py +561 -0
  41. nyx_memory-3.4.2/nexsandglass/features/shadow_sand.py +243 -0
  42. nyx_memory-3.4.2/nexsandglass/features/soul_diff.py +112 -0
  43. nyx_memory-3.4.2/nexsandglass/features/weavethread.py +328 -0
  44. nyx_memory-3.4.2/nexsandglass/interfaces/__init__.py +5 -0
  45. nyx_memory-3.4.2/nexsandglass/interfaces/nexsandglass.py +123 -0
  46. nyx_memory-3.4.2/nexsandglass/interfaces/nyx.py +444 -0
  47. nyx_memory-3.4.2/nexsandglass/interfaces/plugin.py +59 -0
  48. nyx_memory-3.4.2/nexsandglass/interfaces/sandglass_mcp.py +391 -0
  49. nyx_memory-3.4.2/nexsandglass/l3/__init__.py +113 -0
  50. nyx_memory-3.4.2/nexsandglass/l3/emotion_l3.py +429 -0
  51. nyx_memory-3.4.2/nexsandglass/l3/l3_persona.py +124 -0
  52. nyx_memory-3.4.2/nexsandglass/l3/l3_persona_verify.py +143 -0
  53. nyx_memory-3.4.2/nexsandglass/l3/l3_search_core.py +513 -0
  54. nyx_memory-3.4.2/nexsandglass/l3/l3_tasks.py +93 -0
  55. nyx_memory-3.4.2/nexsandglass/l3/offset_l3.py +522 -0
  56. nyx_memory-3.4.2/nexsandglass/l3/offset_signals.py +34 -0
  57. nyx_memory-3.4.2/nexsandglass/l3/persona_l3.py +626 -0
  58. nyx_memory-3.4.2/nexsandglass/l3/scene_l3.py +407 -0
  59. nyx_memory-3.4.2/nexsandglass/l3/weave_l3.py +416 -0
  60. nyx_memory-3.4.2/nexsandglass/migrate_to_chromadb.py +60 -0
  61. nyx_memory-3.4.2/nexsandglass/nyx_server.py +357 -0
  62. nyx_memory-3.4.2/nexsandglass/runtime/__init__.py +38 -0
  63. nyx_memory-3.4.2/nexsandglass/runtime/bundle.py +324 -0
  64. nyx_memory-3.4.2/nexsandglass/runtime/consolidation.py +270 -0
  65. nyx_memory-3.4.2/nexsandglass/runtime/eval.py +126 -0
  66. nyx_memory-3.4.2/nexsandglass/runtime/facade.py +357 -0
  67. nyx_memory-3.4.2/nexsandglass/runtime/intent.py +295 -0
  68. nyx_memory-3.4.2/nexsandglass/runtime/orchestrator.py +779 -0
  69. nyx_memory-3.4.2/nexsandglass/runtime/promotion.py +409 -0
  70. nyx_memory-3.4.2/nexsandglass/utils/__init__.py +19 -0
  71. nyx_memory-3.4.2/nexsandglass/utils/discipline.py +66 -0
  72. nyx_memory-3.4.2/nexsandglass/utils/heartbeat.py +104 -0
  73. nyx_memory-3.4.2/nyx_memory.egg-info/PKG-INFO +444 -0
  74. nyx_memory-3.4.2/nyx_memory.egg-info/SOURCES.txt +97 -0
  75. nyx_memory-3.4.2/nyx_memory.egg-info/dependency_links.txt +1 -0
  76. nyx_memory-3.4.2/nyx_memory.egg-info/requires.txt +19 -0
  77. nyx_memory-3.4.2/nyx_memory.egg-info/top_level.txt +1 -0
  78. nyx_memory-3.4.2/pyproject.toml +41 -0
  79. nyx_memory-3.4.2/setup.cfg +4 -0
  80. nyx_memory-3.4.2/tests/test_engram_bundle.py +162 -0
  81. nyx_memory-3.4.2/tests/test_engram_cognitive.py +193 -0
  82. nyx_memory-3.4.2/tests/test_engram_cognitive_os.py +193 -0
  83. nyx_memory-3.4.2/tests/test_engram_consolidation.py +107 -0
  84. nyx_memory-3.4.2/tests/test_engram_dream.py +171 -0
  85. nyx_memory-3.4.2/tests/test_engram_fusion.py +271 -0
  86. nyx_memory-3.4.2/tests/test_engram_intent.py +136 -0
  87. nyx_memory-3.4.2/tests/test_engram_loops.py +274 -0
  88. nyx_memory-3.4.2/tests/test_engram_orchestrator.py +172 -0
  89. nyx_memory-3.4.2/tests/test_engram_promotion.py +164 -0
  90. nyx_memory-3.4.2/tests/test_engram_temporal.py +122 -0
  91. nyx_memory-3.4.2/tests/test_eval_temporal.py +195 -0
  92. nyx_memory-3.4.2/tests/test_nyx_server.py +143 -0
  93. nyx_memory-3.4.2/tests/test_runtime_api.py +120 -0
  94. nyx_memory-3.4.2/tests/test_runtime_b1.py +139 -0
  95. nyx_memory-3.4.2/tests/test_runtime_b2.py +123 -0
  96. nyx_memory-3.4.2/tests/test_runtime_b3.py +151 -0
  97. nyx_memory-3.4.2/tests/test_runtime_bugfixes.py +205 -0
  98. nyx_memory-3.4.2/tests/test_semantic_search.py +100 -0
  99. nyx_memory-3.4.2/tests/test_weavethread_llm.py +83 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NexSandglass
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,444 @@
1
+ Metadata-Version: 2.4
2
+ Name: nyx-memory
3
+ Version: 3.4.2
4
+ Summary: 夜神 Nyx — 跨会话记忆感知系统
5
+ Author-email: sixgod <sixgod@example.com>
6
+ License: MIT
7
+ Keywords: memory,agent,ai,knowledge-graph,dejavu
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Provides-Extra: mcp
21
+ Requires-Dist: mcp>=0.9.0; extra == "mcp"
22
+ Provides-Extra: test
23
+ Requires-Dist: pytest>=7.0; extra == "test"
24
+ Provides-Extra: vector
25
+ Requires-Dist: sentence-transformers>=2.0; extra == "vector"
26
+ Requires-Dist: numpy>=1.20; extra == "vector"
27
+ Provides-Extra: api
28
+ Requires-Dist: httpx>=0.24; extra == "api"
29
+ Provides-Extra: chroma
30
+ Requires-Dist: chromadb>=0.4; extra == "chroma"
31
+ Provides-Extra: sqlitevec
32
+ Requires-Dist: sqlite-vec>=0.1; extra == "sqlitevec"
33
+ Dynamic: license-file
34
+
35
+ # NexSandglass / Nyx(夜神)
36
+
37
+ > **夜神 Nyx — Hermes Agent 的跨会话记忆感知系统**
38
+
39
+ NexSandglass 是 Hermes Agent 的记忆基础设施,在 Hermes 原生 memory 工具关闭时接管全部跨会话记忆、事实存储、联想检索和 déjà vu 检测。
40
+
41
+ ![Python](https://img.shields.io/badge/Python-3.8%2B-3776AB?logo=python) ![License](https://img.shields.io/badge/License-MIT-green) ![Version](https://img.shields.io/badge/version-7.3-blue)
42
+
43
+ ---
44
+
45
+ ## 📋 核心能力
46
+
47
+ | 能力 | 模块 | 说明 |
48
+ |------|------|------|
49
+ | 🧠 **沙漏 Sandglass** | `core/sandglass_sqlite.py` | 长期记忆存储、全文搜索、语义搜索 |
50
+ | 🕸️ **织线 Thread** | `features/weavethread.py` | 知识图谱(实体关系三元组),支持时间窗口查询 |
51
+ | 👻 **Déjà Vu (Veil)** | `interfaces/nyx.py` | 模糊感知——"感觉聊过但检索不到"的 Bloom Filter 检测 + 寻回(nyx_hunt) |
52
+ | 🏜️ **影子沙 Fact Store** | `features/shadow_sand.py` | 结构化事实存储(带信任评分) |
53
+ | 📊 **情绪/画像** | `core/emotion_vocab.py`, `l3/persona_l3.py` | 用户状态追踪、偏移率计算、回音折 |
54
+ | 🌙 **梦境 Dream** | `dream/` | 夜间多阶段复盘:记忆整理、反思成长、创造联结 |
55
+ | 🔍 **语义检索** | `core/embedding_provider.py`, `core/vector_search.py` | 真正的向量语义检索(本地多语言模型 + RRF 混合,v3.4.0) |
56
+ | 🤖 **LLM 图谱抽取** | `core/llm_extract.py`, `features/weavethread.py` | 可选 LLM 知识图谱补充抽取 + 实体归一化(可降级,v3.4.0) |
57
+ | 🔌 **MCP 接口** | `interfaces/sandglass_mcp.py`, `interfaces/nyx.py` | MCP 工具接入 Hermes / Claude |
58
+ | 🧬 **记忆加工** | `engram/types.py`, `engram/decay.py` | Tulving 四类记忆 + Ebbinghaus 衰减(EngramTide 融合) |
59
+ | 🧬 **差异化写入** | `engram/writer.py` | semantic 覆盖 / emotional 强化 / procedural 去重 / episodic 直插 |
60
+ | 🧬 **Constitutional** | `engram/context.py` | 记忆融入 system prompt 隐性影响(自然无痕) |
61
+ | 🔄 **记忆自我演化** | `engram/evolve.py`, `engram/loops/` | 四闭环:事实↔图谱、梦境→加工、画像→上下文、召回→重要性 |
62
+ | 🌙 **梦境管线** | `engram/dream_pipeline.py`, `engram/prompts/` | hypnos 三女神融合:浅睡总结→深睡内化→灵感联结 |
63
+ | 🎛️ **热路径收编** | `runtime/orchestrator.py` | NyxOrchestrator:写入/召回统一入口,包住底层引擎 |
64
+ | 🧭 **意图召回** | `runtime/intent.py` | MemoryIntent 自适应召回(v5.0),语义/时间/领域/关系感知排序 |
65
+ | 📦 **记忆 Bundle** | `runtime/bundle.py` | MemoryBundle 合并两套出口(Constitutional + system_prompt),10 槽位 |
66
+ | 🌱 **候选晋升** | `runtime/promotion.py` | "什么值得记住"——Observation→Extract→Score→Type→Promote/Session/Drop |
67
+ | 🕰️ **时序事实** | `engram/loops/temporal_fact.py` | current_only / as_of / history_of 演变链,不静默覆盖 |
68
+ | 🌙 **Consolidation Engine** | `runtime/consolidation.py` | Dream 生产化:Proposal→Validator→Apply/Quarantine + 快照回滚 |
69
+ | 🧭 **Cognitive OS 端到端** | `runtime/eval.py`, `orchestrator.cognitive_recall` | Formation→Store→Dream→Intent→Bundle→Context→Agent 全链路 |
70
+
71
+ ---
72
+
73
+ ## ✨ 新增能力(Phase 0-7, v4-v7)
74
+
75
+ > 在原有记忆基础设施之上,新增的"认知记忆"层次,解决 **What to remember / What to recall now / How memory changed** 三问。
76
+
77
+ ### 🎛️ 稳定门面 + 热路径收编(Phase 0-1)
78
+ - `runtime/facade.py`:四个稳定操作 `observe / recall / feedback / forget`,对外不暴露实现细节
79
+ - `runtime/orchestrator.py`:`NyxOrchestrator` 收编所有热路径——写入经 `FormationRouter`,读取经 `RecallPlanner`
80
+ - 禁止新代码直写内部表(dev escape hatch 打日志);MCP 工具仍可暴露但内部转 orchestrator
81
+
82
+ ### 🧭 意图感知自适应召回(Phase 4, v5.0)
83
+ - `runtime/intent.py`:`MemoryIntent` 解析 entities / temporal / domain / relation / types / current|history
84
+ - 策略路由:ownership+vehicle+previous → 多源;熟悉但搜不到 → nyx_hunt;generic → SearchRouter 混合
85
+ - 多因子排序:semantic / temporal_validity / importance / confidence / recency / lifecycle_penalty / trust
86
+ - 意图失败自动降级 generic_semantic;**包住而非替换** SearchRouter
87
+
88
+ ### 📦 MemoryBundle 合并出口(Phase 3)
89
+ - `runtime/bundle.py`:把 engram Constitutional + Provider system_prompt 两套出口统一为 10 槽位 Bundle
90
+ - `core_facts / preferences / current_thread / historical_events / related_memories / contradictions / confidence_summary / temporal_state / persona_layer / offset_layer / open_loops`
91
+ - 流水线:candidates → score → temporal → budget → compress → render;`utility = relevance/token_cost`
92
+
93
+ ### 🌱 候选晋升(Phase 4 记忆选择)
94
+ - `runtime/promotion.py`:替代默认"整轮 dump",只晋升值得长期记住的
95
+ - 复用 engram.writer 差异化策略(override/reinforce/dedup/insert)
96
+ - 重复→reinforce 不双写;冲突→conflict candidate 不静默覆盖;闲聊/OTP 不晋升
97
+
98
+ ### 🕰️ 时序事实(Phase 5, v6.0)
99
+ - `engram/loops/temporal_fact.py`:`get_current / as_of / history_of / evolution_chain`
100
+ - 写入新值 → 旧值 valid_until=now + historical,新值 active + 链接;禁止静默覆盖
101
+ - Golden:2025 Tesla → 2026 Geely,现在 vs 以前答案不同
102
+
103
+ ### 🌙 Dream 生产化(Phase 6, v6.5)
104
+ - `runtime/consolidation.py`:所有变更 → DreamProposal → Validator → Apply/Quarantine
105
+ - 保留 provenance(source memory ids);destructive merge 可回滚快照
106
+ - 压缩/抽象/关系/冲突/衰减;冲突写入 Bundle.contradictions;异步调度不阻塞热路径
107
+
108
+ ### 🧭 Cognitive OS 端到端(Phase 7, v7.0)
109
+ - `orchestrator.cognitive_recall()`:Formation→Store/Graph→Dream async→Intent Recall→Bundle→Context→Agent
110
+ - `runtime/eval.py`:formation P/R、temporal accuracy、token utility、p95 latency
111
+ - MCP 统一入口 `memory_observe / memory_recall / memory_feedback / memory_forget`(旧工具保留作适配层)
112
+
113
+ ---
114
+
115
+ ## 📦 包结构
116
+
117
+ ```
118
+ nexsandglass/
119
+ ├── core/ # 基础设施
120
+ │ ├── embedding_provider.py # 语义向量后端(本地/外部 API,Task 1)
121
+ │ ├── vector_store.py # 向量存储(JSON/sqlite-vec,Task 1)
122
+ │ ├── vector_search.py # 向量语义检索 + RRF 融合(Task 1)
123
+ │ ├── search_router.py # 检索路由器(五路混合排序)
124
+ │ ├── llm_extract.py # 可选 LLM 抽取接口(Task 2)
125
+ │ ├── sandglass_sqlite.py # SQLite 沙漏存储
126
+ │ ├── sandglass_paths.py # 数据路径管理
127
+ │ ├── sandglass_archive.py # 记忆归档
128
+ │ ├── l0_buffer.py # L0 缓冲层
129
+ │ ├── emotion_vocab.py # 情绪词库
130
+ ├── interfaces/ # 对外接口
131
+ │ ├── nexsandglass.py # 主接口
132
+ │ ├── nyx.py # Nyx 适配层(含 Veil Bloom Filter + Déjà Vu 寻回)
133
+ │ ├── sandglass_mcp.py # MCP 工具
134
+ │ └── plugin.py # 插件接口
135
+ ├── features/ # 特性模块
136
+ │ ├── weavethread.py # 知识图谱(正则 + 可选 LLM 抽取,Task 2)
137
+ │ ├── shadow_sand.py # 结构化事实存储(信任评分)
138
+ │ ├── sandglass_vault.py # 沙漏索引检索
139
+ │ ├── soul_diff.py # 灵魂差分导出/迁移
140
+ │ ├── nightwatch.py # 夜间值守
141
+ │ └── ... # decision_particles/multi_analysis/pulse/think
142
+ ├── l3/ # L3 层(高级记忆)
143
+ │ ├── persona_l3.py # 画像构建
144
+ │ ├── l3_search_core.py # SimHash/搜索核心
145
+ │ └── ... # tasks/emotion/scene/offset/weave/arch
146
+ ├── engram/ # 🧬 EngramTide 融合层(记忆加工)
147
+ │ ├── types.py # Tulving 四类记忆
148
+ │ ├── decay.py # Ebbinghaus 衰减 + 浮现 + 激活
149
+ │ ├── writer.py # 差异化写入 + embedding 计算(Task 1)
150
+ │ ├── context.py # Constitutional 上下文
151
+ │ ├── evolve.py # 演化协调器
152
+ │ ├── dream_pipeline.py # 🌙 梦境管线(hypnos 融合)
153
+ │ ├── prompts/ # 三女神 prompt(Mnemosyne/Epimetheus/Prometheus)
154
+ │ └── loops/ # 四闭环(事实↔图谱/梦境↔加工/画像↔上下文/召回↔重要性)
155
+ └── utils/ # 工具
156
+ ├── heartbeat.py # 心跳
157
+ └── discipline.py # 纪律约束```
158
+
159
+ ---
160
+
161
+ ## 📊 Benchmark
162
+
163
+ 基于 `tests/eval/run_eval.py` 运行的记忆系统评测(测试集 60 条,top-k=5):
164
+
165
+ | 指标 | 结果 |
166
+ |------|------|
167
+ | 词法检索召回率 | 75.00% |
168
+ | Episodic 记忆 30 天衰减后权重 | 22.31% |
169
+ | 评测脚本 | `tests/eval/run_eval.py` |
170
+
171
+ >注:混合检索(词法+RRF向量)需要安装 `[vector]` 或 `[chroma]` 额外依赖后运行。
172
+
173
+ ---
174
+
175
+ ## 🚀 安装
176
+
177
+ ### 方式一:pip 安装(推荐)
178
+
179
+ ```bash
180
+ pip install nexsandglass
181
+ ```
182
+
183
+ 带 MCP 支持:
184
+
185
+ ```bash
186
+ pip install "nexsandglass[mcp]"
187
+ ```
188
+
189
+ 带向量语义检索:
190
+
191
+ ```bash
192
+ pip install "nexsandglass[vector,chroma]"
193
+ ```
194
+
195
+ ### 方式二:直接安装
196
+
197
+ ```bash
198
+ # Linux / macOS
199
+ ./install.sh
200
+
201
+ # Windows
202
+ install.bat
203
+ ```
204
+
205
+ ### 方式三:Docker
206
+
207
+ ```bash
208
+ docker compose up -d
209
+ ```
210
+
211
+ ### 方式四:作为 Hermes 技能
212
+
213
+ 技能文件位于 `skills/nyx/`,复制到 Hermes 技能目录即可自动加载:
214
+
215
+ ```bash
216
+ cp -r skills/nyx ~/.hermes/skills/memory/
217
+ ```
218
+
219
+ ---
220
+
221
+ ## 🔧 配置
222
+
223
+ `memory_bus_config.yaml`(或 Hermes `config.yaml`)示例:
224
+
225
+ ```yaml
226
+ memory:
227
+ provider: nexsandglass
228
+ memory_enabled: true
229
+ user_profile_enabled: true
230
+ nyx:
231
+ sandglass:
232
+ backend: tfidf # 或 chromadb
233
+ auto_consolidate: true
234
+ dream:
235
+ enabled: true
236
+ cron: "0 3 * * *"
237
+ dejavu:
238
+ enabled: true
239
+ sensitivity: 0.7
240
+ ```
241
+
242
+ ---
243
+
244
+ ## 🛠️ MCP 工具
245
+
246
+ | 工具 | 功能 |
247
+ |------|------|
248
+ | `sandglass_search` | 倒排索引关键词搜索 |
249
+ | `sandglass_semantic` | 语义搜索(TF-IDF / ChromaDB 后端) |
250
+ | `sandglass_recent` | 最近 N 条记忆 |
251
+ | `sandglass_persona` | 当前主人画像 |
252
+ | `sandglass_offset` | 当前偏移率(决策趋势) |
253
+ | `sandglass_echo` | 回音折(情感风向) |
254
+ | `sandglass_chart` | 情绪熵 ASCII 可视化 |
255
+ | `sandglass_dejavu` | Déjà Vu 模糊感知(check/stats/save_bf/awaken) |
256
+ | `sandglass_thread` | 织线知识图谱查询 |
257
+ | `sandglass_thread_graph` | 实体子图展开 |
258
+ | `sandglass_thread_weave` | 因果链摘要 |
259
+ | `sandglass_dream` | 幽灵决策("如果选另一个选项会怎样") |
260
+ | `sandglass_export/import` | 记忆迁移 |
261
+ | `soul_export/merge` | 灵魂差分导出/合并 |
262
+ | `fact_store` | 事实增删查(信任评分) |
263
+ | `fact_feedback` | 信任评分反馈 |
264
+ | `memory_observe` | 🆕 统一记忆写入入口(经 PromotionEngine 晋升) |
265
+ | `memory_recall` | 🆕 统一记忆召回入口(经 MemoryIntent 自适应) |
266
+ | `memory_feedback` | 🆕 统一反馈入口 |
267
+ | `memory_forget` | 🆕 统一遗忘入口 |
268
+
269
+ ---
270
+
271
+ ## 📖 使用示例
272
+
273
+ ```python
274
+ # 搜索记忆
275
+ sandglass_search(query="荷兰 BV 公司", limit=10)
276
+
277
+ # 语义搜索
278
+ sandglass_semantic(query="如何优化网络延迟", backend="tfidf")
279
+
280
+ # 查看主人画像
281
+ sandglass_persona()
282
+
283
+ # 查询知识图谱
284
+ sandglass_thread(entity="用户", relation="偏好", limit=5)
285
+
286
+ # 展开知识子图
287
+ sandglass_thread_graph(entity="Xian Delicious Foods", depth=2)
288
+
289
+ # 幽灵决策
290
+ sandglass_dream(question="如果选择另一个方案会怎样")
291
+ ```
292
+
293
+ ---
294
+
295
+ ## 📊 数据存储
296
+
297
+ | 数据 | 位置 | 格式 |
298
+ |------|------|------|
299
+ | 沙漏记忆 | `~/.hermes/sandglass/` | SQLite / JSONL |
300
+ | 织线图谱 | `~/.hermes/sandglass/thread/` | JSON(三元组) |
301
+ | 事实存储 | `~/.hermes/sandglass/facts/` | SQLite |
302
+ | Déjà Vu | `~/.hermes/sandglass/dejavu.bf` | Bloom Filter 持久化 |
303
+ | 梦境日志 | `~/.hermes/dreams/` | Markdown |
304
+
305
+ ---
306
+
307
+ ## 📝 更新日志
308
+
309
+ ### v7.3 (2026-08-27) — 3 个引擎缺陷修复(Windows 沙盒测试发现)
310
+
311
+ - 🛠️ **缺陷1** `shadow_sand` 批提交策略导致同库直写死锁:`_maybe_commit` 每累积 3 次写才 commit,
312
+ 持久连接在操作间隙仍持有 `shadow_sand.db` 写锁,阻塞同库其他连接(`resolve_temporal_conflict`
313
+ 直连 `weavethread._DB`)→ `database is locked`、写入被吞。改为**每次写操作结束立即 commit**
314
+ + `_get_conn` 加 `timeout=10` + `PRAGMA journal_mode=WAL`,移除 `_commit_pending` 计数器
315
+ - 🛠️ **缺陷2** `_Mist` 连接跨线程崩坏导致 phantom 数据静默丢失:`_drift()` 建持久连接未设
316
+ `check_same_thread=False`,跨线程用(SearchRouter/MCP)在 Python 3.11+ 抛 `ProgrammingError`
317
+ 被 `except` 吞掉。改为 `check_same_thread=False` + `_Mist` 加 `threading.RLock` 保护
318
+ `haunt/stalk/census` 及 `nyx_forget/cleanup/reindex` 全部 DB 操作
319
+ - 🛠️ **缺陷3** `temporal_fact` 隐藏依赖外部建表:`wthread_triples` 的 DDL 只在 `weavethread._ensure_table()`
320
+ 定义,第三方直接使用 temporal API(全新空库/未触发 weavethread)→ `no such table` 静默失败、
321
+ 读路径直接崩溃。新增参数化 `_ensure_table(db_path)` 并在 `resolve_temporal_conflict` 与
322
+ `ensure_temporal_columns` 内调用,使模块**自足建表**;并为 `TEMPORAL_RELATIONS` 补语义 docstring
323
+ - ✅ 3 项均以独立 ad-hoc 验证脚本复现+验证(缺陷1 5/5、缺陷2 4/4、缺陷3 6/6);全量 19 测试文件逐文件独立运行全绿
324
+
325
+ ### v7.2 (2026-08-18) — DoD 收尾:5 golden scenarios + 单一事实来源
326
+
327
+ - ✅ **DoD#7** 新增 5 个 golden scenarios 自动化验收(`tests/test_engram_cognitive_os.py`):
328
+ A. "还是按照之前那个方案" → 找回决策/约束/结论;B. 跨 session 偏好演化(Tesla→Geely);
329
+ C. 闲聊不污染长期记忆(Formation 门禁);D. token_budget 受限保留铁律/关键事实;E. 单源失败降级不崩
330
+ - ✅ 每个 golden 场景使用独立临时数据目录(`NEXSANDBASE_HOME`),不污染生产记忆、场景间不串扰
331
+ - ✅ **DoD#9** `skills/memory/nyx/SKILL.md` 收敛单一事实来源:删除历史 `scripts/engram` 副本残留引用,
332
+ 代码路径统一指向 `nexsandglass/engram`,移除"双向同步拷贝"铁律
333
+ - ✅ `test_engram_cognitive_os.py` 全绿(21 项检查 PASS)
334
+ - ✅ 9 条 Definition of Done 全部达标:唯一 API / 经 Promotion / Intent-Rank 召回 / Bundle 唯一出口 /
335
+ temporal current vs history / Dream Proposal / golden scenarios / 无双写与 NameError / 无第二套实现
336
+
337
+ ### v7.1 (2026-08-12) — runtime 脚手架修复(B0 契约 + 7 阻断 bug)
338
+
339
+ - 🛠️ **Bug1** `system_prompt_block` open_loops NameError → 不再静默 fallback 旧拼接(改用 `open_loops_layer`)
340
+ - 🛠️ **Bug2** `cognitive_recall` 误调 `intent.history_context` 实例方法 → 改用模块级函数
341
+ - 🛠️ **Bug3** `sandglass_mcp` tools/list 补声明 `memory_observe/recall/feedback/forget` 四工具
342
+ - 🛠️ **Bug4** `RecallPlanner._adapt_nyx` 对齐 `nyx_sense/hunt` 真实返回结构(phantom whisper + 熟悉度)
343
+ - 🛠️ **Bug5** `sync_turn` 与 FormationRouter 双写 sandglass → 加 `raw_already_logged` 参数,审计日志一行一次
344
+ - 🛠️ **Bug6** `facade.feedback` 传空 memories 名存实亡 → 加载匹配行并回写权重(helpful 提升 / weaken 降低)
345
+ - 🛠️ **Bug7** 删除 `skills/nyx/scripts/` 与主包分叉的 22 个副本,单一事实来源归 `nexsandglass/`
346
+ - 📄 新增 `RUNTIME.md`(B0 唯一对外 API + MemoryContext/MemoryObject 契约)+ `PR_BUGFIX.md`
347
+ - ✅ 新增 `tests/test_runtime_{api,b1,b2,b3,bugfixes}.py`;全量 19 个测试文件独立运行全绿
348
+
349
+ ### v7.0 (2026-08-12) — Cognitive Memory OS 全链路
350
+
351
+ - 🧭 **Cognitive OS 端到端**:Formation→Store/Graph→Dream async→Intent Recall→Bundle→Context→Agent
352
+ - 🧭 **评测框架** `runtime/eval.py`:formation P/R、temporal accuracy、token utility、p95 latency
353
+ - 🎛️ MCP 统一入口 `memory_observe/recall/feedback/forget`(旧工具保留适配层)
354
+
355
+ ### v6.5 (2026-08-12) — Dream 生产化
356
+
357
+ - 🌙 `runtime/consolidation.py`:DreamProposal→Validator→Apply/Quarantine + 快照回滚
358
+ - 🌙 冲突写入 Bundle.contradictions;异步调度不阻塞 observe/recall
359
+
360
+ ### v6.0 (2026-08-12) — 时序事实
361
+
362
+ - 🕰️ `engram/loops/temporal_fact.py` 融合查询 API:current_only / as_of / history_of / evolution_chain
363
+ - 🕰️ 不静默覆盖:旧值 historical + 新值 active + supersedes 链接
364
+
365
+ ### v5.0 (2026-08-12) — 意图自适应召回
366
+
367
+ - 🧭 `runtime/intent.py`:MemoryIntent 解析 + 策略路由 + 多因子排序
368
+ - 🧭 意图失败降级 generic_semantic;包住 SearchRouter
369
+
370
+ ### v4.0 (2026-08-12) — 候选晋升
371
+
372
+ - 🌱 `runtime/promotion.py`:Observation→Extract→Score→Type→Promote/SessionOnly/Drop
373
+ - 🌱 重复→reinforce;冲突→conflict candidate;闲聊/OTP 不晋升
374
+
375
+ ### v3.5.0 (2026-08-12) — 稳定门面 + 热路径收编
376
+
377
+ - 🎛️ `runtime/facade.py`:observe/recall/feedback/forget 稳定门面
378
+ - 🎛️ `runtime/orchestrator.py`:NyxOrchestrator 收编热路径(FormationRouter/RecallPlanner)
379
+ - 📦 `runtime/bundle.py`:MemoryBundle 合并两套出口
380
+ - 🧬 `engram/types.py`:MemoryObject canonical schema + lifecycle 状态机
381
+
382
+ ### v3.4.1 (2026-08-01) — 评测框架补全
383
+
384
+ - 📊 评测测试集扩充至 **60 条**(fact_exact 10 / fact_semantic 15 / cross_session 10 / emotional 8 / procedural 8 / tech 9)
385
+ - 📊 run_eval.py 词法对比真实接入(token 重叠检索),产出**具体数字**:
386
+ - 首轮评测:60 条测试集词法召回率 **75%**,衰减系数 0.223(30 天 episodic)
387
+ - 报告模板:`tests/eval/latest_report.md`
388
+ - 混合检索对比支持注入向量组件后自动启用(RRF 融合)
389
+
390
+ ### v3.4.0 (2026-08-01) — 审查问题修复
391
+
392
+ - 🔍 **真正的语义检索**(Task 1):新增 `core/embedding_provider.py`(本地 sentence-transformers + 外部 API 可插拔)、`core/vector_store.py`(JSON/sqlite-vec 后端)、`core/vector_search.py`(向量检索 + RRF 融合);SearchRouter 新增第五路向量检索,与现有四路做混合排序;`engram/writer.py` 写入时自动计算 embedding
393
+ - 🤖 **LLM 知识图谱抽取**(Task 2):新增 `core/llm_extract.py`(可选接口);`features/weavethread.py` 新增 `wthread_extract_with_source`(regex/llm 来源标注)和 `wthread_extract_llm`(可降级 LLM 补充抽取);环境变量 `WTHREAD_LLM_EXTRACTION=1` 开启,关闭时纯正则
394
+ - 📝 **文档修复**(Task 3):README 包结构替换虚构路径(core/thread_*.py→features/weavethread.py, core/fact_store.py→features/shadow_sand.py, core/persona.py→l3/persona_l3.py);修正 Déjà Vu 描述(明确实现在 interfaces/nyx.py 的 _Veil Bloom Filter + nyx_hunt 寻回)
395
+
396
+ ### v3.3.0 (2026-07-31) — 🌙 hypnos 梦境融合
397
+
398
+ - 🌙 新增 `engram/dream_pipeline.py`:hypnos 三女神流程并入 Nyx 梦境
399
+ - 🌙 Mnemosyne 浅睡总结(prompt + 规则兜底)/ Epimetheus 深睡内化(确定性代码)/ Prometheus 灵感联结
400
+ - 🌙 新增 `engram/prompts/`:hypnos 三女神 prompt 资产入库
401
+ - 📝 README/SKILL.md 更新:梦境管线章节 + 融合设计文档
402
+
403
+ ### v3.2.0 (2026-07-31) — 🔄 记忆自我演化
404
+
405
+ - 🔄 新增 `engram/loops/` 四闭环 + `engram/evolve.py` 演化协调器
406
+ - 🔄 闭环1 Thread↔FactStore:事实→图谱自动更新,图谱反向验证冲突
407
+ - 🔄 闭环2 Dream↔Engram:梦境触发重分类(≥3次提炼)/合并/关系发现
408
+ - 🔄 闭环3 Persona↔Context:画像确认事实加权,字段变更触发重建
409
+ - 🔄 闭环4 Recall↔Writer:成功召回提升重要性,长期无关加速衰减
410
+ - 📝 README/SKILL.md 更新:演化闭环章节 + 设计文档
411
+
412
+ ### v3.1.0 (2026-07-31) — 🧬 EngramTide 融合
413
+
414
+ - 🧬 新增 `nexsandglass/engram/` 记忆加工层(types / decay / writer / context)
415
+ - 🧠 Tulving 四类记忆:semantic / episodic / emotional / procedural 差异化写入
416
+ - ⏳ Ebbinghaus 指数衰减:episodic/emotional 衰减,DECAY_FLOOR 永不归零
417
+ - 📤 分层浮现 R1-R4:规则 > 高唤醒情绪 > 未解决 > 近期事件
418
+ - ⚡ 逐轮激活:当前输入相似记忆 boost(封顶 1.0)
419
+ - 📜 Constitutional 上下文:记忆隐性影响回复,严禁暴露机械检索
420
+ - 📝 README 更新:包结构 + 核心能力表加入融合层
421
+
422
+ ### v3.0.0 (2026-07-31)
423
+
424
+ - 🔄 重构为模块化包结构(core / interfaces / utils / features / l3)
425
+ - 🧠 技能层同步:`skills/nyx/` 完整纳入仓库(SKILL.md + 14 篇参考文档)
426
+ - 📝 README 重写:新增架构说明、MCP 工具表、使用示例
427
+ - 🐛 修复 `_fail_open` 装饰器循环导入问题
428
+ - 🔀 合并远端文件(nyx.py、PROTOCOL.md、demo/)
429
+
430
+ ### 早期版本
431
+
432
+ - v2.9.9:雷军 TOCTOU 修复(Lock + 元组原子赋值)
433
+ - v2.9.9:词库自生长修复(马云 + 托尼双审)
434
+ - 基础沙漏记忆存储与检索
435
+
436
+ ---
437
+
438
+ ## 📄 License
439
+
440
+ MIT License
441
+
442
+ ---
443
+
444
+ **Made with 🧠 by Nyx — 夜神记忆感知系统**