dsh-biocore 0.2.0 → 0.3.1

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 (245) hide show
  1. package/README.md +11 -0
  2. package/lib/core-worker.js +268 -0
  3. package/lib/index.js +160 -70
  4. package/lib/modules/autonomy.js +125 -0
  5. package/lib/modules/cache-stats.js +48 -0
  6. package/lib/modules/core-turn.js +24 -6
  7. package/lib/modules/expression-inject.js +0 -10
  8. package/lib/modules/expression-refresh.js +0 -9
  9. package/lib/modules/memory-capture.js +2 -1
  10. package/lib/modules/memory-inject.js +50 -5
  11. package/lib/modules/memory-tools.js +7 -4
  12. package/lib/modules/python-env.js +46 -0
  13. package/lib/modules/safety-gate.js +0 -3
  14. package/lib/modules/series.js +54 -0
  15. package/lib/modules/switch.js +16 -0
  16. package/lib/py-bridge.js +81 -15
  17. package/package.json +1 -1
  18. package/python/biocore_memory/core/config.py +138 -127
  19. package/python/biocore_memory/engine.py +2653 -2476
  20. package/python/biocore_memory/recall/embedding.py +129 -0
  21. package/python/biocore_memory/recall/feedback.py +202 -0
  22. package/python/biocore_model/preference_drift.py +255 -0
  23. package/python/biocore_model/tests/__init__.py +1 -0
  24. package/python/biocore_model/tests/core_mode_ui_check.mjs +63 -0
  25. package/python/biocore_model/tests/core_status_check.mjs +29 -0
  26. package/python/biocore_model/tests/dom_safe_check.mjs +22 -0
  27. package/python/biocore_model/tests/leak_samples_run.py +18 -0
  28. package/python/biocore_model/tests/orb_ring_check.mjs +20 -0
  29. package/python/biocore_model/tests/panel_html_check.mjs +63 -0
  30. package/python/biocore_model/tests/persona_flow_check.mjs +17 -0
  31. package/python/biocore_model/tests/render_guard_check.mjs +19 -0
  32. package/python/biocore_model/tests/switch_groups_check.mjs +94 -0
  33. package/python/biocore_model/tests/tabs_state_check.mjs +24 -0
  34. package/python/biocore_model/tests/test_affective_labor.py +102 -0
  35. package/python/biocore_model/tests/test_appraisal.py +137 -0
  36. package/python/biocore_model/tests/test_appraisal_action.py +55 -0
  37. package/python/biocore_model/tests/test_arch_convergence.py +35 -0
  38. package/python/biocore_model/tests/test_attachment_behavior.py +95 -0
  39. package/python/biocore_model/tests/test_attachment_regulation.py +63 -0
  40. package/python/biocore_model/tests/test_attachment_state.py +29 -0
  41. package/python/biocore_model/tests/test_attribution.py +56 -0
  42. package/python/biocore_model/tests/test_attributor.py +108 -0
  43. package/python/biocore_model/tests/test_autonomic.py +69 -0
  44. package/python/biocore_model/tests/test_autonomy_accumulator.py +84 -0
  45. package/python/biocore_model/tests/test_autonomy_affect.py +62 -0
  46. package/python/biocore_model/tests/test_autonomy_blame.py +44 -0
  47. package/python/biocore_model/tests/test_autonomy_caps.py +29 -0
  48. package/python/biocore_model/tests/test_autonomy_check.py +40 -0
  49. package/python/biocore_model/tests/test_autonomy_clingy.py +41 -0
  50. package/python/biocore_model/tests/test_autonomy_cooldown_selfcontact.py +138 -0
  51. package/python/biocore_model/tests/test_autonomy_frustration.py +42 -0
  52. package/python/biocore_model/tests/test_autonomy_hourly_limit.py +46 -0
  53. package/python/biocore_model/tests/test_autonomy_loop.py +64 -0
  54. package/python/biocore_model/tests/test_autonomy_mode.py +37 -0
  55. package/python/biocore_model/tests/test_autonomy_model.py +60 -0
  56. package/python/biocore_model/tests/test_autonomy_model_v2.py +68 -0
  57. package/python/biocore_model/tests/test_autonomy_module_text.py +104 -0
  58. package/python/biocore_model/tests/test_autonomy_params.py +163 -0
  59. package/python/biocore_model/tests/test_autonomy_reason.py +34 -0
  60. package/python/biocore_model/tests/test_autonomy_self.py +153 -0
  61. package/python/biocore_model/tests/test_autonomy_send_gate.py +38 -0
  62. package/python/biocore_model/tests/test_autonomy_silence.py +37 -0
  63. package/python/biocore_model/tests/test_autonomy_status.py +35 -0
  64. package/python/biocore_model/tests/test_autonomy_test_trigger.py +24 -0
  65. package/python/biocore_model/tests/test_autonomy_tick.py +148 -0
  66. package/python/biocore_model/tests/test_autonomy_v4.py +64 -0
  67. package/python/biocore_model/tests/test_autonomy_v5.py +43 -0
  68. package/python/biocore_model/tests/test_autonomy_v7.py +48 -0
  69. package/python/biocore_model/tests/test_autonomy_v_theta.py +85 -0
  70. package/python/biocore_model/tests/test_batch1_wiring.py +231 -0
  71. package/python/biocore_model/tests/test_batch2_wiring.py +231 -0
  72. package/python/biocore_model/tests/test_batch3_wiring.py +223 -0
  73. package/python/biocore_model/tests/test_bio_tick.py +202 -0
  74. package/python/biocore_model/tests/test_boundary.py +183 -0
  75. package/python/biocore_model/tests/test_boundary_gate.py +295 -0
  76. package/python/biocore_model/tests/test_brain_split.py +99 -0
  77. package/python/biocore_model/tests/test_co_recall.py +350 -0
  78. package/python/biocore_model/tests/test_commitment_extractor.py +197 -0
  79. package/python/biocore_model/tests/test_compassion_fatigue.py +84 -0
  80. package/python/biocore_model/tests/test_connection_bids.py +69 -0
  81. package/python/biocore_model/tests/test_core_bridge.py +88 -0
  82. package/python/biocore_model/tests/test_core_bridge_episode.py +14 -0
  83. package/python/biocore_model/tests/test_core_bridge_forget.py +17 -0
  84. package/python/biocore_model/tests/test_core_bridge_identity.py +15 -0
  85. package/python/biocore_model/tests/test_core_bridge_media.py +17 -0
  86. package/python/biocore_model/tests/test_core_bridge_relation.py +17 -0
  87. package/python/biocore_model/tests/test_core_bridge_summary.py +17 -0
  88. package/python/biocore_model/tests/test_core_client.py +156 -0
  89. package/python/biocore_model/tests/test_core_commands.py +146 -0
  90. package/python/biocore_model/tests/test_core_mode.py +161 -0
  91. package/python/biocore_model/tests/test_core_state.py +240 -0
  92. package/python/biocore_model/tests/test_criticality.py +61 -0
  93. package/python/biocore_model/tests/test_cross_session_copy.py +67 -0
  94. package/python/biocore_model/tests/test_debug_values.py +169 -0
  95. package/python/biocore_model/tests/test_defense_mechanisms.py +177 -0
  96. package/python/biocore_model/tests/test_delta_budget.py +157 -0
  97. package/python/biocore_model/tests/test_diag_trace.py +201 -0
  98. package/python/biocore_model/tests/test_directives_compat.py +698 -0
  99. package/python/biocore_model/tests/test_dissonance.py +97 -0
  100. package/python/biocore_model/tests/test_drift_sign.py +87 -0
  101. package/python/biocore_model/tests/test_embedding_fallback.py +277 -0
  102. package/python/biocore_model/tests/test_embedding_local.py +279 -0
  103. package/python/biocore_model/tests/test_embedding_mode.py +175 -0
  104. package/python/biocore_model/tests/test_embedding_modes.py +342 -0
  105. package/python/biocore_model/tests/test_emotion_geometry.py +114 -0
  106. package/python/biocore_model/tests/test_emotion_probe.py +214 -0
  107. package/python/biocore_model/tests/test_emotion_probe_concurrency.py +128 -0
  108. package/python/biocore_model/tests/test_entity_graph.py +198 -0
  109. package/python/biocore_model/tests/test_entity_resolve.py +446 -0
  110. package/python/biocore_model/tests/test_envy.py +173 -0
  111. package/python/biocore_model/tests/test_exit_or_silence.py +209 -0
  112. package/python/biocore_model/tests/test_expr_guard.py +1 -0
  113. package/python/biocore_model/tests/test_expr_intent.py +66 -0
  114. package/python/biocore_model/tests/test_expr_state.py +66 -0
  115. package/python/biocore_model/tests/test_expr_template.py +71 -0
  116. package/python/biocore_model/tests/test_expr_tone.py +41 -0
  117. package/python/biocore_model/tests/test_extreme_scenarios.py +147 -0
  118. package/python/biocore_model/tests/test_feedback_flow.py +185 -0
  119. package/python/biocore_model/tests/test_feedback_guard.py +65 -0
  120. package/python/biocore_model/tests/test_feedback_llm.py +59 -0
  121. package/python/biocore_model/tests/test_feedback_llm_inferred.py +140 -0
  122. package/python/biocore_model/tests/test_feedback_memory.py +63 -0
  123. package/python/biocore_model/tests/test_feedback_user.py +61 -0
  124. package/python/biocore_model/tests/test_frustration_curve.py +66 -0
  125. package/python/biocore_model/tests/test_global_bio_state.py +116 -0
  126. package/python/biocore_model/tests/test_governance.py +181 -0
  127. package/python/biocore_model/tests/test_granularity.py +133 -0
  128. package/python/biocore_model/tests/test_graph_extract.py +224 -0
  129. package/python/biocore_model/tests/test_graph_recall.py +226 -0
  130. package/python/biocore_model/tests/test_graph_sqlite.py +298 -0
  131. package/python/biocore_model/tests/test_growth.py +301 -0
  132. package/python/biocore_model/tests/test_intent_render.py +60 -0
  133. package/python/biocore_model/tests/test_intero_regulation.py +224 -0
  134. package/python/biocore_model/tests/test_intero_style.py +146 -0
  135. package/python/biocore_model/tests/test_item3_numeric.py +105 -0
  136. package/python/biocore_model/tests/test_item6_numeric.py +116 -0
  137. package/python/biocore_model/tests/test_layered_memory.py +174 -0
  138. package/python/biocore_model/tests/test_leak_guard.py +75 -0
  139. package/python/biocore_model/tests/test_learning_probe.py +93 -0
  140. package/python/biocore_model/tests/test_life_loop.py +222 -0
  141. package/python/biocore_model/tests/test_life_loop_10s.py +131 -0
  142. package/python/biocore_model/tests/test_local_embedding_health.py +258 -0
  143. package/python/biocore_model/tests/test_memory_affect_encoding.py +79 -0
  144. package/python/biocore_model/tests/test_memory_backend.py +332 -0
  145. package/python/biocore_model/tests/test_memory_dedup.py +316 -0
  146. package/python/biocore_model/tests/test_memory_dual.py +219 -0
  147. package/python/biocore_model/tests/test_memory_dual_wiring.py +219 -0
  148. package/python/biocore_model/tests/test_memory_feedback.py +241 -0
  149. package/python/biocore_model/tests/test_memory_fixes.py +84 -0
  150. package/python/biocore_model/tests/test_memory_forgetting.py +58 -0
  151. package/python/biocore_model/tests/test_memory_inject.py +211 -0
  152. package/python/biocore_model/tests/test_memory_mood_recall.py +118 -0
  153. package/python/biocore_model/tests/test_memory_store.py +372 -0
  154. package/python/biocore_model/tests/test_metacog.py +103 -0
  155. package/python/biocore_model/tests/test_migrate.py +245 -0
  156. package/python/biocore_model/tests/test_migrate_store.py +194 -0
  157. package/python/biocore_model/tests/test_mind_wander.py +65 -0
  158. package/python/biocore_model/tests/test_mood.py +35 -0
  159. package/python/biocore_model/tests/test_narrative.py +114 -0
  160. package/python/biocore_model/tests/test_needs_esteem.py +51 -0
  161. package/python/biocore_model/tests/test_needs_events.py +205 -0
  162. package/python/biocore_model/tests/test_needs_sleep.py +54 -0
  163. package/python/biocore_model/tests/test_noise_bank.py +54 -0
  164. package/python/biocore_model/tests/test_numeric_schema.py +98 -0
  165. package/python/biocore_model/tests/test_output_protocol.py +65 -0
  166. package/python/biocore_model/tests/test_page_debug.py +147 -0
  167. package/python/biocore_model/tests/test_page_status_autonomy.py +215 -0
  168. package/python/biocore_model/tests/test_pipeline.py +345 -0
  169. package/python/biocore_model/tests/test_pipeline_api.py +192 -0
  170. package/python/biocore_model/tests/test_pipeline_mode.py +222 -0
  171. package/python/biocore_model/tests/test_plugin_config.py +85 -0
  172. package/python/biocore_model/tests/test_policy_learning.py +116 -0
  173. package/python/biocore_model/tests/test_possible_selves.py +88 -0
  174. package/python/biocore_model/tests/test_predictor.py +227 -0
  175. package/python/biocore_model/tests/test_preference_drift.py +142 -0
  176. package/python/biocore_model/tests/test_preset.py +142 -0
  177. package/python/biocore_model/tests/test_proactive_context.py +70 -0
  178. package/python/biocore_model/tests/test_proactive_history.py +90 -0
  179. package/python/biocore_model/tests/test_proactive_memory.py +141 -0
  180. package/python/biocore_model/tests/test_proactive_send_record.py +88 -0
  181. package/python/biocore_model/tests/test_probe_contract.py +71 -0
  182. package/python/biocore_model/tests/test_prospective.py +154 -0
  183. package/python/biocore_model/tests/test_provider_fallback.py +89 -0
  184. package/python/biocore_model/tests/test_reconstruction.py +111 -0
  185. package/python/biocore_model/tests/test_regulation_strategies.py +228 -0
  186. package/python/biocore_model/tests/test_relation_stage.py +114 -0
  187. package/python/biocore_model/tests/test_relationship_stage.py +59 -0
  188. package/python/biocore_model/tests/test_release_140.py +55 -0
  189. package/python/biocore_model/tests/test_repair_after_boundary.py +249 -0
  190. package/python/biocore_model/tests/test_reply_limit.py +86 -0
  191. package/python/biocore_model/tests/test_reply_limit_persist.py +48 -0
  192. package/python/biocore_model/tests/test_reply_split.py +52 -0
  193. package/python/biocore_model/tests/test_reply_split_astrbot.py +66 -0
  194. package/python/biocore_model/tests/test_reply_split_inject.py +53 -0
  195. package/python/biocore_model/tests/test_rerank.py +229 -0
  196. package/python/biocore_model/tests/test_rollback.py +175 -0
  197. package/python/biocore_model/tests/test_runtime.py +175 -0
  198. package/python/biocore_model/tests/test_runtime_active.py +205 -0
  199. package/python/biocore_model/tests/test_runtime_pipeline.py +1583 -0
  200. package/python/biocore_model/tests/test_runtime_proactive.py +231 -0
  201. package/python/biocore_model/tests/test_scheduler.py +79 -0
  202. package/python/biocore_model/tests/test_secrecy.py +105 -0
  203. package/python/biocore_model/tests/test_self_esteem.py +45 -0
  204. package/python/biocore_model/tests/test_self_intent.py +347 -0
  205. package/python/biocore_model/tests/test_self_interest.py +183 -0
  206. package/python/biocore_model/tests/test_self_layer_wiring.py +198 -0
  207. package/python/biocore_model/tests/test_self_verification.py +113 -0
  208. package/python/biocore_model/tests/test_situation.py +142 -0
  209. package/python/biocore_model/tests/test_sleep_circadian.py +41 -0
  210. package/python/biocore_model/tests/test_social_pain.py +49 -0
  211. package/python/biocore_model/tests/test_social_repair.py +67 -0
  212. package/python/biocore_model/tests/test_social_theory.py +78 -0
  213. package/python/biocore_model/tests/test_source_monitoring.py +204 -0
  214. package/python/biocore_model/tests/test_speak_like_group.py +36 -0
  215. package/python/biocore_model/tests/test_stages.py +226 -0
  216. package/python/biocore_model/tests/test_state_tag.py +86 -0
  217. package/python/biocore_model/tests/test_template_expr.py +65 -0
  218. package/python/biocore_model/tests/test_text_inference.py +70 -0
  219. package/python/biocore_model/tests/test_theta_params.py +115 -0
  220. package/python/biocore_model/tests/test_topic_control.py +200 -0
  221. package/python/biocore_model/tests/test_turn_memory.py +105 -0
  222. package/python/biocore_model/tests/test_turn_memory_panel.py +174 -0
  223. package/python/biocore_model/tests/test_ui_settings.py +84 -0
  224. package/python/biocore_model/tests/test_ui_settings_authority.py +179 -0
  225. package/python/biocore_model/tests/test_user_appraisal_async.py +155 -0
  226. package/python/biocore_model/tests/test_user_classify.py +122 -0
  227. package/python/biocore_model/tests/test_value_order.py +117 -0
  228. package/python/biocore_model/tests/test_voice_bank.py +105 -0
  229. package/python/biocore_model/tests/test_waiting_sense.py +216 -0
  230. package/python/biocore_model/tests/test_x_directives.py +101 -0
  231. package/python/biocore_model/tests/ui_compat_check.mjs +22 -0
  232. package/python/biocore_model/tests/view_mode_check.mjs +17 -0
  233. package/python/biocore_runtime/autonomy.py +208 -0
  234. package/python/biocore_runtime/core_state.py +302 -0
  235. package/python/biocore_runtime/governance.py +495 -0
  236. package/python/biocore_runtime/growth.py +528 -0
  237. package/python/biocore_runtime/pipeline.py +850 -23
  238. package/python/biocore_runtime/relationship_state.py +214 -0
  239. package/python/biocore_runtime/self_layer.py +103 -0
  240. package/python/biocore_runtime/service.py +162 -0
  241. package/python/biocore_runtime/standby.py +472 -0
  242. package/ui/panel-layout.js +83 -39
  243. package/ui/panel.css +885 -743
  244. package/ui/panel.html +356 -296
  245. package/ui/panel.js +739 -865
@@ -0,0 +1,205 @@
1
+ # -*- coding: utf-8 -*-
2
+ """PIPE-2 active-mode tests: run_active payload, fallback, ctx enrichment.
3
+
4
+ Covers: prompt non-empty / empty-dict fallback / shadow untouched / trace
5
+ fields / snapshot+relationship enrichment / motive+silence+intent+tone.
6
+ """
7
+ import json
8
+ import os
9
+ import tempfile
10
+ import unittest
11
+
12
+ from biocore_model import expr_tone as _tone
13
+ from biocore_model import pipeline as pl
14
+ from biocore_model import runtime as rt
15
+
16
+
17
+ class FakeEvent:
18
+ def __init__(self, text="你好", umo="umo-1", sender="u-1"):
19
+ self.message_str = text
20
+ self.unified_msg_origin = umo
21
+ self._sender = sender
22
+
23
+ def get_sender_id(self):
24
+ return self._sender
25
+
26
+
27
+ class FakeCore:
28
+ def __init__(self):
29
+ self._snapshot = {
30
+ "emotion": "calm", "intensity": 0.5, "v": 0.1, "a": 0.2, "d": 0.5,
31
+ "social": 0.5, "stress": 0.1, "energy": 0.6, "trust": 0.5,
32
+ "self_esteem": 0.7,
33
+ "labels": {"emotion": "calm", "need": "talk"},
34
+ "spectrum_probs": [{"name": "calmness", "p": 0.5}],
35
+ }
36
+
37
+ def snapshot(self):
38
+ return dict(self._snapshot)
39
+
40
+
41
+ class FakePlugin:
42
+ def __init__(self, data_dir=None, persona_text=""):
43
+ self.data_dir = data_dir
44
+ self.persona_text = persona_text
45
+
46
+ def _relationship_of(self, user):
47
+ return {"state": {"closeness": 0.6, "trust": 0.5}}
48
+
49
+
50
+ class BoomPipeline(pl.Pipeline):
51
+ def run(self, ctx=None, start=None):
52
+ raise RuntimeError("active boom")
53
+
54
+
55
+ def make_ctx(text="你好", core=None, plugin=None, now=1000.0, **meta):
56
+ return rt.make_request_ctx(plugin=plugin or FakePlugin(),
57
+ event=FakeEvent(text), core=core or FakeCore(),
58
+ text=text, now=now, meta=dict(meta))
59
+
60
+
61
+ class RunActiveTest(unittest.TestCase):
62
+ def setUp(self):
63
+ rt.reset_mode()
64
+ rt.reset_pipeline()
65
+
66
+ def test_active_returns_prompt_payload(self):
67
+ out = rt.run_active(make_ctx())
68
+ self.assertIsInstance(out, dict)
69
+ self.assertTrue(out.get("prompt_user") or out.get("prompt_system"))
70
+ self.assertIsInstance(out.get("prompt_system"), str)
71
+ self.assertIsInstance(out.get("prompt_user"), str)
72
+ self.assertIsInstance(out.get("trace"), dict)
73
+
74
+ def test_active_trace_fields(self):
75
+ out = rt.run_active(make_ctx())
76
+ trace = out["trace"]
77
+ self.assertIn("stages", trace)
78
+ self.assertIn("ring", trace)
79
+ self.assertEqual(trace["runtime"]["schema"], rt.SCHEMA)
80
+ self.assertEqual(trace["runtime"]["mode"], "active")
81
+ self.assertIn("memory", trace["runtime"]["switches"])
82
+ self.assertEqual([row["name"] for row in trace["stages"]],
83
+ list(rt.get_pipeline().names()))
84
+
85
+ def test_active_failure_returns_empty_dict(self):
86
+ self.assertEqual(rt.run_active(make_ctx(), pipeline=BoomPipeline()), {})
87
+
88
+ def test_active_garbage_ctx_never_raises(self):
89
+ self.assertIsInstance(rt.run_active(None), dict)
90
+ self.assertIsInstance(rt.run_active({"meta": "bad"}), dict)
91
+
92
+ def test_active_sets_active_meta(self):
93
+ ctx = make_ctx()
94
+ out = rt.run_active(ctx)
95
+ self.assertTrue(out)
96
+ self.assertEqual(ctx["meta"]["pipeline_mode"], "active")
97
+ self.assertFalse(ctx["meta"]["shadow"])
98
+
99
+
100
+ class ShadowUnchangedTest(unittest.TestCase):
101
+ def setUp(self):
102
+ rt.reset_mode()
103
+ rt.reset_pipeline()
104
+
105
+ def test_shadow_run_reply_still_returns_ctx(self):
106
+ ctx = make_ctx()
107
+ out = rt.run_reply(ctx)
108
+ self.assertIsInstance(out, dict)
109
+ self.assertTrue(out["meta"]["shadow"])
110
+ self.assertNotIn("prompt_system", out)
111
+
112
+ def test_run_active_does_not_change_mode(self):
113
+ rt.run_active(make_ctx())
114
+ self.assertEqual(rt.get_mode(), "shadow")
115
+ out = rt.run_reply(make_ctx(meta_llm=True))
116
+ self.assertIsInstance(out, dict)
117
+ self.assertIn("trace", out)
118
+ self.assertNotIn("prompt_system", out)
119
+
120
+
121
+ class EnrichCtxTest(unittest.TestCase):
122
+ def test_snapshot_and_relationship(self):
123
+ core = FakeCore()
124
+ plugin = FakePlugin()
125
+ ctx = make_ctx(core=core, plugin=plugin)
126
+ ctx["core"] = core
127
+ ctx["plugin"] = plugin
128
+ out = rt.enrich_ctx(ctx)
129
+ self.assertEqual(out["state"]["emotion"], "calm")
130
+ self.assertEqual(out["relationship"]["state"]["closeness"], 0.6)
131
+ self.assertEqual(out["meta"]["relationship"], out["relationship"])
132
+
133
+ def test_caller_fields_not_overwritten(self):
134
+ ctx = make_ctx()
135
+ ctx["state"] = {"emotion": "given"}
136
+ ctx["relationship"] = {"state": {"closeness": 0.1}}
137
+ ctx["intent"] = {"kind": "given"}
138
+ out = rt.enrich_ctx(ctx)
139
+ self.assertEqual(out["state"], {"emotion": "given"})
140
+ self.assertEqual(out["relationship"]["state"]["closeness"], 0.1)
141
+ self.assertEqual(out["intent"], {"kind": "given"})
142
+
143
+ def test_motive_silence_intent_tone_from_accumulator(self):
144
+ now = 1000000.0
145
+ data = tempfile.mkdtemp(prefix="bc_active_")
146
+ self.addCleanup(lambda: __import__("shutil").rmtree(data, True))
147
+ with open(os.path.join(data, "ui_settings.json"), "w", encoding="utf-8") as fh:
148
+ json.dump({"schema": 1, "autonomy": {"accumulator": {
149
+ "V": 0.2, "theta": 0.55, "last_user_msg_ts": now - 7200.0,
150
+ "intent": {"kind": "social_gap"}, "tone": {"text": "gentle"}}}}, fh)
151
+ ctx = make_ctx(plugin=FakePlugin(data), now=now)
152
+ out = rt.enrich_ctx(ctx)
153
+ self.assertIsInstance(out.get("motive"), dict)
154
+ self.assertIn("motive", out["motive"])
155
+ self.assertIn("drift", out["motive"])
156
+ self.assertEqual(out["silence"]["hours"], 2.0)
157
+ self.assertEqual(out["intent"], {"kind": "social_gap"})
158
+ self.assertEqual(out["tone"], {"text": "gentle"})
159
+
160
+
161
+ class LongPromptTest(unittest.TestCase):
162
+ PERSONA = ("你是小灰,一只灰色羽毛的拟人小生物,喜欢安静地陪着对方,说话短、语气轻。" * 120)[:2636]
163
+
164
+ def setUp(self):
165
+ rt.reset_mode()
166
+ rt.reset_pipeline()
167
+
168
+ def _plugin(self, now=1000000.0):
169
+ data = tempfile.mkdtemp(prefix="bc_active_long_")
170
+ self.addCleanup(lambda: __import__("shutil").rmtree(data, True))
171
+ with open(os.path.join(data, "ui_settings.json"), "w", encoding="utf-8") as fh:
172
+ json.dump({"schema": 1, "autonomy": {"accumulator": {
173
+ "V": 0.3, "theta": 0.55, "last_user_msg_ts": now - 7200.0,
174
+ "intent": {"kind": "social_gap", "text_hint": "想接住情绪"},
175
+ "tone": {"text": "先接住情绪,再谈事情"}}}}, fh)
176
+ return FakePlugin(data, persona_text=self.PERSONA)
177
+
178
+ def test_active_prompt_has_persona_state_gap_intent_tone_protocol(self):
179
+ out = rt.run_active(make_ctx(plugin=self._plugin(), now=1000000.0))
180
+ system = out.get("prompt_system", "")
181
+ user = out.get("prompt_user", "")
182
+ prompt = (system + "\n" + user).strip()
183
+ self.assertGreater(len(prompt), 1200)
184
+ self.assertIn(self.PERSONA[:40], system)
185
+ self.assertNotIn("【输出格式", system)
186
+ self.assertNotIn("<bc>", system)
187
+ self.assertNotIn("【输出格式", user)
188
+ self.assertIn("情绪", user) # state_block
189
+ self.assertIn("关系", user) # relationship
190
+ self.assertIn("间隔", user) # gap
191
+ self.assertTrue("social_gap" in user or "想接住情绪" in user) # intent
192
+ tone_text = str(_tone.tone_block("calm", emotion="calm", intensity=0.5,
193
+ self_esteem=0.7, regulation=None).get("text") or "")
194
+ self.assertTrue(tone_text[:6] in user) # tone
195
+
196
+ def test_run_prompt_enriches_for_main_path(self):
197
+ # main.py calls run_prompt directly; it must self-enrich too.
198
+ out = rt.run_prompt(make_ctx(plugin=self._plugin(), now=1000000.0))
199
+ self.assertIsInstance(out, dict)
200
+ self.assertIn(self.PERSONA[:40], out.get("prompt_system", ""))
201
+ self.assertGreater(len(out.get("prompt_system", "")) + len(out.get("prompt_user", "")), 1200)
202
+
203
+
204
+ if __name__ == "__main__":
205
+ unittest.main()