dsh-biocore 0.1.0 → 0.1.2

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 (250) hide show
  1. package/README.md +2 -2
  2. package/lib/py/bridge.py +15 -7
  3. package/lib/py-bridge.js +4 -3
  4. package/package.json +3 -2
  5. package/python/biocore_memory/__init__.py +21 -0
  6. package/python/biocore_memory/adapters/__init__.py +2 -0
  7. package/python/biocore_memory/adapters/astrbot.py +24 -0
  8. package/python/biocore_memory/adapters/dsh_cli.py +335 -0
  9. package/python/biocore_memory/co_recall.py +324 -0
  10. package/python/biocore_memory/consolidate/__init__.py +11 -0
  11. package/python/biocore_memory/consolidate/gated.py +104 -0
  12. package/python/biocore_memory/consolidate/neighbors.py +68 -0
  13. package/python/biocore_memory/consolidate/reflection.py +45 -0
  14. package/python/biocore_memory/consolidate/tree.py +95 -0
  15. package/python/biocore_memory/consolidate/writeback.py +181 -0
  16. package/python/biocore_memory/core/__init__.py +4 -0
  17. package/python/biocore_memory/core/config.py +127 -0
  18. package/python/biocore_memory/core/permissions.py +69 -0
  19. package/python/biocore_memory/core/types.py +116 -0
  20. package/python/biocore_memory/core/util.py +26 -0
  21. package/python/biocore_memory/embedding_local.py +447 -0
  22. package/python/biocore_memory/embedding_mode.py +156 -0
  23. package/python/biocore_memory/engine.py +2476 -0
  24. package/python/biocore_memory/engine_helpers.py +266 -0
  25. package/python/biocore_memory/event/__init__.py +3 -0
  26. package/python/biocore_memory/event/_types.py +16 -0
  27. package/python/biocore_memory/event/consistency.py +117 -0
  28. package/python/biocore_memory/event/extract.py +48 -0
  29. package/python/biocore_memory/event/media.py +111 -0
  30. package/python/biocore_memory/event/notes.py +85 -0
  31. package/python/biocore_memory/event/notes_link.py +87 -0
  32. package/python/biocore_memory/event/vector.py +69 -0
  33. package/python/biocore_memory/evict/__init__.py +3 -0
  34. package/python/biocore_memory/evict/adaptive.py +73 -0
  35. package/python/biocore_memory/evict/consequence.py +58 -0
  36. package/python/biocore_memory/evict/heat.py +54 -0
  37. package/python/biocore_memory/evict/inhibition.py +105 -0
  38. package/python/biocore_memory/evict/policy.py +188 -0
  39. package/python/biocore_memory/evict/score.py +23 -0
  40. package/python/biocore_memory/identity/__init__.py +6 -0
  41. package/python/biocore_memory/identity/api.py +99 -0
  42. package/python/biocore_memory/identity/history.py +9 -0
  43. package/python/biocore_memory/identity/ledger.py +191 -0
  44. package/python/biocore_memory/identity/narrative.py +358 -0
  45. package/python/biocore_memory/identity/snapshot.py +13 -0
  46. package/python/biocore_memory/identity/writeback.py +61 -0
  47. package/python/biocore_memory/index/__init__.py +3 -0
  48. package/python/biocore_memory/index/cue_index.py +80 -0
  49. package/python/biocore_memory/index/entities.py +85 -0
  50. package/python/biocore_memory/index/entity_boost.py +104 -0
  51. package/python/biocore_memory/index/graph.py +172 -0
  52. package/python/biocore_memory/recall/__init__.py +5 -0
  53. package/python/biocore_memory/recall/api.py +65 -0
  54. package/python/biocore_memory/recall/bm25.py +118 -0
  55. package/python/biocore_memory/recall/channels.py +98 -0
  56. package/python/biocore_memory/recall/complexity.py +62 -0
  57. package/python/biocore_memory/recall/constraints.py +75 -0
  58. package/python/biocore_memory/recall/embedding.py +745 -0
  59. package/python/biocore_memory/recall/expand.py +26 -0
  60. package/python/biocore_memory/recall/filters.py +40 -0
  61. package/python/biocore_memory/recall/fusion.py +18 -0
  62. package/python/biocore_memory/recall/mmr.py +70 -0
  63. package/python/biocore_memory/recall/ppr.py +85 -0
  64. package/python/biocore_memory/recall/retrieval_practice.py +102 -0
  65. package/python/biocore_memory/relay/__init__.py +2 -0
  66. package/python/biocore_memory/relay/card.py +51 -0
  67. package/python/biocore_memory/slots/__init__.py +18 -0
  68. package/python/biocore_memory/slots/admission.py +64 -0
  69. package/python/biocore_memory/slots/boundary.py +128 -0
  70. package/python/biocore_memory/slots/evict_bridge.py +106 -0
  71. package/python/biocore_memory/slots/registry.py +135 -0
  72. package/python/biocore_memory/slots/switch.py +42 -0
  73. package/python/biocore_memory/store/__init__.py +4 -0
  74. package/python/biocore_memory/store/audit.py +74 -0
  75. package/python/biocore_memory/store/compress.py +81 -0
  76. package/python/biocore_memory/store/dedupe.py +178 -0
  77. package/python/biocore_memory/store/json_store.py +154 -0
  78. package/python/biocore_memory/store/media.py +145 -0
  79. package/python/biocore_memory/store/provenance.py +73 -0
  80. package/python/biocore_memory/store/rate_limit.py +93 -0
  81. package/python/biocore_memory/store/security.py +107 -0
  82. package/python/biocore_memory/store/source_consistency.py +123 -0
  83. package/python/biocore_memory/store/tiering.py +61 -0
  84. package/python/biocore_memory/store/tiering_exec.py +50 -0
  85. package/python/biocore_memory/store/tombstone.py +23 -0
  86. package/python/biocore_memory/store/versions.py +69 -0
  87. package/python/biocore_memory/thread/__init__.py +2 -0
  88. package/python/biocore_memory/thread/card.py +58 -0
  89. package/python/biocore_model/__init__.py +37 -0
  90. package/python/biocore_model/affective_labor.py +162 -0
  91. package/python/biocore_model/appraisal.py +257 -0
  92. package/python/biocore_model/appraisal_action.py +78 -0
  93. package/python/biocore_model/archive_queue.py +60 -0
  94. package/python/biocore_model/attachment_behavior.py +130 -0
  95. package/python/biocore_model/attachment_regulation.py +75 -0
  96. package/python/biocore_model/attachment_state.py +41 -0
  97. package/python/biocore_model/attribution.py +73 -0
  98. package/python/biocore_model/attributor.py +162 -0
  99. package/python/biocore_model/autonomic.py +91 -0
  100. package/python/biocore_model/autonomy_affect.py +51 -0
  101. package/python/biocore_model/autonomy_check.py +67 -0
  102. package/python/biocore_model/autonomy_loop.py +122 -0
  103. package/python/biocore_model/autonomy_mode.py +114 -0
  104. package/python/biocore_model/autonomy_model.py +733 -0
  105. package/python/biocore_model/autonomy_params.py +131 -0
  106. package/python/biocore_model/autonomy_reason.py +73 -0
  107. package/python/biocore_model/autonomy_tick.py +227 -0
  108. package/python/biocore_model/bio_appraisal.py +49 -0
  109. package/python/biocore_model/bio_autonomy_state.py +171 -0
  110. package/python/biocore_model/bio_config.py +221 -0
  111. package/python/biocore_model/bio_const.py +128 -0
  112. package/python/biocore_model/bio_daily.py +267 -0
  113. package/python/biocore_model/bio_emotion.py +538 -0
  114. package/python/biocore_model/bio_emotion2.py +214 -0
  115. package/python/biocore_model/bio_goal.py +220 -0
  116. package/python/biocore_model/bio_identity.py +82 -0
  117. package/python/biocore_model/bio_noise.py +119 -0
  118. package/python/biocore_model/bio_physiology2.py +114 -0
  119. package/python/biocore_model/bio_snapshot.py +324 -0
  120. package/python/biocore_model/bio_state.py +272 -0
  121. package/python/biocore_model/bio_tick.py +310 -0
  122. package/python/biocore_model/bio_util.py +82 -0
  123. package/python/biocore_model/blocks.py +264 -0
  124. package/python/biocore_model/boundary.py +251 -0
  125. package/python/biocore_model/boundary_gate.py +188 -0
  126. package/python/biocore_model/commitment_extractor.py +517 -0
  127. package/python/biocore_model/compassion_fatigue.py +84 -0
  128. package/python/biocore_model/connection_bids.py +120 -0
  129. package/python/biocore_model/core_bridge.py +177 -0
  130. package/python/biocore_model/core_client.py +127 -0
  131. package/python/biocore_model/core_commands.py +112 -0
  132. package/python/biocore_model/core_mode.py +104 -0
  133. package/python/biocore_model/core_mode_ui.mjs +104 -0
  134. package/python/biocore_model/criticality.py +81 -0
  135. package/python/biocore_model/defense_mechanisms.py +272 -0
  136. package/python/biocore_model/delta_budget.py +99 -0
  137. package/python/biocore_model/diag_trace.py +274 -0
  138. package/python/biocore_model/dissonance.py +134 -0
  139. package/python/biocore_model/emotion_geometry.py +108 -0
  140. package/python/biocore_model/emotion_probe.py +209 -0
  141. package/python/biocore_model/entity_graph.py +931 -0
  142. package/python/biocore_model/entity_resolve.py +260 -0
  143. package/python/biocore_model/envy.py +193 -0
  144. package/python/biocore_model/exit_or_silence.py +230 -0
  145. package/python/biocore_model/expr_guard.py +24 -0
  146. package/python/biocore_model/expr_intent.py +77 -0
  147. package/python/biocore_model/expr_state.py +204 -0
  148. package/python/biocore_model/expr_template.py +105 -0
  149. package/python/biocore_model/expr_tone.py +81 -0
  150. package/python/biocore_model/extreme_scenarios.py +205 -0
  151. package/python/biocore_model/feedback_flow.py +227 -0
  152. package/python/biocore_model/feedback_guard.py +129 -0
  153. package/python/biocore_model/feedback_llm.py +163 -0
  154. package/python/biocore_model/feedback_memory.py +96 -0
  155. package/python/biocore_model/feedback_user.py +93 -0
  156. package/python/biocore_model/frustration_curve.py +110 -0
  157. package/python/biocore_model/granularity.py +283 -0
  158. package/python/biocore_model/graph_extract.py +248 -0
  159. package/python/biocore_model/graph_recall.py +221 -0
  160. package/python/biocore_model/intent_render.py +91 -0
  161. package/python/biocore_model/intero_core.py +235 -0
  162. package/python/biocore_model/intero_style.py +116 -0
  163. package/python/biocore_model/layered_memory.py +297 -0
  164. package/python/biocore_model/learning_probe.py +120 -0
  165. package/python/biocore_model/memory_dual.py +224 -0
  166. package/python/biocore_model/memory_forgetting.py +125 -0
  167. package/python/biocore_model/memory_store.py +1399 -0
  168. package/python/biocore_model/metacog.py +153 -0
  169. package/python/biocore_model/migrate.py +733 -0
  170. package/python/biocore_model/migrate_store.py +337 -0
  171. package/python/biocore_model/mind_wander.py +111 -0
  172. package/python/biocore_model/mood.py +48 -0
  173. package/python/biocore_model/narrative.py +172 -0
  174. package/python/biocore_model/needs_esteem.py +116 -0
  175. package/python/biocore_model/needs_events.py +137 -0
  176. package/python/biocore_model/needs_sleep.py +72 -0
  177. package/python/biocore_model/noise_bank.py +95 -0
  178. package/python/biocore_model/persona_flow.mjs +25 -0
  179. package/python/biocore_model/pipeline.py +240 -0
  180. package/python/biocore_model/pipeline_api.py +200 -0
  181. package/python/biocore_model/plugin_config.py +83 -0
  182. package/python/biocore_model/plugin_routes.py +1435 -0
  183. package/python/biocore_model/policy_learning.py +132 -0
  184. package/python/biocore_model/possible_selves.py +110 -0
  185. package/python/biocore_model/predictor.py +178 -0
  186. package/python/biocore_model/preset.py +205 -0
  187. package/python/biocore_model/proactive_context.py +153 -0
  188. package/python/biocore_model/prompt_rules.py +90 -0
  189. package/python/biocore_model/prospective.py +183 -0
  190. package/python/biocore_model/provider_fallback.py +97 -0
  191. package/python/biocore_model/reconstruction.py +132 -0
  192. package/python/biocore_model/regulation_loop.py +179 -0
  193. package/python/biocore_model/regulation_strategies.py +294 -0
  194. package/python/biocore_model/relation_stage.py +130 -0
  195. package/python/biocore_model/relationship_stage.py +95 -0
  196. package/python/biocore_model/render.py +901 -0
  197. package/python/biocore_model/render_guard.mjs +34 -0
  198. package/python/biocore_model/repair_after_boundary.py +350 -0
  199. package/python/biocore_model/reply_limit.py +183 -0
  200. package/python/biocore_model/reply_split.py +203 -0
  201. package/python/biocore_model/rollback.py +143 -0
  202. package/python/biocore_model/runtime.py +479 -0
  203. package/python/biocore_model/sanitize.py +200 -0
  204. package/python/biocore_model/scheduler.py +123 -0
  205. package/python/biocore_model/schema.py +120 -0
  206. package/python/biocore_model/secrecy.py +145 -0
  207. package/python/biocore_model/self_esteem.py +50 -0
  208. package/python/biocore_model/self_intent.py +437 -0
  209. package/python/biocore_model/self_interest.py +263 -0
  210. package/python/biocore_model/self_verification.py +178 -0
  211. package/python/biocore_model/services.py +78 -0
  212. package/python/biocore_model/situation.py +254 -0
  213. package/python/biocore_model/sleep_circadian.py +116 -0
  214. package/python/biocore_model/social_pain.py +69 -0
  215. package/python/biocore_model/social_repair.py +111 -0
  216. package/python/biocore_model/social_theory.py +131 -0
  217. package/python/biocore_model/source_monitoring.py +292 -0
  218. package/python/biocore_model/stages.py +487 -0
  219. package/python/biocore_model/state_tag.py +231 -0
  220. package/python/biocore_model/switch_groups.mjs +201 -0
  221. package/python/biocore_model/tabs_state.mjs +37 -0
  222. package/python/biocore_model/template_expr.py +252 -0
  223. package/python/biocore_model/tools/caps_check.mjs +23 -0
  224. package/python/biocore_model/tools/init_symbols_check.mjs +11 -0
  225. package/python/biocore_model/tools/missing_ids.mjs +16 -0
  226. package/python/biocore_model/tools/scope_check.mjs +19 -0
  227. package/python/biocore_model/topic_control.py +268 -0
  228. package/python/biocore_model/turn_memory.py +152 -0
  229. package/python/biocore_model/ui_compat.mjs +48 -0
  230. package/python/biocore_model/ui_settings.py +266 -0
  231. package/python/biocore_model/ui_settings.py.bak_authority +108 -0
  232. package/python/biocore_model/value_order.py +186 -0
  233. package/python/biocore_model/view_mode.mjs +8 -0
  234. package/python/biocore_model/voice_bank.py +177 -0
  235. package/python/biocore_model/waiting_sense.py +229 -0
  236. package/python/biocore_model/x_directives.py +142 -0
  237. package/python/biocore_runtime/__init__.py +7 -0
  238. package/python/biocore_runtime/pipeline.py +1915 -0
  239. package/python/dsh_adapter/README.md +96 -0
  240. package/python/dsh_adapter/adapter.py +1077 -0
  241. package/python/dsh_adapter/cli.py +107 -0
  242. package/python/dsh_adapter/data/demo_state.json +164 -0
  243. package/python/dsh_adapter/data/verify_state.json +164 -0
  244. package/python/dsh_adapter/tests/__init__.py +1 -0
  245. package/python/dsh_adapter/tests/test_adapter.py +494 -0
  246. package/ui/panel-layout.js +3 -3
  247. package/ui/panel.css +53 -6
  248. package/ui/panel.html +33 -32
  249. package/ui/panel.js +9 -1
  250. package/lib/py/__pycache__/bridge.cpython-310.pyc +0 -0
@@ -0,0 +1,494 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Tests for the DSH adapter: state IO, one-turn update, constraints, purity."""
3
+ import ast
4
+ import builtins
5
+ import copy
6
+ import json
7
+ import os
8
+ import pathlib
9
+ import sys
10
+ import tempfile
11
+ import time
12
+ import unittest
13
+ from pathlib import Path
14
+
15
+ HERE = Path(__file__).resolve().parent
16
+ sys.path.insert(0, str(HERE.parent))
17
+
18
+ import adapter # noqa: E402
19
+
20
+
21
+ class StateIOTest(unittest.TestCase):
22
+ def setUp(self):
23
+ self.tmp = tempfile.TemporaryDirectory()
24
+ self.store = Path(self.tmp.name) / "nested" / "state.json"
25
+
26
+ def tearDown(self):
27
+ self.tmp.cleanup()
28
+
29
+ def test_default_state_shape(self):
30
+ state = adapter.default_state()
31
+ self.assertEqual(state["version"], 1)
32
+ self.assertEqual(state["turn"], 0)
33
+ for key in ("v", "a", "d", "social", "stress", "energy"):
34
+ self.assertIn(key, state["core"])
35
+ self.assertEqual(state["relationship"]["closeness"], 0.5)
36
+ self.assertEqual(state["relationship"]["trust"], 0.5)
37
+ self.assertEqual(state["relationship"]["conflict"], 0.0)
38
+ self.assertEqual(state["seen"], {})
39
+
40
+ def test_load_missing_file_returns_default(self):
41
+ loaded = adapter.load_state(self.store)
42
+ self.assertEqual(loaded, adapter.default_state())
43
+
44
+ def test_save_creates_parent_and_roundtrips(self):
45
+ state = adapter.default_state()
46
+ state["turn"] = 2
47
+ state["core"]["v"] = -0.3
48
+ saved = adapter.save_state(state, self.store)
49
+ self.assertTrue(Path(saved).exists())
50
+ self.assertTrue(self.store.parent.is_dir())
51
+ loaded = adapter.load_state(self.store)
52
+ self.assertEqual(loaded["turn"], 2)
53
+ self.assertAlmostEqual(loaded["core"]["v"], -0.3, places=4)
54
+
55
+ def test_save_leaves_no_tmp_file(self):
56
+ adapter.save_state(adapter.default_state(), self.store)
57
+ leftovers = list(self.store.parent.glob("*.tmp"))
58
+ self.assertEqual(leftovers, [])
59
+
60
+ def test_malformed_json_raises(self):
61
+ self.store.parent.mkdir(parents=True)
62
+ self.store.write_text("{not valid json", encoding="utf-8")
63
+ with self.assertRaises(ValueError):
64
+ adapter.load_state(self.store)
65
+
66
+ def test_non_object_json_raises(self):
67
+ self.store.parent.mkdir(parents=True)
68
+ self.store.write_text("[1, 2, 3]", encoding="utf-8")
69
+ with self.assertRaises(ValueError):
70
+ adapter.load_state(self.store)
71
+
72
+ def test_load_accepts_dict(self):
73
+ loaded = adapter.load_state({"turn": 3, "core": {"v": 0.4}})
74
+ self.assertEqual(loaded["turn"], 3)
75
+ self.assertAlmostEqual(loaded["core"]["v"], 0.4, places=4)
76
+
77
+ def test_normalize_fills_defaults_and_clamps(self):
78
+ state = adapter.normalize_state({
79
+ "turn": 2,
80
+ "core": {"v": 9, "a": -1},
81
+ "relationship": {"closeness": -3},
82
+ })
83
+ self.assertEqual(state["turn"], 2)
84
+ self.assertEqual(state["core"]["v"], 1.0)
85
+ self.assertEqual(state["core"]["a"], 0.0)
86
+ self.assertEqual(state["core"]["stress"], 0.2) # default filled in
87
+ self.assertEqual(state["relationship"]["closeness"], 0.0)
88
+
89
+ def test_save_does_not_mutate(self):
90
+ state = adapter.default_state()
91
+ before = copy.deepcopy(state)
92
+ adapter.save_state(state, self.store)
93
+ self.assertEqual(state, before)
94
+
95
+
96
+ class OneTurnTest(unittest.TestCase):
97
+ def setUp(self):
98
+ self.state = adapter.default_state()
99
+
100
+ def test_result_shape_and_hint_contract(self):
101
+ result = adapter.one_turn("嗯", self.state)
102
+ for key in ("reply_hint", "state_after", "prompt_blocks", "debug"):
103
+ self.assertIn(key, result)
104
+ hint = result["reply_hint"]
105
+ for key in ("length_scale", "initiative", "tone",
106
+ "allow_correction", "note", "sources"):
107
+ self.assertIn(key, hint)
108
+ self.assertGreaterEqual(hint["length_scale"], 0.5)
109
+ self.assertLessEqual(hint["length_scale"], 1.5)
110
+ self.assertGreaterEqual(hint["initiative"], 0.0)
111
+ self.assertLessEqual(hint["initiative"], 1.0)
112
+ self.assertIsInstance(hint["tone"], str)
113
+ self.assertIsInstance(hint["allow_correction"], bool)
114
+ self.assertIsInstance(hint["sources"], list)
115
+
116
+ def test_advances_turn_and_injected_time(self):
117
+ result = adapter.one_turn("嗯", self.state)
118
+ after = result["state_after"]
119
+ self.assertEqual(after["turn"], 1)
120
+ self.assertAlmostEqual(after["now"], adapter.TURN_SECONDS)
121
+ self.assertAlmostEqual(after["core"]["last_bio_tick_ts"],
122
+ adapter.TURN_SECONDS)
123
+
124
+ def test_state_after_has_tick_output(self):
125
+ after = adapter.one_turn("嗯", self.state)["state_after"]
126
+ self.assertIsInstance(after["core"]["needs"], dict)
127
+ self.assertIsInstance(after["core"]["intero"], dict)
128
+
129
+ def test_input_state_is_not_mutated(self):
130
+ before = copy.deepcopy(self.state)
131
+ adapter.one_turn("今天好累", self.state)
132
+ self.assertEqual(self.state, before)
133
+
134
+ def test_same_input_is_deterministic(self):
135
+ first = adapter.one_turn("谢谢你", self.state)
136
+ second = adapter.one_turn("谢谢你", self.state)
137
+ self.assertEqual(first["reply_hint"], second["reply_hint"])
138
+ self.assertEqual(first["state_after"], second["state_after"])
139
+
140
+ def test_praise_moves_affect_positive(self):
141
+ before = copy.deepcopy(self.state["core"])
142
+ result = adapter.one_turn("谢谢你,今天好多了", self.state)
143
+ after = result["state_after"]["core"]
144
+ self.assertEqual(result["debug"]["kind"], "praise")
145
+ self.assertGreater(after["v"], before["v"])
146
+ self.assertGreater(after["social"], before["social"])
147
+
148
+ def test_insult_raises_social_pain(self):
149
+ result = adapter.one_turn("滚,烦死了", self.state)
150
+ after = result["state_after"]["core"]
151
+ self.assertEqual(result["debug"]["kind"], "insult")
152
+ self.assertGreater(after["social_pain"], 0.0)
153
+
154
+ def test_affection_raises_social(self):
155
+ result = adapter.one_turn("抱抱", self.state)
156
+ after = result["state_after"]["core"]
157
+ self.assertEqual(result["debug"]["kind"], "affection")
158
+ self.assertGreater(after["social"], self.state["core"]["social"])
159
+
160
+ def test_sad_text_uses_empathic_burden(self):
161
+ result = adapter.one_turn("今天有点累,很难受", self.state)
162
+ self.assertEqual(result["debug"]["kind"], "sad")
163
+ self.assertIn("stress", result["debug"]["deltas"])
164
+
165
+ def test_negative_valence_shortens_length(self):
166
+ warm = adapter.one_turn("嗯", self.state)["reply_hint"]
167
+ cold_state = adapter.normalize_state({"core": {"v": -0.8}})
168
+ cold = adapter.one_turn("嗯", cold_state)["reply_hint"]
169
+ self.assertLessEqual(cold["length_scale"], warm["length_scale"])
170
+
171
+ def test_prompt_blocks_render(self):
172
+ result = adapter.one_turn("嗯", self.state)
173
+ blocks = result["prompt_blocks"]
174
+ self.assertTrue(blocks)
175
+ for block in blocks:
176
+ self.assertIn(block["position"],
177
+ {"before_history", "depth", "after_history"})
178
+ self.assertTrue(block["content"].strip())
179
+ joined = "\n".join(block["content"] for block in blocks)
180
+ self.assertIn("关系", joined)
181
+ self.assertTrue(result["debug"]["state_block"])
182
+
183
+ def test_seen_is_bounded(self):
184
+ state = adapter.default_state()
185
+ state["seen"] = {"k%d" % i: float(i) for i in range(adapter.SEEN_LIMIT + 60)}
186
+ after = adapter.one_turn("嗯", state)["state_after"]
187
+ self.assertLessEqual(len(after["seen"]), adapter.SEEN_LIMIT)
188
+ self.assertTrue(after["seen"])
189
+
190
+ def test_tolerates_none_and_garbage_state(self):
191
+ for bad in (None, "not a state", 42, []):
192
+ result = adapter.one_turn("嗯", bad)
193
+ self.assertIn("reply_hint", result)
194
+
195
+ def test_one_turn_is_pure_no_io_no_clock(self):
196
+ state = adapter.default_state()
197
+ real = {
198
+ "open": builtins.open,
199
+ "path_open": pathlib.Path.open,
200
+ "read_text": pathlib.Path.read_text,
201
+ "write_text": pathlib.Path.write_text,
202
+ "replace": os.replace,
203
+ "time": time.time,
204
+ }
205
+
206
+ def boom(*args, **kwargs):
207
+ raise AssertionError("one_turn must not touch IO or the clock")
208
+
209
+ builtins.open = boom
210
+ pathlib.Path.open = boom
211
+ pathlib.Path.read_text = boom
212
+ pathlib.Path.write_text = boom
213
+ os.replace = boom
214
+ time.time = boom
215
+ try:
216
+ result = adapter.one_turn("谢谢你", state)
217
+ finally:
218
+ builtins.open = real["open"]
219
+ pathlib.Path.open = real["path_open"]
220
+ pathlib.Path.read_text = real["read_text"]
221
+ pathlib.Path.write_text = real["write_text"]
222
+ os.replace = real["replace"]
223
+ time.time = real["time"]
224
+ self.assertIn("reply_hint", result)
225
+
226
+
227
+ class ConstraintTest(unittest.TestCase):
228
+ def test_merged_sources_and_confidence(self):
229
+ hint = adapter.one_turn("嗯", adapter.default_state())["reply_hint"]
230
+ for source in ("exit_or_silence", "metacog", "state"):
231
+ self.assertIn(source, hint["sources"])
232
+ self.assertGreaterEqual(hint["confidence"], 0.05)
233
+ self.assertLessEqual(hint["confidence"], 0.95)
234
+
235
+ def test_classify_text(self):
236
+ cases = {
237
+ "滚": "insult",
238
+ "谢谢你": "praise",
239
+ "抱抱": "affection",
240
+ "今天有点累": "sad",
241
+ "不想聊了": "reject",
242
+ "嗯": "reply",
243
+ }
244
+ for text, expected in cases.items():
245
+ self.assertEqual(adapter.classify_user_text(text), expected, text)
246
+
247
+ def test_no_astrbot_or_main_import(self):
248
+ root = HERE.parent
249
+ for name in ("adapter.py", "cli.py"):
250
+ path = root / name
251
+ source = path.read_text(encoding="utf-8")
252
+ tree = ast.parse(source, filename=str(path))
253
+ for node in ast.walk(tree):
254
+ modules = []
255
+ if isinstance(node, ast.Import):
256
+ modules = [alias.name for alias in node.names]
257
+ elif isinstance(node, ast.ImportFrom) and node.module:
258
+ modules = [node.module]
259
+ for module in modules:
260
+ head = module.split(".")[0]
261
+ self.assertNotIn(head, ("astrbot", "main", "aiocqhttp"),
262
+ "%s imports %s" % (name, module))
263
+ self.assertNotIn("import astrbot", source)
264
+
265
+ def test_adapter_lives_outside_plugin_repo(self):
266
+ here = str(Path(adapter.__file__).resolve())
267
+ self.assertIn("dsh_adapter", here)
268
+ self.assertNotIn("astrbot_plugin_biocore_standalone", here)
269
+
270
+ def test_cli_module_imports(self):
271
+ import cli
272
+ self.assertTrue(callable(cli.main))
273
+ self.assertTrue(cli.DEMO_TEXTS)
274
+
275
+
276
+ class UIProjectionTest(unittest.TestCase):
277
+ """DSH-UI-DESIGN section 7: 57 rows, endpoint payloads, 4 switches."""
278
+
279
+ @staticmethod
280
+ def _resolve(payload, path):
281
+ current = payload
282
+ for part in path.split("."):
283
+ if not isinstance(current, dict) or part not in current:
284
+ raise KeyError(path)
285
+ current = current[part]
286
+ return current
287
+
288
+ def _turned_state(self, turns=1):
289
+ state = adapter.default_state()
290
+ state["session_id"] = "sess-1"
291
+ for text in ("谢谢你", "今天有点累", "抱抱", "嗯")[:turns]:
292
+ state = adapter.one_turn(text, state)["state_after"]
293
+ return state
294
+
295
+ def test_six_endpoints_are_declared(self):
296
+ self.assertEqual(len(adapter.ENDPOINTS), 6)
297
+ self.assertEqual(set(adapter.ENDPOINTS), {
298
+ "/api/biocore/state", "/api/biocore/series",
299
+ "/api/biocore/memory", "/api/biocore/trace",
300
+ "/api/biocore/health", "/api/biocore/switch"})
301
+
302
+ def test_field_paths_are_57(self):
303
+ self.assertEqual(len(adapter.FIELD_PATHS), 57)
304
+ self.assertEqual(len(set(adapter.FIELD_PATHS)), 57)
305
+
306
+ def test_state_payload_has_every_documented_row(self):
307
+ payload = adapter.state_payload(self._turned_state(), session_id="sess-1")
308
+ for path in adapter.FIELD_PATHS:
309
+ self._resolve(payload, path)
310
+ self.assertEqual(payload["adapter"]["level"], "L2")
311
+ self.assertEqual(payload["session_id"], "sess-1")
312
+ self.assertTrue(payload["ok"])
313
+ self.assertTrue(payload["available"])
314
+
315
+ def test_first_screen_five_numbers_and_three_words(self):
316
+ payload = adapter.state_payload(self._turned_state(), session_id="sess-1")
317
+ self.assertGreaterEqual(payload["v"], -1.0)
318
+ self.assertLessEqual(payload["v"], 1.0)
319
+ for name in ("tension", "warmth", "heaviness", "clarity"):
320
+ value = payload["intero"][name]
321
+ self.assertGreaterEqual(value, 0.0)
322
+ self.assertLessEqual(value, 1.0)
323
+ self.assertIn(payload["tone"]["label"],
324
+ ("", "先接住情绪", "慢一点说", "亲近一点", "没听清先确认"))
325
+ self.assertIn(payload["relation"]["stage"], ("陌生", "熟悉", "亲近", "稳定"))
326
+ self.assertIn(payload["autonomy"]["state"], ("静", "等", "想联系", "冷却"))
327
+
328
+ def test_state_payload_size_limit(self):
329
+ state = self._turned_state()
330
+ state["memory"]["recent"] = [
331
+ {"id": "m%d" % i, "ts": 1.0, "score": 0.5, "source": "chat",
332
+ "kind": "fact", "text": "很长的记忆正文" * 20} for i in range(20)]
333
+ payload = adapter.state_payload(state, session_id="sess-1")
334
+ size = len(json.dumps(payload, ensure_ascii=False).encode("utf-8"))
335
+ self.assertLessEqual(size, adapter.STATE_PAYLOAD_LIMIT)
336
+ blob = json.dumps(payload, ensure_ascii=False)
337
+ self.assertNotIn("prompt_blocks", blob)
338
+
339
+ def test_series_payload_contract(self):
340
+ state = self._turned_state(4)
341
+ payload = adapter.series_payload(state, session_id="sess-1", window="1h")
342
+ self.assertTrue(payload["ok"])
343
+ self.assertTrue(payload["available"])
344
+ self.assertEqual(payload["window"], "1h")
345
+ for name in ("v", "tension", "warmth", "heaviness", "clarity"):
346
+ points = payload["series"][name]
347
+ self.assertTrue(points)
348
+ self.assertLessEqual(len(points), adapter.SERIES_LIMIT)
349
+ for point in points:
350
+ self.assertIn("ts", point)
351
+ self.assertIn("value", point)
352
+ bad_window = adapter.series_payload(state, window="9y")
353
+ self.assertEqual(bad_window["window"], "1h")
354
+
355
+ def test_memory_payload_preview_and_limit(self):
356
+ state = self._turned_state()
357
+ state["memory"]["recent"] = [
358
+ {"id": "m%d" % i, "ts": float(i), "score": 0.9, "source": "chat",
359
+ "kind": "fact", "text": "长" * 200} for i in range(30)]
360
+ state["memory"]["count"] = 30
361
+ state["memory"]["last_recall"] = {
362
+ "query": "体检", "hits": 3, "latency_ms": 12.5}
363
+ payload = adapter.memory_payload(state, session_id="sess-1")
364
+ self.assertTrue(payload["available"])
365
+ self.assertEqual(len(payload["recent"]), adapter.MEMORY_LIMIT)
366
+ for item in payload["recent"]:
367
+ self.assertLessEqual(len(item["text_preview"]),
368
+ adapter.MEMORY_PREVIEW_LIMIT)
369
+ self.assertEqual(payload["last_recall"]["query"], "体检")
370
+ self.assertEqual(payload["last_recall"]["hits"], 3)
371
+ small = adapter.memory_payload(state, limit=5)
372
+ self.assertEqual(len(small["recent"]), 5)
373
+
374
+ def test_trace_payload_contract(self):
375
+ state = self._turned_state()
376
+ payload = adapter.trace_payload(state, session_id="sess-1")
377
+ self.assertTrue(payload["available"])
378
+ trace = payload["trace"]
379
+ self.assertEqual(set(trace), {"state_delta", "intent", "metacog_band",
380
+ "length_source", "prompt_diff"})
381
+ self.assertIsNone(adapter.state_payload(state)["trace"])
382
+ with_trace = adapter.state_payload(state, include_trace=True)
383
+ self.assertIsNotNone(with_trace["trace"])
384
+
385
+ def test_switch_map_has_exactly_four_keys(self):
386
+ self.assertEqual(set(adapter.SWITCH_MAP), {
387
+ "safety.master", "safety.boundary", "safety.crisis",
388
+ "autonomy.proactive_send"})
389
+ for key, config_key in adapter.SWITCH_MAP.items():
390
+ self.assertIn(config_key, adapter.DEFAULT_SETTINGS)
391
+ request = adapter.switch_request(
392
+ {"key": key, "value": True, "confirm": key})
393
+ self.assertTrue(request["ok"], key)
394
+ self.assertEqual(request["settings_patch"], {config_key: True})
395
+
396
+ def test_switch_rejects_unknown_invalid_and_missing_confirm(self):
397
+ bad_key = adapter.switch_request(
398
+ {"key": "core.v", "value": 0.9, "confirm": "core.v"})
399
+ self.assertFalse(bad_key["ok"])
400
+ self.assertEqual(bad_key["code"], "unknown_key")
401
+ bad_value = adapter.switch_request(
402
+ {"key": "safety.master", "value": "on", "confirm": "safety.master"})
403
+ self.assertFalse(bad_value["ok"])
404
+ self.assertEqual(bad_value["code"], "invalid_value")
405
+ no_confirm = adapter.switch_request(
406
+ {"key": "safety.master", "value": True})
407
+ self.assertFalse(no_confirm["ok"])
408
+ self.assertEqual(no_confirm["code"], "confirm_required")
409
+ wrong_confirm = adapter.switch_request(
410
+ {"key": "safety.master", "value": True, "confirm": "safety.boundary"})
411
+ self.assertFalse(wrong_confirm["ok"])
412
+
413
+ def test_apply_switch_only_touches_settings(self):
414
+ state = adapter.default_state()
415
+ before = copy.deepcopy(state)
416
+ result = adapter.apply_switch(
417
+ state, {"key": "safety.master", "value": True,
418
+ "confirm": "safety.master"})
419
+ self.assertTrue(result["ok"])
420
+ after = result["state_after"]
421
+ self.assertTrue(after["settings"]["safety_enabled"])
422
+ self.assertEqual(after["core"], before["core"])
423
+ self.assertEqual(after["memory"], before["memory"])
424
+ self.assertEqual(after["relationship"], before["relationship"])
425
+ self.assertEqual(result["settings_patch"], {"safety_enabled": True})
426
+ self.assertEqual(state, before) # input untouched
427
+
428
+ def test_unknown_session_returns_no_state_yet(self):
429
+ payload = adapter.state_payload(None, session_id="missing")
430
+ self.assertTrue(payload["ok"])
431
+ self.assertFalse(payload["available"])
432
+ self.assertEqual(payload["reason"], "no_state_yet")
433
+ for path in adapter.FIELD_PATHS:
434
+ self._resolve(payload, path)
435
+ state = self.default_with_session("session-a")
436
+ mismatch = adapter.state_payload(state, session_id="session-b")
437
+ self.assertFalse(mismatch["available"])
438
+ self.assertEqual(mismatch["reason"], "no_state_yet")
439
+
440
+ @staticmethod
441
+ def default_with_session(session_id):
442
+ state = adapter.default_state()
443
+ state["session_id"] = session_id
444
+ return state
445
+
446
+ def test_health_payload_with_and_without_state(self):
447
+ empty = adapter.health_payload(None)
448
+ self.assertFalse(empty["available"])
449
+ self.assertTrue(empty["degraded"])
450
+ full = adapter.health_payload(self._turned_state())
451
+ self.assertTrue(full["available"])
452
+ for key in ("service", "store", "last_tick_ts", "tick_interval_s"):
453
+ self.assertIn(key, full)
454
+
455
+ def test_projections_isolate_sessions(self):
456
+ state = self.default_with_session("session-a")
457
+ state = adapter.one_turn("嗯", state)["state_after"]
458
+ for builder in (adapter.series_payload, adapter.memory_payload,
459
+ adapter.trace_payload):
460
+ payload = builder(state, session_id="session-b")
461
+ self.assertFalse(payload["available"])
462
+ self.assertEqual(payload["reason"], "no_state_yet")
463
+ self.assertTrue(adapter.trace_payload(
464
+ state, session_id="session-a")["available"])
465
+
466
+ def test_payload_builders_are_pure(self):
467
+ state = self._turned_state()
468
+ real_open = builtins.open
469
+ real_read = pathlib.Path.read_text
470
+ real_replace = os.replace
471
+
472
+ def boom(*args, **kwargs):
473
+ raise AssertionError("payload builders must not touch the filesystem")
474
+
475
+ builtins.open = boom
476
+ pathlib.Path.read_text = boom
477
+ os.replace = boom
478
+ try:
479
+ adapter.state_payload(state, session_id="sess-1")
480
+ adapter.series_payload(state)
481
+ adapter.memory_payload(state)
482
+ adapter.trace_payload(state)
483
+ adapter.health_payload(state)
484
+ adapter.switch_request(
485
+ {"key": "safety.master", "value": True,
486
+ "confirm": "safety.master"})
487
+ finally:
488
+ builtins.open = real_open
489
+ pathlib.Path.read_text = real_read
490
+ os.replace = real_replace
491
+
492
+
493
+ if __name__ == "__main__":
494
+ unittest.main()
@@ -7,15 +7,15 @@
7
7
  (function (root) {
8
8
  'use strict'
9
9
 
10
- var STORAGE_KEY = 'biocore-panel-layout-v1'
10
+ var STORAGE_KEY = 'biocore-panel-layout-v2'
11
11
  var DEFAULT_ORDER = [
12
- 'mood', 'channels', 'chart',
12
+ 'mood', 'tension', 'warmth', 'heaviness', 'clarity', 'chart',
13
13
  'memory', 'memory-summary', 'metrics', 'trace', 'runtime',
14
14
  'persona', 'model', 'switches', 'expression', 'advanced',
15
15
  ]
16
16
  var TAB_ORDER = ['dashboard', 'memory', 'settings', 'diagnosis']
17
17
  var TAB_GROUPS = Object.freeze({
18
- dashboard: ['mood', 'channels', 'chart'],
18
+ dashboard: ['mood', 'tension', 'warmth', 'heaviness', 'clarity', 'chart'],
19
19
  memory: ['memory', 'memory-summary'],
20
20
  settings: ['persona', 'model', 'switches', 'expression', 'advanced'],
21
21
  diagnosis: ['metrics', 'trace', 'runtime'],
package/ui/panel.css CHANGED
@@ -1,4 +1,4 @@
1
- /* BioCore instrument panel — FlClash mobile spec.
1
+ /* BioCore instrument panel — FlClash mobile spec. | layout v24
2
2
  1) tokens 2) base 3) topbar 4) cards 5) figures 6) lists 7) forms
3
3
  8) switches 9) nav 10) edit mode 11) desktop.
4
4
  Rule: one component rule per selector, px values from docs/DSH-PANEL-FLCLASH-SPEC.md. */
@@ -202,9 +202,9 @@ body {
202
202
  .delta.up { color: var(--ok); }
203
203
  .delta.down { color: var(--danger); }
204
204
  .sub-value { display: flex; align-items: baseline; gap: 6px; letter-spacing: -0.02em; }
205
- .sub-value strong { font-size: 28px; line-height: 34px; font-weight: 700; }
206
- .channels-card .sub-value strong { font-size: 28px; line-height: 34px; }
207
- .mood-card .sub-value strong { font-size: 40px; line-height: 44px; }
205
+ .sub-value strong { font-size: 20px; line-height: 26px; font-weight: 700; }
206
+ .channels-card .sub-value strong { font-size: 20px; line-height: 26px; }
207
+ .mood-card .sub-value strong { font-size: 30px; line-height: 34px; }
208
208
  .unit { display: none; }
209
209
  .sub-status { margin-left: auto; color: var(--text-2); font-size: 13px; line-height: 18px; letter-spacing: 0; }
210
210
  .sub-note { color: var(--text-3); font-size: 12px; line-height: 16px; min-height: 16px; }
@@ -246,7 +246,7 @@ canvas#moodChart { display: block; width: 100%; height: 150px; }
246
246
  .memory-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
247
247
  .memory-stat { display: flex; flex-direction: column; gap: 2px; padding: 14px; background: var(--block); border-radius: var(--radius-block); }
248
248
  .memory-stat span { color: var(--text-2); font-size: 12px; line-height: 16px; }
249
- .memory-stat strong { font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -0.02em; }
249
+ .memory-stat strong { font-size: 22px; line-height: 28px; font-weight: 700; letter-spacing: -0.02em; }
250
250
  .memory-stat em { color: var(--text-2); font-size: 12px; font-style: normal; }
251
251
  .memory-summary-card .capacity { margin-top: 14px; }
252
252
  .capacity { margin-top: 12px; }
@@ -476,7 +476,7 @@ canvas#moodChart { display: block; width: 100%; height: 150px; }
476
476
  .panel { width: min(640px, 100%); }
477
477
  .tabbar { width: min(560px, calc(100% - 48px)); }
478
478
  }
479
- @media (max-width: 359px) {
479
+ @media (max-width: 300px) {
480
480
  .sub-grid.two { grid-template-columns: 1fr; }
481
481
  .relation-grid { gap: 8px 12px; }
482
482
  }
@@ -498,3 +498,50 @@ canvas#moodChart { display: block; width: 100%; height: 150px; }
498
498
  @media (max-width: 620px) {
499
499
  .expression-fields { grid-template-columns: 1fr; }
500
500
  }
501
+
502
+ /* ---------- 13. layout guards (防止旧版/串版样式压扁版面) ---------- */
503
+ html, body { overflow-x: clip; }
504
+ body { max-width: 100%; }
505
+ .panel { max-width: 100%; }
506
+ .channels-wrap { min-width: 0; max-width: 100%; }
507
+ .masthead { height: auto; max-height: none; overflow: visible; }
508
+ .masthead .orb-wrap { min-width: 88px; min-height: 88px; overflow: visible; }
509
+ .masthead .orb { flex: 0 0 auto; }
510
+ .identity { align-self: center; width: 100%; }
511
+ .channels-wrap { position: relative; }
512
+ .channels-wrap > .channel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
513
+
514
+ /* ---------- 14. channels: four independent cards (2×2) ---------- */
515
+ .channels-wrap { position: relative; }
516
+ .channel-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 2px 4px 10px; }
517
+ .channel-title-row h2 { margin: 0; font-size: 17px; line-height: 22px; font-weight: 600; letter-spacing: -0.01em; }
518
+ .channel-aside { color: var(--text-3); font-size: 13px; line-height: 18px; }
519
+ .channel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
520
+ .channel-card {
521
+ min-width: 0;
522
+ max-width: 100%;
523
+ display: flex;
524
+ flex-direction: column;
525
+ gap: 6px;
526
+ min-width: 0;
527
+ padding: 14px;
528
+ background: var(--card);
529
+ border-radius: 20px;
530
+ box-shadow: var(--shadow-e1);
531
+ }
532
+ .channel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
533
+ .channel-label { color: var(--text-2); font-size: 12px; line-height: 16px; }
534
+ .channel-card .sub-trend { color: var(--text-3); font-size: 12px; line-height: 16px; }
535
+ .channel-value { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; row-gap: 2px; min-width: 0; }
536
+ .channel-value strong { font-size: 30px; line-height: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
537
+ .channel-card .sub-status { white-space: nowrap; margin-left: auto; color: var(--text-2); font-size: 13px; line-height: 18px; }
538
+ .channel-card .sub-note { margin: 0; color: var(--text-3); font-size: 11px; line-height: 15px; min-height: 15px; overflow-wrap: anywhere; }
539
+ .channel-card .bar { margin-top: 2px; }
540
+ .channel-card .bar-legend { margin-top: 4px; gap: 10px; font-size: 11px; line-height: 15px; }
541
+ .channel-card .bar-legend .legend-dot { width: 5px; height: 5px; border-radius: 2.5px; margin-right: 3px; }
542
+ @media (min-width: 360px) {
543
+ .channels-wrap .channel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
544
+ }
545
+ @media (max-width: 300px) {
546
+ .channels-wrap .channel-grid { grid-template-columns: 1fr; }
547
+ }