@furongjun1999/dsh-memory 0.9.15 → 0.9.17
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.
- package/CHANGELOG.md +85 -0
- package/README.md +15 -109
- package/lib/hooks.js +5 -0
- package/lib/lib/console_web.mjs +11 -3
- package/lib/lib/hook_audit.d.ts +15 -0
- package/lib/lib/hook_audit.js +28 -0
- package/md_cg/config_registry.py +28 -0
- package/md_cg/mcp_server.py +9 -0
- package/md_cg/mdcg.py +10 -2
- package/md_cg/mdcos.py +40 -12
- package/md_cg/security.py +18 -2
- package/md_cg/test_config_registry_silent_fallback.py +90 -0
- package/md_cg/test_generation_guard.py +2 -1
- package/md_cg/test_i50c_meta_passthrough.py +3 -3
- package/md_cg/test_issue708_writegate_observable.py +141 -0
- package/md_cg/test_issue709_review_chain_enforce.py +132 -0
- package/md_cg/writegate.py +37 -0
- package/package.json +1 -1
- package/src/hooks.ts +5 -0
- package/src/lib/console_web.mjs +11 -3
- package/src/lib/hook_audit.ts +34 -1
- package/ui/minimal/integrity.json +2 -2
- package/ui/minimal/payload/lib/lib/console_web.mjs +11 -3
- package/ui/minimal/payload/src/lib/console_web.mjs +11 -3
package/md_cg/security.py
CHANGED
|
@@ -288,7 +288,7 @@ class Principal:
|
|
|
288
288
|
f"写入敏感度 {sensitivity} 超出 clearance {self.clearance}")
|
|
289
289
|
|
|
290
290
|
# 生效条件:先要求 self.require_write(sensitivity) 未抛异常;随后将形参 layer 为假值(None/空串)时按 "knowledge" 处理,并要求 self.allows_layer(layer) 为 True;最后按 MDCG_WRITE_GATE 三档过**分层写入严格度闸**(writegate):off 零介入放行、warn 记录并放行、enforce 对 deny/require_review 抛 AccessDenied。
|
|
291
|
-
def require_layer_write(self, layer: str, sensitivity: str, reviewers=None):
|
|
291
|
+
def require_layer_write(self, layer: str, sensitivity: str, reviewers=None, *, skip_gate: bool = False):
|
|
292
292
|
"""写层校验:密级 + 层白名单 + **分层复核闸**(2026-10-27 使用者裁定)。
|
|
293
293
|
|
|
294
294
|
分层严格度(writegate.LAYER_TIERS):情景/目标/未解/负记忆 = 0 档
|
|
@@ -298,6 +298,14 @@ class Principal:
|
|
|
298
298
|
|
|
299
299
|
reviewers 为本次写入已取得的复核单元(缺省取环境声明 MDCG_REVIEWERS),
|
|
300
300
|
只在闸启用(warn/enforce)时有意义;off 档完全不介入,行为与历史逐位相同。
|
|
301
|
+
|
|
302
|
+
**skip_gate(issue #709 连带发现,2026-10-28)**:只给**不落记忆盘**的入队动作用
|
|
303
|
+
(当前唯一调用方=`MdCGSecure.propose`)。理由:propose 只把候选写进 inbox、
|
|
304
|
+
不写业务节点,却按**目标层**要求复核单元 ⇒ enforce 下形成死锁:
|
|
305
|
+
「要写 knowledge 需 reflect → 要 reflect 需裁决 → 要裁决需有提案 → 提案又要 reflect」。
|
|
306
|
+
跳过闸**不等于绕过写入闸**:accept 落盘时仍走 `add()` 的同一道闸,复核不被削弱。
|
|
307
|
+
层白名单与密级检查**照常执行**(这里跳过的只有 write_gate 一档)。
|
|
308
|
+
**禁止用于任何真正落盘的路径**——那等于关闸。
|
|
301
309
|
"""
|
|
302
310
|
self.require_write(sensitivity)
|
|
303
311
|
layer = layer or "knowledge"
|
|
@@ -305,6 +313,8 @@ class Principal:
|
|
|
305
313
|
raise AccessDenied(
|
|
306
314
|
f"角色 {self.role} 无权写入 {layer} 层"
|
|
307
315
|
f"(可写层 {list(self.layers_allow) if self.layers_allow is not None else '不限'})")
|
|
316
|
+
if skip_gate:
|
|
317
|
+
return None
|
|
308
318
|
_wg_verdict = self._write_gate_verdict(layer, reviewers)
|
|
309
319
|
if _wg_verdict and _wg_verdict.get("decision") in ("deny", "require_review"):
|
|
310
320
|
if _wg_verdict.get("mode") == "enforce":
|
|
@@ -328,9 +338,15 @@ class Principal:
|
|
|
328
338
|
reviewers = tuple(x.strip().lower() for x in raw.split(",") if x.strip())
|
|
329
339
|
verdict = _wg.decide_write(layer, reviewers=reviewers, mode=mode)
|
|
330
340
|
if mode == "warn" and verdict.get("decision") in ("deny", "require_review"):
|
|
341
|
+
# issue #708:既要 stderr(宿主愿意转发时实时可见),更要**进程内计数**
|
|
342
|
+
# ——后者经 `cg(op=info).write_gate` 可查,不依赖 DSH 是否转发子进程 stderr。
|
|
331
343
|
import sys as _sys
|
|
332
|
-
_sys.stderr.write("[writegate] warn:%s
|
|
344
|
+
_sys.stderr.write("[writegate] warn:%s(未阻断,仅记录;计数见 cg(op=info).write_gate)"
|
|
333
345
|
% verdict.get("reason"))
|
|
346
|
+
try:
|
|
347
|
+
_wg.warn_record(layer, verdict.get("tier"), verdict.get("reason"))
|
|
348
|
+
except Exception: # noqa: BLE001 诊断面不得冒泡进写入路径
|
|
349
|
+
pass
|
|
334
350
|
return verdict
|
|
335
351
|
|
|
336
352
|
# 生效条件:要求 self._require_live() 未抛异常、self.theory_ok 为 True、self.can_admin 为 True 时通过;否则抛 AccessDenied(消息用形参 op 标记操作)。
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# 功能名:配置登记「潜在静默回落」的可观测性守卫(F26-17 主体·前半)
|
|
3
|
+
# 生效条件:python -X utf8 -m md_cg.test_config_registry_silent_fallback;被测面=config_registry.entry_from_row 的两条回落路径(literal_eval 失败 / value_type 缺失)
|
|
4
|
+
# 子功能:①当前数据基线(两处均 0 命中,说明是防御性缺口而非活跃缺陷)②literal_eval 失败必须被 literal_failures() 记到 ③value_type 缺失必须被 missing_value_types() 记到 ④两者都**不得改变既有行为**(值原样保留、value_type 仍回落 str)
|
|
5
|
+
# 执行:直接构造 ROW_FIELDS 元组喂 entry_from_row,断言留痕 + 断言行为不变
|
|
6
|
+
# 验证方式:全部 PASS exit 0,否则 exit 1
|
|
7
|
+
# 不适用条件:不判 value_type 应当推断成什么(那是下一步「按值推断」,会动 427 条登记、需单独评估对 config_registry_guard 的影响)
|
|
8
|
+
"""F26-17 前半:把「潜在静默」变成可观测,且不改变任何既有行为。
|
|
9
|
+
|
|
10
|
+
病灶(`md_cg/config_registry.py::entry_from_row`):
|
|
11
|
+
· `val = ast.literal_eval(d["value_repr"])` 失败时**原样保留字符串**,无任何痕迹;
|
|
12
|
+
· `"value_type": d.get("value_type") or "str"` —— 缺失时静默回落成 str,
|
|
13
|
+
一个**数值型**登记会被当成字符串。
|
|
14
|
+
|
|
15
|
+
实测基线:当前 317 条登记里两处都是 **0 命中** ⇒ 属防御性缺口(陷阱存在但未触发),
|
|
16
|
+
故本轮只加可观测、不改行为;「按值推断 value_type」留作下一步。
|
|
17
|
+
"""
|
|
18
|
+
import os
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
22
|
+
sys.path.insert(0, ROOT)
|
|
23
|
+
|
|
24
|
+
from md_cg import config_registry as cr # noqa: E402
|
|
25
|
+
from md_cg.config_registry_bulk import ROW_FIELDS # noqa: E402
|
|
26
|
+
|
|
27
|
+
_PASS, _FAIL = [], []
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def ok(cond, msg, detail=""):
|
|
31
|
+
(_PASS if cond else _FAIL).append(msg)
|
|
32
|
+
print((" PASS " if cond else " FAIL ") + msg + ((" <- " + str(detail)) if detail and not cond else ""))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _row(**over):
|
|
36
|
+
base = {f: "" for f in ROW_FIELDS}
|
|
37
|
+
base.update({"name": "PROBE_X", "face": "TUNE", "layer": "L0", "kind": "const",
|
|
38
|
+
"tunable": False, "value_repr": "1", "value_type": "int",
|
|
39
|
+
"anchor_how": "const_assign", "anchor_file": "x.py",
|
|
40
|
+
"anchor_symbol": "X", "status": "uncalibrated", "evidence": "",
|
|
41
|
+
"since": "test", "notes": ""})
|
|
42
|
+
base.update(over)
|
|
43
|
+
return tuple(base[f] for f in ROW_FIELDS)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main():
|
|
47
|
+
print("== A 当前数据基线(防御性缺口:陷阱在、未触发)")
|
|
48
|
+
rows = cr.entries()
|
|
49
|
+
ok(len(rows) > 200, "A1 registry 条目数正常(>200)", len(rows))
|
|
50
|
+
ok(cr.literal_failures() == [],
|
|
51
|
+
"A2 当前无 literal_eval 失败项", cr.literal_failures()[:3])
|
|
52
|
+
ok(cr.missing_value_types() == [],
|
|
53
|
+
"A3 当前无 value_type 缺失项", cr.missing_value_types()[:3])
|
|
54
|
+
ok(all(r.get("value_type") for r in rows), "A4 无条目 value_type 为空")
|
|
55
|
+
|
|
56
|
+
print("== B literal_eval 失败必须留痕(判别力自证)")
|
|
57
|
+
before = len(cr.literal_failures())
|
|
58
|
+
e = cr.entry_from_row(_row(name="PROBE_BAD", value_repr="not-a-literal("))
|
|
59
|
+
after = cr.literal_failures()
|
|
60
|
+
ok(len(after) == before + 1, "B1 失败项被记到(+1)", (before, len(after)))
|
|
61
|
+
ok(any(n == "PROBE_BAD" for n, _v in after), "B2 记的是该条名字")
|
|
62
|
+
ok(e["value"] == "not-a-literal(", "B3 **行为不变**:值原样保留", e["value"])
|
|
63
|
+
ok(e["value_type"] == "int", "B4 **行为不变**:value_type 仍取行内声明", e["value_type"])
|
|
64
|
+
|
|
65
|
+
print("== C value_type 缺失必须留痕(判别力自证)")
|
|
66
|
+
before2 = len(cr.missing_value_types())
|
|
67
|
+
e2 = cr.entry_from_row(_row(name="PROBE_NOVT", value_type="", value_repr="42"))
|
|
68
|
+
after2 = cr.missing_value_types()
|
|
69
|
+
ok(len(after2) == before2 + 1, "C1 缺失项被记到(+1)", (before2, len(after2)))
|
|
70
|
+
ok(any(n == "PROBE_NOVT" for n, _v in after2), "C2 记的是该条名字")
|
|
71
|
+
ok(e2["value_type"] == "str", "C3 **行为不变**:仍回落 str(不擅自改成推断值)", e2["value_type"])
|
|
72
|
+
ok(e2["value"] == 42, "C4 值仍被正确解析", e2["value"])
|
|
73
|
+
|
|
74
|
+
print("== D 正常行不得被误记")
|
|
75
|
+
n_lit, n_vt = len(cr.literal_failures()), len(cr.missing_value_types())
|
|
76
|
+
e3 = cr.entry_from_row(_row(name="PROBE_OK", value_repr="[1, 2]", value_type="list"))
|
|
77
|
+
ok(len(cr.literal_failures()) == n_lit, "D1 正常行不进 literal 失败表")
|
|
78
|
+
ok(len(cr.missing_value_types()) == n_vt, "D2 正常行不进 value_type 缺失表")
|
|
79
|
+
ok(e3["value"] == [1, 2] and e3["value_type"] == "list", "D3 正常行字段正确")
|
|
80
|
+
|
|
81
|
+
print()
|
|
82
|
+
print("配置登记静默回落守卫:%d 通过 / %d 失败" % (len(_PASS), len(_FAIL)))
|
|
83
|
+
if _FAIL:
|
|
84
|
+
for f in _FAIL:
|
|
85
|
+
print(" -", f)
|
|
86
|
+
return 0 if not _FAIL else 1
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if __name__ == "__main__":
|
|
90
|
+
raise SystemExit(main())
|
|
@@ -445,7 +445,7 @@ _NEG_UNION = (' neg = list(fm.get("non_applicable_conditions") or
|
|
|
445
445
|
' neg.append(x)\n'
|
|
446
446
|
' fm["non_applicable_conditions"] = neg')
|
|
447
447
|
_TAGS_MAP = ' tags = list(item.get("tags") or [])'
|
|
448
|
-
_CS_MAP = '
|
|
448
|
+
_CS_MAP = ' condition_space=item.get("condition_space"),\n reviewed_by=reviewed_by, **extra)'
|
|
449
449
|
|
|
450
450
|
_MUTATIONS = (
|
|
451
451
|
# ① 契约指定:DEFER 出口**不再透传 meta**(退回 issue50-b 的只传 sensitivity)。
|
|
@@ -503,7 +503,7 @@ _MUTATIONS = (
|
|
|
503
503
|
# A3[bucket_zh](route_key 读 cs ⇒ 桶别名变)+ B1 + B2 + B3。
|
|
504
504
|
("accept 不再映射 condition_space(削弱既有映射)",
|
|
505
505
|
MdCGOS, "review_decide", _CS_MAP,
|
|
506
|
-
'
|
|
506
|
+
' condition_space=None,\n reviewed_by=reviewed_by, **extra)',
|
|
507
507
|
5),
|
|
508
508
|
# ⑧ 去掉幂等对账(既有职责)。预期:D2 = 1。
|
|
509
509
|
("去掉幂等对账 already_decided(既有职责)",
|
|
@@ -534,7 +534,7 @@ _ANCHORS_REQUIRED = (
|
|
|
534
534
|
(MdCGOS, "remember_gated", '**kw, defer_reason=_why)'),
|
|
535
535
|
(MdCGOS, "remember_gated", 'elif v == "DEFER":'),
|
|
536
536
|
(MdCGOS, "remember_gated", 'forgetting._prefeed_id(content)'),
|
|
537
|
-
(MdCGOS, "review_decide", 'condition_space=item.get("condition_space"), **extra)'),
|
|
537
|
+
(MdCGOS, "review_decide", ' condition_space=item.get("condition_space"),\n reviewed_by=reviewed_by, **extra)'),
|
|
538
538
|
(MdCGOS, "review_decide", 'if pid in self._closed_pids():'),
|
|
539
539
|
)
|
|
540
540
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# 功能名:分层写入闸的可观测性与审计链连续性守卫(issue #708)
|
|
3
|
+
# 生效条件:python -X utf8 -m md_cg.test_issue708_writegate_observable;被测面=writegate.warn_report、security warn 计数、_write_review_record 的 reviewers 透传
|
|
4
|
+
# 子功能:①warn 档写入成功且计数可读(不依赖子进程 stderr)②warn_report 形状与有界性 ③enforce 下审计节点**带** reviewers 能落、**不带**仍被拒(对照证明不是放水)④review_decide→_finish_decision→_record_decision→require_layer_write 全链透传锚点
|
|
5
|
+
# 执行:临时库跑三种角色/三档位,断言返回体与 warn_report;再静态断言调用链透传
|
|
6
|
+
# 验证方式:全部 PASS exit 0,否则 exit 1
|
|
7
|
+
# 不适用条件:不判 DSH 是否转发子进程 stderr(宿主面,本守卫只保证"不依赖它");不判 review_decide 的业务语义
|
|
8
|
+
"""issue #708:warn 档不可观测 + enforce 下裁决审计节点被同一闸挡住。
|
|
9
|
+
|
|
10
|
+
病灶(报告人 Starrain08 实测):
|
|
11
|
+
· warn 档只写子进程 stderr,DSH 不转发进 desktop-next.log ⇒ 用户「完全看不到」,等于没有观察期;
|
|
12
|
+
· enforce 档下 `_write_review_record` 写 structural,而 structural 属 2 档(需 reflect+verify),
|
|
13
|
+
该调用**不传 reviewers** ⇒ 审计节点被同一个闸挡住(jsonl 还在,可复核的 md 节点没了)。
|
|
14
|
+
"""
|
|
15
|
+
import os
|
|
16
|
+
import shutil
|
|
17
|
+
import sys
|
|
18
|
+
import tempfile
|
|
19
|
+
|
|
20
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
21
|
+
sys.path.insert(0, ROOT)
|
|
22
|
+
|
|
23
|
+
_PASS, _FAIL = [], []
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def ok(cond, msg, detail=""):
|
|
27
|
+
(_PASS if cond else _FAIL).append(msg)
|
|
28
|
+
print((" PASS " if cond else " FAIL ") + msg + ((" <- " + str(detail)) if detail and not cond else ""))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _clean_env(T):
|
|
32
|
+
for k in list(os.environ):
|
|
33
|
+
if k.startswith("MDCG_"):
|
|
34
|
+
del os.environ[k]
|
|
35
|
+
os.environ.update(MDCG_ROOT=os.path.join(T, "brain"),
|
|
36
|
+
MDCG_STATE_ROOT=os.path.join(T, "stroot"),
|
|
37
|
+
MDCG_AUX_ROOT=os.path.join(T, "auxroot"),
|
|
38
|
+
MDCG_DATA_ROOT=os.path.join(T, "dataroot"),
|
|
39
|
+
MDCG_EXPORT_ROOT=T, MDCG_SUSTAIN="0", MDCG_SLEEP="0")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main():
|
|
43
|
+
T = tempfile.mkdtemp(prefix="i708g_")
|
|
44
|
+
try:
|
|
45
|
+
_clean_env(T)
|
|
46
|
+
from md_cg import writegate as wg
|
|
47
|
+
from md_cg.mdcos import MdCGSecure
|
|
48
|
+
from md_cg.security import Principal
|
|
49
|
+
from md_cg.tokens import role_spec
|
|
50
|
+
|
|
51
|
+
def P(role, clr="internal"):
|
|
52
|
+
s = role_spec(role)
|
|
53
|
+
return Principal(role=role, clearance=clr, can_write=s["can_write"],
|
|
54
|
+
can_admin=s["can_admin"], layers_allow=s["layers_allow"],
|
|
55
|
+
ops_allow=s["ops_allow"])
|
|
56
|
+
|
|
57
|
+
print("== A warn 档:写入成功 + 计数可读(#708 病灶①)")
|
|
58
|
+
os.environ["MDCG_WRITE_GATE"] = "warn"
|
|
59
|
+
os.environ["MDCG_REVIEW_CHANNELS"] = "subagent"
|
|
60
|
+
os.environ.pop("MDCG_REVIEWERS", None)
|
|
61
|
+
base = wg.warn_report()
|
|
62
|
+
cg = MdCGSecure(os.path.join(T, "brain"), principal=P("record"), autoflush=1)
|
|
63
|
+
nid = cg.add("probe_k1", "probe content one", layer="knowledge")
|
|
64
|
+
cg.close()
|
|
65
|
+
ok(bool(nid), "A1 warn 档 write knowledge 成功(不阻断)", nid)
|
|
66
|
+
rep = wg.warn_report()
|
|
67
|
+
ok(rep["total"] >= base["total"] + 1,
|
|
68
|
+
"A2 warn 计数 +1(修前不可见:只写 stderr)", (base["total"], rep["total"]))
|
|
69
|
+
ok(any(k.startswith("knowledge@L1") for k in rep["by_layer"]),
|
|
70
|
+
"A3 计数按层分桶(knowledge@L1)", list(rep["by_layer"])[:4])
|
|
71
|
+
ok(bool(rep["recent"]) and "reason" in rep["recent"][-1],
|
|
72
|
+
"A4 recent 摘要含 reason(无内容、无节点 id)", rep["recent"][-1] if rep["recent"] else None)
|
|
73
|
+
ok(rep["mode"] == "warn", "A5 mode 透出", rep["mode"])
|
|
74
|
+
|
|
75
|
+
print("== B warn_report 形状与有界性")
|
|
76
|
+
ok(set(rep) >= {"mode", "total", "by_layer", "recent", "hint"}, "B1 键齐全", sorted(rep))
|
|
77
|
+
ok(len(rep["recent"]) <= 5, "B2 recent 最多 5 条", len(rep["recent"]))
|
|
78
|
+
ok(wg.WARN_RECENT_MAX == 20, "B3 有界常量在位", wg.WARN_RECENT_MAX)
|
|
79
|
+
|
|
80
|
+
print("== C enforce:审计节点带 reviewers 能落(#708 病灶②)")
|
|
81
|
+
os.environ["MDCG_WRITE_GATE"] = "enforce"
|
|
82
|
+
sg = role_spec("designer")
|
|
83
|
+
p = Principal(role="designer", clearance="secret", can_write=sg["can_write"],
|
|
84
|
+
can_admin=sg["can_admin"], layers_allow=sg["layers_allow"],
|
|
85
|
+
ops_allow=sg["ops_allow"])
|
|
86
|
+
cg2 = MdCGSecure(os.path.join(T, "brain"), principal=p, autoflush=1)
|
|
87
|
+
rec = {"pid": "p1", "round": 1, "decision": "accept", "status": "accepted",
|
|
88
|
+
"redteam_verdict": "absent", "issues": [], "verify_hash": "vh",
|
|
89
|
+
"t": 1793000000, "actor": "tester", "target_id": "n1",
|
|
90
|
+
"record_node_id": "audit_p1_r1", "record_hash": "a" * 64}
|
|
91
|
+
try:
|
|
92
|
+
out = cg2._write_review_record(rec, reviewers=("reflect", "verify"))
|
|
93
|
+
ok(bool(out), "C1 带 reviewers ⇒ 审计节点落盘成功", out)
|
|
94
|
+
except Exception as e: # noqa: BLE001
|
|
95
|
+
ok(False, "C1 带 reviewers ⇒ 审计节点落盘成功", "%s: %s" % (type(e).__name__, e))
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
cg2._write_review_record(dict(rec, record_node_id="audit_p2_r1"), reviewers=None)
|
|
99
|
+
ok(False, "C2 不带 reviewers 仍应被拒(对照:不是放水)", "竟然成功了")
|
|
100
|
+
except Exception as e: # noqa: BLE001
|
|
101
|
+
ok("分层复核闸" in str(e) or "AccessDenied" in type(e).__name__,
|
|
102
|
+
"C2 不带 reviewers 仍被拒(对照)", "%s: %s" % (type(e).__name__, str(e)[:60]))
|
|
103
|
+
cg2.close()
|
|
104
|
+
|
|
105
|
+
print("== D 全链透传锚点(静态)")
|
|
106
|
+
src = open(os.path.join(ROOT, "md_cg", "mdcos.py"), encoding="utf-8").read()
|
|
107
|
+
ok("def _write_review_record(self, rec, reviewers=None)" in src,
|
|
108
|
+
"D1 _write_review_record 接 reviewers")
|
|
109
|
+
ok("reviewed_by=reviewers" in src, "D2 add(...) 透传 reviewed_by")
|
|
110
|
+
# 2026-10-28 改:`reviewed_by` 必须 **pop** 掉(它是闸的输入参数,不是记忆元数据),
|
|
111
|
+
# 否则会经 super().add(**kw) 落进 frontmatter(test_i50c 的 B1 曾因此报白名单外差异)。
|
|
112
|
+
ok('kw.pop("reviewed_by", None)' in src and "reviewers=_reviewers" in src,
|
|
113
|
+
"D3 MdCGSecure.add 用 pop 取出 reviewed_by 交给 require_layer_write(不下传 fm)")
|
|
114
|
+
ok("def _record_decision(self, pid, item, decision, status, reason, round_no," in src,
|
|
115
|
+
"D4 _record_decision 存在")
|
|
116
|
+
ok("_write_review_record(rec, reviewers=reviewers)" in src,
|
|
117
|
+
"D5 _record_decision → _write_review_record 透传")
|
|
118
|
+
ok(src.count("reviewers=reviewed_by)") == 2,
|
|
119
|
+
"D6 两处 _finish_decision 调用点都传 reviewed_by", src.count("reviewers=reviewed_by)"))
|
|
120
|
+
|
|
121
|
+
print("== E 透传后仍需齐备(不得变成万能放行)")
|
|
122
|
+
cg3 = MdCGSecure(os.path.join(T, "brain"), principal=p, autoflush=1)
|
|
123
|
+
try:
|
|
124
|
+
cg3._write_review_record(dict(rec, record_node_id="audit_p3_r1"), reviewers=("reflect",))
|
|
125
|
+
ok(False, "E1 只给 reflect(缺 verify)应被拒(2 档需两者)", "竟然成功了")
|
|
126
|
+
except Exception as e: # noqa: BLE001
|
|
127
|
+
ok("AccessDenied" in type(e).__name__, "E1 只给 reflect 仍被拒", str(e)[:60])
|
|
128
|
+
cg3.close()
|
|
129
|
+
finally:
|
|
130
|
+
shutil.rmtree(T, ignore_errors=True)
|
|
131
|
+
|
|
132
|
+
print()
|
|
133
|
+
print("issue #708 守卫:%d 通过 / %d 失败" % (len(_PASS), len(_FAIL)))
|
|
134
|
+
if _FAIL:
|
|
135
|
+
for f in _FAIL:
|
|
136
|
+
print(" -", f)
|
|
137
|
+
return 0 if not _FAIL else 1
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if __name__ == "__main__":
|
|
141
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# 功能名:复核模型在 enforce 档下的端到端可用性守卫(issue #709 及其连带发现)
|
|
3
|
+
# 生效条件:python -X utf8 -m md_cg.test_issue709_review_chain_enforce;被测面=propose / review_decide(accept) / 审计节点 在 MDCG_WRITE_GATE=enforce 下的完整链
|
|
4
|
+
# 子功能:①propose 不被写层闸拦(否则死锁:要写 knowledge 需 reflect→要 reflect 需裁决→要裁决需提案→提案又要 reflect)②review_decide(accept, reviewed_by) 落业务节点成功 ③同一次裁决的审计节点也落盘且 record_error 为空 ④skip_gate 只给 propose(不得外溢到落盘路径)⑤层白名单/dual_check 不被削弱
|
|
5
|
+
# 执行:临时库 + enforce 档,按「propose → accept」真实顺序跑一遍,断言返回体关键字段
|
|
6
|
+
# 验证方式:全部 PASS exit 0,否则 exit 1
|
|
7
|
+
# 不适用条件:不判 warn/off 档行为(那两条由 test_issue708 / test_writegate_tiers 覆盖);不判 MCP 层序列化
|
|
8
|
+
"""issue #709:enforce 下「批了但审计节点写不进去」,以及修它时连带发现的两个更靠前的缺口。
|
|
9
|
+
|
|
10
|
+
病灶链(都在同一条 reviewed_by 通路上):
|
|
11
|
+
① `propose` 不落盘却按目标层要求复核单元 ⇒ enforce 下**连提案都提不进去**(死锁);
|
|
12
|
+
② `review_decide` 的 accept 落业务节点(`add`)不传 reviewed_by ⇒ **裁决过了、落盘被拦**;
|
|
13
|
+
③ `_write_review_record` 写 structural 审计节点不传 reviewers ⇒ **审计链断裂**(#709 原文)。
|
|
14
|
+
"""
|
|
15
|
+
import os
|
|
16
|
+
import shutil
|
|
17
|
+
import sys
|
|
18
|
+
import tempfile
|
|
19
|
+
|
|
20
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
21
|
+
sys.path.insert(0, ROOT)
|
|
22
|
+
|
|
23
|
+
_PASS, _FAIL = [], []
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def ok(cond, msg, detail=""):
|
|
27
|
+
(_PASS if cond else _FAIL).append(msg)
|
|
28
|
+
print((" PASS " if cond else " FAIL ") + msg + ((" <- " + str(detail)) if detail and not cond else ""))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _fresh(T):
|
|
32
|
+
for k in list(os.environ):
|
|
33
|
+
if k.startswith("MDCG_"):
|
|
34
|
+
del os.environ[k]
|
|
35
|
+
os.environ.update(MDCG_ROOT=os.path.join(T, "brain"),
|
|
36
|
+
MDCG_STATE_ROOT=os.path.join(T, "stroot"),
|
|
37
|
+
MDCG_AUX_ROOT=os.path.join(T, "auxroot"),
|
|
38
|
+
MDCG_DATA_ROOT=os.path.join(T, "dataroot"),
|
|
39
|
+
MDCG_EXPORT_ROOT=T, MDCG_SUSTAIN="0", MDCG_SLEEP="0",
|
|
40
|
+
MDCG_WRITE_GATE="enforce", MDCG_REVIEW_CHANNELS="subagent")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main():
|
|
44
|
+
T = tempfile.mkdtemp(prefix="i709g_")
|
|
45
|
+
try:
|
|
46
|
+
_fresh(T)
|
|
47
|
+
from md_cg.mdcos import MdCGSecure
|
|
48
|
+
from md_cg.security import Principal
|
|
49
|
+
from md_cg.tokens import role_spec
|
|
50
|
+
|
|
51
|
+
sg = role_spec("designer")
|
|
52
|
+
p = Principal(role="designer", clearance="secret", can_write=sg["can_write"],
|
|
53
|
+
can_admin=sg["can_admin"], layers_allow=sg["layers_allow"],
|
|
54
|
+
ops_allow=sg["ops_allow"])
|
|
55
|
+
cg = MdCGSecure(os.path.join(T, "brain"), principal=p, autoflush=1)
|
|
56
|
+
|
|
57
|
+
print("== A propose 在 enforce 下可用(死锁已解,病灶①)")
|
|
58
|
+
try:
|
|
59
|
+
pid = cg.propose("prop_a", "probe content A", layer="knowledge")
|
|
60
|
+
ok(bool(pid), "A1 propose knowledge 成功(修前:被写层闸拦 ⇒ 死锁)", str(pid))
|
|
61
|
+
except Exception as e: # noqa: BLE001
|
|
62
|
+
ok(False, "A1 propose knowledge 成功", "%s: %s" % (type(e).__name__, e))
|
|
63
|
+
pid = None
|
|
64
|
+
ok(callable(getattr(cg, "propose", None)), "A2 propose 方法仍在(未被移除)")
|
|
65
|
+
|
|
66
|
+
print("== B accept 落业务节点(病灶②)")
|
|
67
|
+
if pid:
|
|
68
|
+
try:
|
|
69
|
+
res = cg.review_decide(str(pid), "accept",
|
|
70
|
+
reviewed_by=["reflect", "verify"], decided_by="tester")
|
|
71
|
+
ok(bool(res.get("ok")), "B1 accept 返回 ok", res.get("error") or res.get("detail"))
|
|
72
|
+
ok(bool(res.get("node_id")), "B2 业务节点已落盘(node_id 有值)", res.get("node_id"))
|
|
73
|
+
ok(not res.get("record_error"),
|
|
74
|
+
"B3 **record_error 为空**(#709 原病灶:审计节点不再被同一闸拒)",
|
|
75
|
+
res.get("record_error"))
|
|
76
|
+
ok(bool(res.get("record_node_id")),
|
|
77
|
+
"B4 审计节点 id 有值(审计链未断)", res.get("record_node_id"))
|
|
78
|
+
except Exception as e: # noqa: BLE001
|
|
79
|
+
ok(False, "B1 accept 返回 ok", "%s: %s" % (type(e).__name__, e))
|
|
80
|
+
|
|
81
|
+
print("== C skip_gate 不得外溢(只有 propose 用)")
|
|
82
|
+
src = open(os.path.join(ROOT, "md_cg", "mdcos.py"), encoding="utf-8").read()
|
|
83
|
+
n_skip = src.count("skip_gate=True")
|
|
84
|
+
ok(n_skip == 1, "C1 全仓只有一处 skip_gate=True(propose)", n_skip)
|
|
85
|
+
sec = open(os.path.join(ROOT, "md_cg", "security.py"), encoding="utf-8").read()
|
|
86
|
+
ok("skip_gate: bool = False" in sec, "C2 require_layer_write 的 skip_gate 缺省 False")
|
|
87
|
+
ok("if skip_gate:" in sec and "return None" in sec, "C3 skip_gate 只跳过闸、不跳过前面两步")
|
|
88
|
+
i_skip = sec.find("if skip_gate:")
|
|
89
|
+
i_allow = sec.find("if not self.allows_layer(layer)")
|
|
90
|
+
ok(0 < i_allow < i_skip,
|
|
91
|
+
"C4 层白名单检查在 skip_gate **之前**(未被跳过)", (i_allow, i_skip))
|
|
92
|
+
|
|
93
|
+
print("== D 层白名单仍生效(propose 不得越权)")
|
|
94
|
+
sg2 = role_spec("verify")
|
|
95
|
+
p2 = Principal(role="verify", clearance="internal", can_write=sg2["can_write"],
|
|
96
|
+
can_admin=sg2["can_admin"], layers_allow=sg2["layers_allow"],
|
|
97
|
+
ops_allow=sg2["ops_allow"])
|
|
98
|
+
cg2 = MdCGSecure(os.path.join(T, "brain"), principal=p2, autoflush=1)
|
|
99
|
+
try:
|
|
100
|
+
cg2.propose("prop_b", "probe content B", layer="knowledge")
|
|
101
|
+
ok(False, "D1 verify 角色 propose knowledge 应被层白名单拒", "竟然成功了")
|
|
102
|
+
except Exception as e: # noqa: BLE001
|
|
103
|
+
ok("无权写入" in str(e), "D1 verify 角色 propose knowledge 被层白名单拒", str(e)[:60])
|
|
104
|
+
cg2.close()
|
|
105
|
+
|
|
106
|
+
print("== E 落盘路径仍受闸(skip_gate 没有削弱写入)")
|
|
107
|
+
try:
|
|
108
|
+
cg.add("probe_direct", "probe content C", layer="knowledge")
|
|
109
|
+
ok(False, "E1 无 reviewed_by 直写 knowledge 应被拒", "竟然成功了")
|
|
110
|
+
except Exception as e: # noqa: BLE001
|
|
111
|
+
ok("分层复核闸" in str(e), "E1 无 reviewed_by 直写 knowledge 仍被拒(闸未被削弱)", str(e)[:60])
|
|
112
|
+
# knowledge 是 1 档(只需 reflect)⇒ 给了 reflect **本就该通过**,这是档位正确的证据。
|
|
113
|
+
try:
|
|
114
|
+
nid2 = cg.add("probe_direct2", "probe content D", layer="knowledge",
|
|
115
|
+
reviewed_by=["reflect"])
|
|
116
|
+
ok(bool(nid2), "E2 只给 reflect 直写 knowledge **通过**(1 档语义正确)", nid2)
|
|
117
|
+
except Exception as e: # noqa: BLE001
|
|
118
|
+
ok(False, "E2 只给 reflect 直写 knowledge 应通过(1 档)", "%s: %s" % (type(e).__name__, str(e)[:60]))
|
|
119
|
+
cg.close()
|
|
120
|
+
finally:
|
|
121
|
+
shutil.rmtree(T, ignore_errors=True)
|
|
122
|
+
|
|
123
|
+
print()
|
|
124
|
+
print("issue #709 守卫:%d 通过 / %d 失败" % (len(_PASS), len(_FAIL)))
|
|
125
|
+
if _FAIL:
|
|
126
|
+
for f in _FAIL:
|
|
127
|
+
print(" -", f)
|
|
128
|
+
return 0 if not _FAIL else 1
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
if __name__ == "__main__":
|
|
132
|
+
raise SystemExit(main())
|
package/md_cg/writegate.py
CHANGED
|
@@ -118,6 +118,43 @@ def missing_reviewers(tier, reviewers):
|
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
# 生效条件:layer/reviewers 传入,channels 与 mode 缺省从环境读取;产出 decision=allow|require_review|deny 及 tier/mode/missing/reason;mode=off 时恒 allow。
|
|
121
|
+
|
|
122
|
+
#: issue #708(2026-10-28):warn 档的**可观测性**。
|
|
123
|
+
#:
|
|
124
|
+
#: 病灶(报告人 Starrain08 实测):`warn` 档只往子进程 stderr 写一行,而 DSH 不把子进程
|
|
125
|
+
#: stderr 转发进 `desktop-next.log` ⇒ 用户「完全看不到任何东西」,等于没有观察期,
|
|
126
|
+
#: 只能盲选要不要切 enforce。
|
|
127
|
+
#:
|
|
128
|
+
#: 修法(报告人建议 2):**进程内计数 + 最近条目摘要**,经 `cg(op=info).write_gate` 可查。
|
|
129
|
+
#: 不依赖 stderr 转发,也不写盘(诊断面,零副作用)。
|
|
130
|
+
#: 有界:最多保留 WARN_RECENT_MAX 条,防长驻进程无限增长。
|
|
131
|
+
WARN_RECENT_MAX = 20
|
|
132
|
+
_warn_counts = {} # {(layer, mode): 次数}
|
|
133
|
+
_warn_recent = [] # [(layer, tier, reason)] 最近若干条,无内容、无节点 id
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def warn_record(layer, tier, reason):
|
|
137
|
+
"""记录一次「本该复核却按 warn 放行」——供 `cg(op=info)` 读出。"""
|
|
138
|
+
key = (layer or "", tier)
|
|
139
|
+
_warn_counts[key] = _warn_counts.get(key, 0) + 1
|
|
140
|
+
_warn_recent.append((layer or "", tier, (reason or "")[:160]))
|
|
141
|
+
if len(_warn_recent) > WARN_RECENT_MAX:
|
|
142
|
+
del _warn_recent[:-WARN_RECENT_MAX]
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def warn_report():
|
|
146
|
+
"""生效条件:恒返回可序列化 dict——`{mode, total, by_layer, recent}`。"""
|
|
147
|
+
total = sum(_warn_counts.values())
|
|
148
|
+
by_layer = {"%s@L%s" % k: v for k, v in sorted(_warn_counts.items())}
|
|
149
|
+
return {"mode": gate_mode(),
|
|
150
|
+
"total": total,
|
|
151
|
+
"by_layer": by_layer,
|
|
152
|
+
"recent": [{"layer": a, "tier": b, "reason": c}
|
|
153
|
+
for a, b, c in _warn_recent[-5:]],
|
|
154
|
+
"hint": ("warn 档只记录不阻断;本计数为进程内累计,重启归零。"
|
|
155
|
+
if total else "尚无 warn 记录(要么没触发,要么闸为 off)。")}
|
|
156
|
+
|
|
157
|
+
|
|
121
158
|
def decide_write(layer, reviewers=None, channels=None, mode=None, environ=None):
|
|
122
159
|
"""写入前判定:allow | require_review | deny。
|
|
123
160
|
|
package/package.json
CHANGED
package/src/hooks.ts
CHANGED
|
@@ -972,6 +972,11 @@ export function installMemoryHooks(ctx: Context, mdcg: MdcgClient | null, opts:
|
|
|
972
972
|
// 落盘审计(issue #56):source.kind 分布——先于两级判据记录**完整**输入分布
|
|
973
973
|
// (含被滤与放行),「宿主到底给这条消息标了什么 kind」是排障第一问。
|
|
974
974
|
audit.observeKind(kindOf(event.data.source))
|
|
975
|
+
// issue #695 诊断面:记录 source 的**键名集合**(不含任何值)。
|
|
976
|
+
// kind 只说「以什么形式提交」,键名集合才能回答「source 带哪些字段」——
|
|
977
|
+
// 外部桥接经 sessions.prompt() 注入的控制提示同样走 kind="user",
|
|
978
|
+
// 靠这一维才有可核验的盘面读数(绝不记内容)。
|
|
979
|
+
audit.observeSourceShape(event.data.source)
|
|
975
980
|
// H1 **消息级**判据:委派/中继消息(`form: 'relay'` 语义=「另一个 agent
|
|
976
981
|
// 发给本 agent 的消息」)不写。先于 kind 判据,理由见 isRelayedMessage 注释。
|
|
977
982
|
if (isRelayedMessage(event.data.source)) {
|
package/src/lib/console_web.mjs
CHANGED
|
@@ -28,14 +28,21 @@ async function readBody(req) {
|
|
|
28
28
|
try { return JSON.parse(Buffer.concat(chunks).toString('utf8')); }
|
|
29
29
|
catch { throw Object.assign(new Error('请求必须是有效 JSON'), { status: 400 }); }
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
// issue #699(2026-10-28):第 4 参改为**取值函数**。原实现由挂载点 `ctx.get('connection')` 取值,
|
|
32
|
+
// 而 cordis 的 `Context.get(name, strict=true)` 在服务 fiber 未就绪时返回 undefined ⇒
|
|
33
|
+
// 空值被闭包固化,此后每次请求都命中 503「宿主鉴权不可用」,宿主就绪也不会自愈。
|
|
34
|
+
// 现在改为**每次请求实时取**:服务晚到也能自愈。
|
|
35
|
+
// 兼容:传的不是函数(旧调用方式/直接给实例)时按常量包裹,行为与旧版一致。
|
|
36
|
+
export function createConsoleHandler(mdcg, config, assets, getConnection) {
|
|
37
|
+
const connectionOf = typeof getConnection === 'function' ? getConnection : () => getConnection
|
|
32
38
|
const csrf = randomBytes(32).toString('hex');
|
|
33
39
|
let catalog = null;
|
|
34
40
|
const tools = async () => catalog ?? (catalog = await mdcg.bridge.listTools());
|
|
35
41
|
return async (req, res) => {
|
|
36
42
|
try {
|
|
37
43
|
const path = new URL(req.url, 'http://localhost').pathname;
|
|
38
|
-
|
|
44
|
+
const connection = connectionOf()
|
|
45
|
+
if (!connection || typeof connection.admit !== 'function') return reply(res, 503, { error: '宿主鉴权服务尚未就绪,请稍后重试' });
|
|
39
46
|
const admission = connection.admit(req);
|
|
40
47
|
if ('rejection' in admission) return reply(res, admission.rejection, { error: admission.rejection === 401 ? '未登录,请返回 DSH 登录' : '请求来源不可信' });
|
|
41
48
|
if (req.method === 'GET' && assets[path]) {
|
|
@@ -88,7 +95,8 @@ export function installConsoleWeb(ctx, config, disposers, mdcg) {
|
|
|
88
95
|
'/plugins/lingshu/style.css': [asset('style.css'), 'text/css; charset=utf-8'],
|
|
89
96
|
'/plugins/lingshu/entry.js': [asset('entry.js'), 'application/javascript; charset=utf-8'],
|
|
90
97
|
};
|
|
91
|
-
|
|
98
|
+
// issue #699:传**取值函数**(每次请求实时取),不再把挂载瞬间的值闭包固化。
|
|
99
|
+
const handler = createConsoleHandler(mdcg, config, assets, () => ctx.get('connection'));
|
|
92
100
|
for (const path of ['/lingshu', '/lingshu/', '/plugins/lingshu']) disposers.push(web.register({ kind: path === '/plugins/lingshu' ? 'prefix' : 'exact', path, handler }));
|
|
93
101
|
disposers.push(web.tapIndex(html => html.includes('data-lingshu-entry') ? html : html.replace('</body>', '<script data-lingshu-entry src="/plugins/lingshu/entry.js"></script></body>')));
|
|
94
102
|
ctx.logger.info('dsh-memory: 极简灵枢控制台已挂载 /lingshu(复用唯一大脑桥)');
|
package/src/lib/hook_audit.ts
CHANGED
|
@@ -67,6 +67,12 @@ export interface HookAuditState {
|
|
|
67
67
|
}
|
|
68
68
|
/** 进入消息级处理的 `source.kind` 分布(缺字段/空串/非字符串记 "undefined")。 */
|
|
69
69
|
kinds: Record<string, number>
|
|
70
|
+
/** `source` 的**键名集合**分布(issue #695:只记键名,绝不记值)。
|
|
71
|
+
* 为什么需要:`kind` 只说明「以什么形式提交」,不说明「谁提交的」。
|
|
72
|
+
* 外部桥接经 `sessions.prompt()` 注入的控制提示同样以 kind="user" 通过,
|
|
73
|
+
* 只看 kind 无法区分;而**键名集合**(如 `kind` / `form+kind` / `kind+origin`)
|
|
74
|
+
* 能直接回答「这条事件的 source 到底带哪些字段」,是排查来源归因缺口的第一读数。 */
|
|
75
|
+
source_shapes: Record<string, number>
|
|
70
76
|
/** 最近 ≤MAX_LAST 条摘要。 */
|
|
71
77
|
last: HookAuditEntry[]
|
|
72
78
|
updated_at: string
|
|
@@ -105,6 +111,15 @@ export function kindOf(source: unknown): string {
|
|
|
105
111
|
return typeof k === 'string' && k.length > 0 ? k : 'undefined'
|
|
106
112
|
}
|
|
107
113
|
|
|
114
|
+
/** `source` 的键名集合(排序后 join '+'):空对象记 "empty",非对象记 "not-object"。
|
|
115
|
+
* 只取 `Object.keys`——**绝不读值**,因此不含任何内容/凭据。 */
|
|
116
|
+
export function sourceShapeOf(source: unknown): string {
|
|
117
|
+
if (source === null || source === undefined) return 'undefined'
|
|
118
|
+
if (typeof source !== 'object') return 'not-object'
|
|
119
|
+
const keys = Object.keys(source as Record<string, unknown>).sort()
|
|
120
|
+
return keys.length ? keys.join('+') : 'empty'
|
|
121
|
+
}
|
|
122
|
+
|
|
108
123
|
function nowIso(): string {
|
|
109
124
|
return new Date().toISOString()
|
|
110
125
|
}
|
|
@@ -117,6 +132,7 @@ function emptyState(): HookAuditState {
|
|
|
117
132
|
skipped: { sanitized: 0, not_ready: 0, failed: 0 },
|
|
118
133
|
},
|
|
119
134
|
kinds: {},
|
|
135
|
+
source_shapes: {},
|
|
120
136
|
last: [],
|
|
121
137
|
updated_at: nowIso(),
|
|
122
138
|
}
|
|
@@ -144,7 +160,7 @@ function sumCounts(bucket: unknown, keys: readonly string[]): number | null {
|
|
|
144
160
|
function mergeState(raw: unknown): HookAuditState {
|
|
145
161
|
const s = emptyState()
|
|
146
162
|
if (!raw || typeof raw !== 'object') return s
|
|
147
|
-
const r = raw as { counts?: unknown; kinds?: unknown; last?: unknown }
|
|
163
|
+
const r = raw as { counts?: unknown; kinds?: unknown; source_shapes?: unknown; last?: unknown }
|
|
148
164
|
if (r.counts && typeof r.counts === 'object') {
|
|
149
165
|
const c = r.counts as { filtered?: unknown; written?: unknown; skipped?: unknown }
|
|
150
166
|
const buckets: Array<[Record<string, number>, string[], unknown]> = [
|
|
@@ -162,6 +178,11 @@ function mergeState(raw: unknown): HookAuditState {
|
|
|
162
178
|
if (typeof v === 'number' && Number.isFinite(v) && v > 0) s.kinds[k] = Math.floor(v)
|
|
163
179
|
}
|
|
164
180
|
}
|
|
181
|
+
if (r.source_shapes && typeof r.source_shapes === 'object') {
|
|
182
|
+
for (const [k, v] of Object.entries(r.source_shapes as Record<string, unknown>)) {
|
|
183
|
+
if (typeof v === 'number' && Number.isFinite(v) && v > 0) s.source_shapes[k] = Math.floor(v)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
165
186
|
if (Array.isArray(r.last)) {
|
|
166
187
|
for (const e of r.last) {
|
|
167
188
|
if (!e || typeof e !== 'object') continue
|
|
@@ -230,6 +251,18 @@ export class HookAuditRecorder {
|
|
|
230
251
|
})
|
|
231
252
|
}
|
|
232
253
|
|
|
254
|
+
/** `source` 的键名集合分布(issue #695):只记**键名**,不记任何值。
|
|
255
|
+
*
|
|
256
|
+
* 与 `observeKind` 的分工:kind 回答「以什么形式提交」,本方法回答「source 带哪些字段」。
|
|
257
|
+
* 两者都不参与写入判定(本模块是诊断面,红线不动)。
|
|
258
|
+
*/
|
|
259
|
+
observeSourceShape(source: unknown): void {
|
|
260
|
+
const shape = sourceShapeOf(source)
|
|
261
|
+
this.#mutate((s) => {
|
|
262
|
+
s.source_shapes[shape] = (s.source_shapes[shape] ?? 0) + 1
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
|
|
233
266
|
/** 成功**发起**的写入(按 role;发起后失败另记 skipped.failed)。 */
|
|
234
267
|
written(role: HookWriteRole): void {
|
|
235
268
|
this.#mutate((s) => {
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
"path": "src/lib/console_web.mjs",
|
|
30
|
-
"sha256": "
|
|
30
|
+
"sha256": "9C8F8450571729688033033F35345B18E9EEB68B871E3A4C53A9B619F28AA61E"
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
"path": "lib/lib/console_web.mjs",
|
|
34
|
-
"sha256": "
|
|
34
|
+
"sha256": "9C8F8450571729688033033F35345B18E9EEB68B871E3A4C53A9B619F28AA61E"
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
"path": "lib/client.js",
|