@furongjun1999/dsh-memory 0.9.23 → 0.10.3

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 (118) hide show
  1. package/CHANGELOG.en.md +515 -404
  2. package/CHANGELOG.md +642 -449
  3. package/README.en.md +244 -240
  4. package/README.md +272 -262
  5. package/codebuddy/CODEBUDDY.md +1 -1
  6. package/docs/discipline/templates/full.md.tmpl +1 -1
  7. package/docs/discipline/templates/rules.mdc.tmpl +1 -1
  8. package/docs/en/mdcg/world-model-endpoint.md +1 -1
  9. package/docs/mdcg/cogmap_ops.md +19 -16
  10. package/lib/client.js +29 -3
  11. package/lib/hooks.d.ts +12 -0
  12. package/lib/hooks.js +43 -1
  13. package/lib/tools.d.ts +2 -2
  14. package/md_cg/bucketindex.py +231 -0
  15. package/md_cg/bucketscope.py +357 -0
  16. package/md_cg/cohesion.py +337 -0
  17. package/md_cg/config_registry_bulk.py +24 -10
  18. package/md_cg/config_validate.py +14 -2
  19. package/md_cg/constraint_audit.py +231 -0
  20. package/md_cg/constraint_watch.py +206 -0
  21. package/md_cg/context_audit.py +240 -0
  22. package/md_cg/context_plan.py +142 -0
  23. package/md_cg/detrerank.py +137 -0
  24. package/md_cg/distill.py +247 -0
  25. package/md_cg/dossier.py +151 -0
  26. package/md_cg/entities.py +133 -0
  27. package/md_cg/fsutil.py +135 -0
  28. package/md_cg/govern/__init__.py +23 -0
  29. package/md_cg/iface/__init__.py +46 -0
  30. package/md_cg/iface/_verify.py +609 -0
  31. package/md_cg/iface/contracts.py +337 -0
  32. package/md_cg/judgment_manifest.py +14 -0
  33. package/md_cg/kernel/__init__.py +27 -0
  34. package/md_cg/mcp_server.py +6044 -5761
  35. package/md_cg/mdcg.py +501 -16
  36. package/md_cg/mdcos.py +546 -12
  37. package/md_cg/metacognition.py +66 -13
  38. package/md_cg/mutate_extract_shipped.py +126 -0
  39. package/md_cg/mutate_ledger_e2e.py +100 -0
  40. package/md_cg/op_table.py +22 -0
  41. package/md_cg/probe_c_ledger_integrity.py +258 -0
  42. package/md_cg/probe_d_retirement_discipline.py +263 -0
  43. package/md_cg/profiles.py +298 -0
  44. package/md_cg/protocol.py +7 -1
  45. package/md_cg/reldate.py +142 -0
  46. package/md_cg/review_cli.py +6 -1
  47. package/md_cg/run_tests.py +30 -1
  48. package/md_cg/scopeselect.py +214 -0
  49. package/md_cg/scrub.py +66 -9
  50. package/md_cg/selfstmt.py +139 -0
  51. package/md_cg/state_extract.py +149 -0
  52. package/md_cg/state_slots.py +62 -10
  53. package/md_cg/state_view.py +181 -0
  54. package/md_cg/structboost.py +179 -0
  55. package/md_cg/sustain.py +28 -2
  56. package/md_cg/test_alternatives_historical.py +165 -0
  57. package/md_cg/test_b2_sensitivity_landing.py +226 -223
  58. package/md_cg/test_b3_merge_keeps_content.py +608 -583
  59. package/md_cg/test_bucket_cards.py +85 -0
  60. package/md_cg/test_bucket_day_order.py +74 -0
  61. package/md_cg/test_bucket_quota.py +79 -0
  62. package/md_cg/test_bucket_recency_guards.py +75 -0
  63. package/md_cg/test_bucket_three_causes.py +83 -0
  64. package/md_cg/test_bucket_time_rounds.py +87 -0
  65. package/md_cg/test_bucketindex.py +130 -0
  66. package/md_cg/test_bucketscope_early.py +71 -0
  67. package/md_cg/test_cohesion.py +107 -0
  68. package/md_cg/test_cond_term_fold_gate.py +1210 -0
  69. package/md_cg/test_cond_term_neg_scope.py +147 -0
  70. package/md_cg/test_constraint_audit.py +87 -0
  71. package/md_cg/test_constraint_watch.py +108 -0
  72. package/md_cg/test_context_audit.py +110 -0
  73. package/md_cg/test_context_plan.py +81 -0
  74. package/md_cg/test_detrerank.py +157 -0
  75. package/md_cg/test_gate_four_kpi.py +136 -0
  76. package/md_cg/test_generation_guard.py +14 -2
  77. package/md_cg/test_issue192_move_layer_indices_guard.py +48 -0
  78. package/md_cg/test_issue39_utf8_stdio.py +572 -572
  79. package/md_cg/test_issue413_preimage_failclosed.py +147 -9
  80. package/md_cg/test_issue768_overwrite_time_window_anchor.py +135 -0
  81. package/md_cg/test_issue789_log_plaintext_probe.py +100 -0
  82. package/md_cg/test_issue790_verb_negation.py +77 -0
  83. package/md_cg/test_issue810_root_guard.py +71 -0
  84. package/md_cg/test_issue812_info_index_stale.py +78 -0
  85. package/md_cg/test_issue827_weaken_dedup.py +361 -0
  86. package/md_cg/test_issue829_calibration_positive_gate.py +473 -0
  87. package/md_cg/test_kernel_iface_contracts.py +18 -0
  88. package/md_cg/test_md_cg_no_hive_dep.py +238 -17
  89. package/md_cg/test_probe_cd_shipped.py +385 -0
  90. package/md_cg/test_recent_tail.py +93 -0
  91. package/md_cg/test_run_tests_entry_gates.py +110 -0
  92. package/md_cg/test_scopeselect.py +70 -0
  93. package/md_cg/test_scopeselect_clock.py +70 -0
  94. package/md_cg/test_session_attribution_consistency.py +835 -813
  95. package/md_cg/test_state_extract_shipped.py +162 -0
  96. package/md_cg/test_state_ledger_chain.py +207 -0
  97. package/md_cg/test_state_ledger_e2e.py +145 -0
  98. package/md_cg/test_structboost.py +102 -0
  99. package/md_cg/test_timeboost.py +83 -0
  100. package/md_cg/test_timeboost_relativedate.py +71 -0
  101. package/md_cg/test_topicagg.py +129 -0
  102. package/md_cg/timeboost.py +223 -0
  103. package/md_cg/tokens.py +1 -1
  104. package/md_cg/topicagg.py +142 -0
  105. package/md_cg/version_anchor.py +84 -1
  106. package/md_cg/whitebox_kb/wisdom/code_compose.py +33 -5
  107. package/md_cg/whitebox_kb/wisdom/code_solidified.json +6195 -6195
  108. package/md_cg/whitebox_kb/wisdom/compose_engine.py +5 -1
  109. package/md_cg/whitebox_kb/wisdom/role_compose.py +271 -268
  110. package/package.json +1 -1
  111. package/src/hooks.ts +43 -1
  112. package/ui/minimal/payload/build-ui.mjs +41 -2
  113. package/ui/minimal/payload/lib/client.js +29 -3
  114. package/ui/minimal/payload/web/app.js +3 -1
  115. package/ui/minimal/payload/web/client.js +30 -3
  116. package/web/app.js +3 -1
  117. package/web/client.js +30 -3
  118. package/zcode/AGENTS.md +1 -1
@@ -26,7 +26,8 @@
26
26
 
27
27
  import re
28
28
 
29
- __all__ = ["FIELDS", "parse_anchor", "check_anchor", "ANCHOR_LINE_RE"]
29
+ __all__ = ["FIELDS", "parse_anchor", "check_anchor", "check_staleness",
30
+ "scan_dir", "ANCHOR_LINE_RE"]
30
31
 
31
32
  #: 三元字段(键名 → 中文别名,都接受)
32
33
  FIELDS = ("theory", "architecture", "projection")
@@ -101,6 +102,88 @@ def check_anchor(text):
101
102
  "found": rep["found"], "legacy": legacy}
102
103
 
103
104
 
105
+ def _norm(v):
106
+ """归一化版本串:去空白与全角空格,便于比较「智能论 3.4」与「智能论3.4」。"""
107
+ import re as _re
108
+ return _re.sub(r"\s+", "", str(v or ""))
109
+
110
+
111
+ #: 架构名与版本的分隔约定(2026-10-24 第五十三轮):
112
+ #: 规范写法是「架构名 v版本」,如「上下文管理研究 v6」。
113
+ #: 若写成「上下文管理研究(四十九轮)」这类不带 v 的形式,会被判为 nonstandard——
114
+ #: **不猜它的版本**(第五十二轮实测:把轮次当版本会让检查变成噪声源)。
115
+ _ARCH_VER_RE = re.compile(r"^(.*?)\s+v(\d+(?:\.\d+)*)\s*$")
116
+
117
+
118
+ def split_arch(arch_field):
119
+ """把「架构名 v版本」拆成 (名字, 版本)。不规范返回 (原文, None)。"""
120
+ m = _ARCH_VER_RE.match(str(arch_field or "").strip())
121
+ if not m:
122
+ return str(arch_field or "").strip(), None
123
+ return m.group(1).strip(), "v" + m.group(2)
124
+
125
+
126
+ def check_staleness(text, current):
127
+ """陈化检查——判断锚里的理论/架构版本是否还是当前版本。
128
+
129
+ 为什么需要(2026-10-24 第五十一、五十二轮):
130
+ 第五十一轮发现「过期」是三种不可测失效之一,对策是「版本锚」。
131
+ 但实测发现:56 份文档 100% 都有锚,**却没有工具核对锚是否过期**——
132
+ 写上 ≠ 核对。本函数补上核对这一步。
133
+
134
+ 参数:
135
+ current 当前版本,形如 {"theory": "智能论 3.4", "architecture": "..."}。
136
+ **必须由调用方提供**——本模块不知道「现在是什么版本」,
137
+ 那是外部事实,不能猜。
138
+
139
+ 返回 dict:
140
+ ok True=锚与当前一致;False=**过期**;None=无锚或无法判定
141
+ stale [{field, found, current}] 过期的字段
142
+ anchor 解析出的锚
143
+
144
+ **「本投影」版本不参与比较**——它是本文档自己的版本,无所谓过期。
145
+ """
146
+ rep = parse_anchor(text)
147
+ # legacy 材料:已显式标注为历史(I18 的 legacy_no_anchor)。
148
+ # 它「没有三元锚」是**明示的选择**,不是遗漏——故与「忘了标」区分开。
149
+ legacy = LEGACY_MARK in str(text or "")
150
+ if not rep.get("found"):
151
+ return {"ok": None, "stale": [], "anchor": {}, "legacy": legacy,
152
+ "reason": ("已标 legacy(历史材料),不参与陈化检查" if legacy
153
+ else "没有版本锚,无从判断是否过期")}
154
+ stale = []
155
+ notes = []
156
+
157
+ # theory:直接比较
158
+ want_t = (current or {}).get("theory")
159
+ got_t = rep["anchor"].get("theory")
160
+ if want_t and got_t and _norm(got_t) != _norm(want_t):
161
+ stale.append({"field": "theory", "found": got_t, "current": want_t})
162
+
163
+ # architecture:**按架构名分组比较**(2026-10-24 第五十三轮修正)
164
+ # 一个 current 比所有文档会让「不同架构」被判过期——实测 13 份里 5 份是别的架构。
165
+ got_a = rep["anchor"].get("architecture")
166
+ want_a = (current or {}).get("architecture")
167
+ arch_map = want_a if isinstance(want_a, dict) else None
168
+ if got_a:
169
+ name, ver = split_arch(got_a)
170
+ if arch_map is not None:
171
+ if name not in arch_map:
172
+ notes.append("架构「%s」不在当前版本表中,不判过期(可能是另一份架构或历史材料)" % name)
173
+ elif ver is None:
174
+ notes.append("架构字段「%s」不含 v 版本号,格式不规范,不判过期也不判通过" % got_a)
175
+ elif _norm(ver) != _norm(arch_map.get(name)):
176
+ stale.append({"field": "architecture", "found": got_a,
177
+ "current": "%s %s" % (name, arch_map.get(name))})
178
+ elif want_a:
179
+ if _norm(got_a) != _norm(want_a):
180
+ stale.append({"field": "architecture", "found": got_a, "current": want_a})
181
+
182
+ return {"ok": (None if notes else not stale), "stale": stale, "anchor": rep["anchor"],
183
+ "notes": notes,
184
+ "note": "本投影版本不参与比较;架构按名分组比较"}
185
+
186
+
104
187
  def scan_dir(directory, suffix=".md"):
105
188
  """扫描目录下的对外材料,分类为 ok/legacy/todo。
106
189
 
@@ -9,7 +9,7 @@
9
9
  ⑤ 固化:验证通过代码 → 固化 JSON → 同任务直出
10
10
  零 LLM:全部白箱确定性生成 + 自校验(语法/测试是物理基底裁决)。
11
11
  """
12
- import sys, json, os, ast
12
+ import sys, json, os, ast, tempfile
13
13
  sys.stdout.reconfigure(encoding='utf-8')
14
14
 
15
15
 
@@ -596,8 +596,7 @@ def domain_solidify(question, domain=None, uid=None):
596
596
  "source": "domain_solidified", "domain": domain}
597
597
  CODE_SOLIDIFIED[key] = entry
598
598
  try:
599
- json.dump(CODE_SOLIDIFIED, open(_SOL_FILE, "w", encoding="utf-8"),
600
- ensure_ascii=False, indent=1)
599
+ _save_solidified()
601
600
  except Exception:
602
601
  pass
603
602
  return entry
@@ -802,6 +801,36 @@ if os.path.exists(_SOL_FILE):
802
801
  CODE_SOLIDIFIED = {}
803
802
 
804
803
 
804
+ def _save_solidified():
805
+ """把 `CODE_SOLIDIFIED` 落盘——**必须以 LF 写**(`newline="\\n"`)。
806
+
807
+ `code_solidified.json` 是**入库文件**,仓内它的规范换行是 LF(`\n`)。
808
+ 文本模式 `open(..., "w")` 不声明 `newline=` 时,Windows 上 `json.dump`
809
+ 会把每个 `\n` 写成 `\r\n` ⇒ 跑一次相关测试,`git status` 就多一条
810
+ 「12390 行全改」的噪声(实测:6195 行 LF 全变 CRLF,JSON 语义不变)。
811
+ 这种改动既无意义又会被误提交,故在写侧一次性钉死换行。
812
+
813
+ 写入用 `atomic_write` 语义的临时文件 + `os.replace`,避免半写坏档:
814
+ 固化表是 `code_route` 的直出面,读侧遇到坏 JSON 会静默清空(见上面
815
+ `except: CODE_SOLIDIFIED = {}`),那会把已固化的条目整批丢掉。
816
+ """
817
+ d = os.path.dirname(_SOL_FILE)
818
+ fd, tmp = tempfile.mkstemp(prefix=".code_solidified.", suffix=".tmp", dir=d)
819
+ try:
820
+ with os.fdopen(fd, "w", encoding="utf-8", newline="\n") as fh:
821
+ json.dump(CODE_SOLIDIFIED, fh, ensure_ascii=False, indent=1)
822
+ # 不补尾部换行:入库基线 `code_solidified.json` 末尾**无换行**
823
+ # (`git show` 上是 "")。补一行会让每次
824
+ # 落盘都产生一条 1 行的 diff,等于把 CRLF 噪声换成另一种噪声。
825
+ os.replace(tmp, _SOL_FILE)
826
+ except Exception:
827
+ try:
828
+ os.unlink(tmp)
829
+ except OSError:
830
+ pass
831
+ raise
832
+
833
+
805
834
  def code_solidify(question, task=None, uid=None, fn=None):
806
835
  """固化:组合生成 + 自校验通过 → 固化(自举纪律:未验证代码不固化)"""
807
836
  lang = detect_language(question)
@@ -816,8 +845,7 @@ def code_solidify(question, task=None, uid=None, fn=None):
816
845
  "source": "code_solidified", "lang": lang}
817
846
  CODE_SOLIDIFIED[key] = entry
818
847
  try:
819
- json.dump(CODE_SOLIDIFIED, open(_SOL_FILE, "w", encoding="utf-8"),
820
- ensure_ascii=False, indent=1)
848
+ _save_solidified()
821
849
  except Exception:
822
850
  pass
823
851
  return entry