@furongjun1999/dsh-memory 0.9.12 → 0.9.14

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 (35) hide show
  1. package/README.md +21 -4
  2. package/codebuddy/CODEBUDDY.md +8 -3
  3. package/codebuddy/README.md +92 -92
  4. package/docs/discipline/templates/zcode-user.md.tmpl +52 -52
  5. package/docs//345/267/245/344/275/234/347/272/252/345/276/213_/350/256/244/347/237/245/345/233/276/346/235/241/347/233/256_v1.1.json +488 -461
  6. package/docs//350/247/204/350/214/203/AI/347/274/226/347/250/213/351/200/232/347/224/250/350/247/204/350/214/203_/347/201/265/346/236/242/351/200/202/351/205/215.md +45 -45
  7. package/dsh/README.md +82 -82
  8. package/lib/hooks.d.ts +7 -1
  9. package/lib/hooks.js +62 -31
  10. package/lib/index.js +4 -1
  11. package/md_cg/config_registry_bulk.py +2 -0
  12. package/md_cg/config_validate.py +463 -461
  13. package/md_cg/conformance_core.py +28 -0
  14. package/md_cg/consistency.py +9 -2
  15. package/md_cg/mcp_server.py +91 -0
  16. package/md_cg/mdcg.py +162 -7
  17. package/md_cg/mdcos.py +53 -6
  18. package/md_cg/nodefile.py +39 -1
  19. package/md_cg/op_table.py +1 -0
  20. package/md_cg/relations.py +91 -0
  21. package/md_cg/scrub.py +20 -3
  22. package/md_cg/test_exact_text_cache.py +12 -4
  23. package/md_cg/test_issue218_postcondition_value_blind.py +4 -2
  24. package/md_cg/test_issue644_637_636.py +84 -0
  25. package/md_cg/test_issue650_658_f26.py +98 -0
  26. package/md_cg/test_issue659_r26_batch2.py +74 -0
  27. package/md_cg/test_issue665_scrub_process_records.py +59 -0
  28. package/md_cg/test_issue669_ccg_empty_colon.py +69 -0
  29. package/md_cg/test_issue672_validity_scope.py +47 -0
  30. package/md_cg/version_anchor.py +160 -0
  31. package/package.json +2 -2
  32. package/src/hooks.ts +64 -31
  33. package/src/index.ts +4 -1
  34. package/zcode/AGENTS.md +8 -3
  35. package/zcode/README.md +41 -41
@@ -0,0 +1,160 @@
1
+ # -*- coding: utf-8 -*-
2
+ """版本锚(version anchor)——I18 的代码落点。
3
+
4
+ 为什么需要(issue #6 提案,2026-10-18 采纳):
5
+ I17 规定「任何投影不得自称权威」,那么每个投影必须能回溯到
6
+ 「信息 + 条件空间 + 证据链」三元组。**版本锚就是那个回溯入口**——
7
+ 缺版本锚的对外材料,读者无法判断它对应哪一版理论、哪一版架构,
8
+ 也就无法回溯。这不是排版问题,是可回溯性的前提。
9
+
10
+ 三条纪律:
11
+ 1. **三元齐全**:理论版本、架构版本、本投影版本,缺一不可记为不完整。
12
+ 2. **机器可读**:格式固定,便于校验(conformance / CI 可红)。
13
+ 3. **不猜**:解析不到就是缺,不用「看起来像版本号」去**猜**——猜出来的锚比没有更糟。
14
+
15
+ 格式(Markdown 引用块内一行,字段用全角竖线分隔):
16
+
17
+ > **版本锚**:理论=智能论 3.4 | 架构=灵枢记忆系统统一架构 v1.2 | 投影=变更说明 v1
18
+
19
+ 也接受 YAML 式三行:
20
+
21
+ version_anchor:
22
+ theory: 智能论 3.4
23
+ architecture: 灵枢记忆系统统一架构 v1.2
24
+ projection: 变更说明 v1
25
+ """
26
+
27
+ import re
28
+
29
+ __all__ = ["FIELDS", "parse_anchor", "check_anchor", "ANCHOR_LINE_RE"]
30
+
31
+ #: 三元字段(键名 → 中文别名,都接受)
32
+ FIELDS = ("theory", "architecture", "projection")
33
+ _ALIASES = {
34
+ "theory": ("theory", "理论", "理论版本"),
35
+ "architecture": ("architecture", "架构", "架构版本"),
36
+ "projection": ("projection", "投影", "本投影", "投影版本"),
37
+ }
38
+
39
+ #: 单行形态: > **版本锚**:理论=… | 架构=… | 投影=…
40
+ ANCHOR_LINE_RE = re.compile(r"版本锚\*\*\s*[::]\s*(.+)$", re.M)
41
+ _KV_RE = re.compile(r"([^==||]+?)\s*[==]\s*([^||]+)")
42
+
43
+
44
+ def _canon(name):
45
+ n = str(name or "").strip()
46
+ for key, alts in _ALIASES.items():
47
+ if n in alts:
48
+ return key
49
+ return None
50
+
51
+
52
+ def parse_anchor(text):
53
+ """从文本中解析版本锚。
54
+
55
+ 返回 {"found": bool, "anchor": {field: value}, "missing": [field...]}。
56
+ 两种形态都支持;解析不到即 missing,**不做推测性填充**。
57
+ """
58
+ text = str(text or "")
59
+ anchor = {}
60
+
61
+ m = ANCHOR_LINE_RE.search(text)
62
+ if m:
63
+ for k, v in _KV_RE.findall(m.group(1)):
64
+ key = _canon(k)
65
+ if key and key not in anchor:
66
+ val = v.strip().strip("*_ ")
67
+ if val:
68
+ anchor[key] = val
69
+
70
+ # YAML 式三行形态(仅在上面的单行形态没解析全时补充)
71
+ if len(anchor) < len(FIELDS):
72
+ for key, alts in _ALIASES.items():
73
+ if key in anchor:
74
+ continue
75
+ for alt in alts:
76
+ ym = re.search(r"^\s*" + re.escape(alt) + r"\s*[::]\s*(.+?)\s*$",
77
+ text, re.M)
78
+ if ym and ym.group(1).strip():
79
+ anchor[key] = ym.group(1).strip().strip("\"'*_ ")
80
+ break
81
+
82
+ missing = [f for f in FIELDS if not anchor.get(f)]
83
+ return {"found": bool(anchor), "anchor": anchor, "missing": missing}
84
+
85
+
86
+ #: 历史材料标记:早于 I18 施行、且作者已难追溯的对外材料。
87
+ #: 它们**不补锚**(推定版本等于造锚),但在检查结果里显式区分于「应补未补」。
88
+ LEGACY_MARK = "legacy_no_anchor"
89
+
90
+
91
+ def check_anchor(text):
92
+ """I18 判定:三元齐全才算通过。返回 (ok, detail)。
93
+
94
+ detail["legacy"] 为真表示该材料自带历史标记——不算通过,但也不算待修。
95
+ 这两件事必须分开:**「明示未标注」与「忘了标注」责任不同**。
96
+ """
97
+ rep = parse_anchor(text)
98
+ ok = rep["found"] and not rep["missing"]
99
+ legacy = LEGACY_MARK in str(text or "")
100
+ return ok, {"anchor": rep["anchor"], "missing": rep["missing"],
101
+ "found": rep["found"], "legacy": legacy}
102
+
103
+
104
+ def scan_dir(directory, suffix=".md"):
105
+ """扫描目录下的对外材料,分类为 ok/legacy/todo。
106
+
107
+ 「todo」是应补未补的,需要人决定;「legacy」是明示历史材料,不催。
108
+ """
109
+ import os
110
+ rows = {"ok": [], "legacy": [], "todo": []}
111
+ d = str(directory)
112
+ if not os.path.isdir(d):
113
+ return {"error": "目录不存在:%s" % d, **rows}
114
+ for name in sorted(os.listdir(d)):
115
+ if not name.endswith(suffix):
116
+ continue
117
+ path = os.path.join(d, name)
118
+ if not os.path.isfile(path):
119
+ continue
120
+ try:
121
+ with open(path, "r", encoding="utf-8", errors="replace") as fh:
122
+ text = fh.read()
123
+ except OSError as exc:
124
+ rows["todo"].append({"file": name, "why": "read_error: %s" % exc})
125
+ continue
126
+ ok, detail = check_anchor(text)
127
+ if ok:
128
+ rows["ok"].append(name)
129
+ elif detail.get("legacy"):
130
+ rows["legacy"].append(name)
131
+ else:
132
+ rows["todo"].append({"file": name, "missing": detail["missing"]})
133
+ return rows
134
+
135
+
136
+ def main(argv=None):
137
+ import sys
138
+ argv = list(sys.argv[1:] if argv is None else argv)
139
+ try:
140
+ sys.stdout.reconfigure(encoding="utf-8")
141
+ except Exception:
142
+ pass
143
+ if "--check" not in argv:
144
+ print("用法:python -m md_cg.version_anchor --check <目录> [--json]")
145
+ return 2
146
+ d = argv[argv.index("--check") + 1]
147
+ rows = scan_dir(d)
148
+ if "--json" in argv:
149
+ import json as _j
150
+ print(_j.dumps(rows, ensure_ascii=False, indent=1, sort_keys=True))
151
+ else:
152
+ print("ok=%d legacy=%d todo=%d" % (len(rows["ok"]), len(rows["legacy"]),
153
+ len(rows["todo"])))
154
+ for item in rows["todo"]:
155
+ print(" TODO ", item)
156
+ return 0 if not rows["todo"] else 1
157
+
158
+
159
+ if __name__ == "__main__":
160
+ raise SystemExit(main())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@furongjun1999/dsh-memory",
3
- "version": "0.9.12",
3
+ "version": "0.9.14",
4
4
  "description": "灵枢(Lingshu·líng shū)DeepSeek Harness 插件:完整大脑——长期记忆/知识飞轮/自我认知/递归反思接入 DSH,对话自动沉淀进 md_cg 认知图(md 文档)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -91,7 +91,7 @@
91
91
  "build": "node -e \"require('node:fs').rmSync('lib',{recursive:true,force:true})\" && tsc -p tsconfig.json",
92
92
  "test": "npm run build && node --import tsx --test \"test/*.test.ts\"",
93
93
  "prepare": "node -e \"const fs=require('fs');const tsc='node_modules/typescript/bin/tsc';if(fs.existsSync(tsc)){fs.rmSync('lib',{recursive:true,force:true});require('child_process').execFileSync(process.execPath,[tsc,'-p','tsconfig.json'],{stdio:'inherit'})}else if(fs.existsSync('lib/index.js')){console.log('[prepare] 跳过构建:typescript 未安装(NODE_ENV=production 或 --omit=dev 会省略 devDependencies)——需要构建请用 npm install --include=dev')}else{console.error('[prepare] 本安装会得到一个不可用的包(issue #161):包入口 main 指向 lib/index.js,但 lib/ 被 .gitignore 忽略、git 归档里没有它,此处 typescript 又未安装(NODE_ENV=production 或 --omit=dev 会省略 devDependencies)⇒ prepare 无法构建,lib/index.js 不存在。修法:用 npm install --include=dev 安装(带上 devDependencies,让 prepare 能构建),或改用已带构建产物的发布包。');process.exitCode=1}\"",
94
- "gate": "python scripts/check_unreachable.py && python scripts/check_publish_artifact.py && python scripts/check_publish_smoke.py && python scripts/cogmap_sync.py check && python scripts/link_check.py && python scripts/check_line_anchors.py && python scripts/workspace_index.py --check && python scripts/discipline_nodes.py --init --write --cg-root .tmp/discipline-cg && python scripts/verify_discipline.py --allow-missing --cg-root .tmp/discipline-cg && python scripts/gate_rust_crate_test.py && python scripts/gate_rust_parity.py && python scripts/check_local_paths.py && python scripts/body_e2e_smoke.py",
94
+ "gate": "python scripts/check_unreachable.py && python scripts/check_publish_artifact.py && python scripts/check_publish_smoke.py && python scripts/cogmap_sync.py check && python scripts/link_check.py && python scripts/check_line_anchors.py && python scripts/workspace_index.py --check && python scripts/discipline_nodes.py --init --write --cg-root .tmp/discipline-cg && python scripts/verify_discipline.py --allow-missing --cg-root .tmp/discipline-cg && python scripts/gate_output.py && python scripts/gate_rust_crate_test.py && python scripts/gate_rust_parity.py && python scripts/check_local_paths.py && python scripts/body_e2e_smoke.py",
95
95
  "prepublishOnly": "npm run build && npm test && npm run gate"
96
96
  },
97
97
  "repository": {
package/src/hooks.ts CHANGED
@@ -92,6 +92,12 @@ export interface MemoryHooksOptions {
92
92
  autoRecall: boolean
93
93
  /** 自动召回条数(默认 4)。 */
94
94
  autoRecallLimit: number
95
+ /** 逢十轮提醒(纪律第 16 条;issue #645)。缺省 10 = 每 10 个真实用户回合提醒一次;
96
+ * 数字 = 自定义间隔(1~100);false = 关闭。
97
+ *
98
+ * 计轮单位是「用户消息条数」,不是 assemble 次数——实测一次模型请求约 10 次 assemble,
99
+ * 按 assemble 计数会把「每 10 轮」退化成「每一步」。 */
100
+ turnReminder?: boolean | number
95
101
  /** 身份锚点独立注入块(issue #635,默认 false = 保持既有行为)。
96
102
  *
97
103
  * 背景:永久层(self/anchor)被 RECALL_SKIP_LAYERS 跳过,用户写完「我是谁」永远
@@ -764,16 +770,41 @@ export function installMemoryHooks(ctx: Context, mdcg: MdcgClient | null, opts:
764
770
  // 因此本实现把「要不要补」交还给宿主:压缩归档后宿主会把 retained 置空并重新投影快照
765
771
  // (RuntimeContextProjection 的 retained === null 分支),本块自然跟着回来——
766
772
  // 不需要插件自己数步数做自愈。
767
- /** 进程内轮次计数(session → 已 assemble 轮数)。见 shouldRemindTurn。 */
768
- /** 进程内「本十轮段提醒文本」(session → 文本):段内每轮重推同一文本,避免快照增删。 */
769
- const remindText = new Map<string, string>()
770
- const turnSeq = new Map<string, number>()
771
- if (opts.autoRecall) {
773
+ /** 真实轮次计数(session → 用户消息条数)。issue #645:计轮单位必须是「用户回合」,
774
+ * 不是 assemble 次数——实测一步约 10 次 assemble,按 assemble 计数会把「每 10 轮」
775
+ * 退化成「每一步」,提醒于是常驻上下文、agent 反复空转归档。 */
776
+ const userTurns = new Map<string, number>()
777
+ /** 待推送提醒(session → 文本):用户回合计数命中时写入,assemble 时只消费一次;
778
+ * 不做 sticky 重推(那是提醒常驻的直接原因)。 */
779
+ const pendingReminder = new Map<string, string>()
780
+ /** 提醒间隔:false → 0(关闭);数字 → clamp 1..100;未设 → 10。 */
781
+ const reminderInterval = (() => {
782
+ const cfg = opts.turnReminder
783
+ if (cfg === false) return 0
784
+ const n = typeof cfg === 'number' ? cfg : 10
785
+ if (!Number.isFinite(n)) return 10
786
+ return Math.max(1, Math.min(100, Math.floor(n)))
787
+ })()
788
+ {
789
+ // 本 handler **恒定注册**(#657):提醒是独立配置(memory.turnReminder),
790
+ // 关掉自动召回不该让它只写不读;召回部分在内部按 opts.autoRecall 门控。
772
791
  const recallLimit = Math.max(1, Math.min(10, opts.autoRecallLimit || 4))
773
792
  ctx.on('system-prompt/assemble', async (assembly, _ctx, next) => {
774
793
  try {
775
794
  // 异步取最近记忆节点(失败静默——不阻塞模型请求)
776
- if (graph.isReady()) {
795
+ // 会话标识:门控内外都要用(提醒消费 + 自动召回),故先解析。
796
+ const hostCtx = (_ctx as unknown) as { agent?: { session?: unknown } } | undefined
797
+ const sid = sessionIdOf(hostCtx?.agent?.session)
798
+ || (observedSession ? currentSession() : '')
799
+ // 逢十轮提醒的消费面(#657):不受 autoRecall 门控。
800
+ if (sid) {
801
+ const pending = pendingReminder.get(sid)
802
+ if (pending) {
803
+ pendingReminder.delete(sid)
804
+ assembly.contexts.push({ name: 'lingshu:turn-reminder', text: pending })
805
+ }
806
+ }
807
+ if (opts.autoRecall && graph.isReady()) {
777
808
  // 会话隔离(P45):自动召回只注入**本会话**的记忆,防多会话串台;
778
809
  // 取不到会话标识则退回旧行为(不加过滤),不做半吊子猜测。
779
810
  // ⚠️ 取值必须**每步稳定**:本块按 v0.4.8 契约每步都 push,内容一旦与上
@@ -782,30 +813,18 @@ export function installMemoryHooks(ctx: Context, mdcg: MdcgClient | null, opts:
782
813
  // 退回「最近一次 session/event 的会话」。
783
814
  // 想读**所有**会话做了什么:别走自动召回(它会串台),显式调
784
815
  // `stg(op=timeline, session="*")`,返回项带 session 归属。
785
- const hostCtx = (_ctx as unknown) as { agent?: { session?: unknown } } | undefined
786
- // 回落 = **本实例观测门 × 模块单点值**(裁定项 dwfq-7b3a555e-1,见上方
787
- // observedSession 注释):本实例尚未观测 → 回落 ''(保持「新实例 =
788
- // 干净状态」,与 test/session-attribution.test.ts ② 的「未观测 → 不加
789
- // 过滤」相容);已观测 → 取 lib/session_state.ts 的进程级单点值。
790
- // 真机单实例下两者逐位等价(差异窗口不可达)。
791
- const sid = sessionIdOf(hostCtx?.agent?.session)
792
- || (observedSession ? currentSession() : '')
793
- // 逢十轮提醒(纪律第 16 条):assemble 每轮触发一次 ⇒ 以此计轮。
794
- // 状态只在本进程内(重启归零):宁可多提醒一次,不留假状态。
795
- const turnKey = sid || '__no_sid__'
796
- const turnNo = (turnSeq.get(turnKey) ?? 0) + 1
797
- turnSeq.set(turnKey, turnNo)
798
- // 粘性提醒(2026-10-21):只在触发轮 push、下一轮就消失会让宿主多追两份快照
799
- // (10→11 增删各一次)。故把「本轮所属十轮段的提醒文本」按会话记住,
800
- // 段内每轮**原样重推**(文本不变 ⇒ 渲染快照不追加),跨段才换一次文本。
801
- if (shouldRemindTurn(turnNo)) {
802
- remindText.set(turnKey, escapePromptBraces(formatTurnReminder(turnNo)))
803
- }
804
- const sticky = remindText.get(turnKey)
805
- if (sticky) {
806
- assembly.contexts.push({ name: 'lingshu:turn-reminder', text: sticky })
816
+ // sid 已在门控外解析(提醒消费与召回共用同一份,避免两次口径漂移)。
817
+ // 逢十轮提醒(纪律第 16 条;issue #645 修正):计数挪到 session/event 的真实
818
+ // 用户回合上,这里只消费一次待推文本。旧实现把 assemble 当轮次 + 段内永久重推
819
+ // ⇒ 提醒几乎常驻、agent 反复空转归档;sid 缺失时还回落共用键 __no_sid__,
820
+ // 并行会话互相污染频率。现改为:无 sid 不提醒;提醒只在本回合第一次 assemble 出现。
821
+ if (sid) {
822
+ const pending = pendingReminder.get(sid)
823
+ if (pending) {
824
+ pendingReminder.delete(sid)
825
+ assembly.contexts.push({ name: 'lingshu:turn-reminder', text: pending })
826
+ }
807
827
  }
808
- // issue #635:身份锚点独立块(默认关)。开启时多取几条,按层分流:
809
828
  // 非永久层 → 既有「最近记忆」块;self/anchor → 独立「身份锚点」块(独立预算)。
810
829
  const identityOn = opts.autoRecallIdentity === true
811
830
  const timelinePayload = await graph.timeline(
@@ -929,6 +948,17 @@ export function installMemoryHooks(ctx: Context, mdcg: MdcgClient | null, opts:
929
948
  observedSession = true
930
949
  }
931
950
  const sessionTag = sid ? { session: sid } : { session: UNASSIGNED_SESSION }
951
+ // 逢十轮提醒的**计轮点**(#645/#658):真实用户回合 = 用户消息条数。
952
+ // 位置在 opts.userMessage 之外——那个开关是「消息不自动进知识面」的正当决策,
953
+ // 与「提醒还该不该跑」是两件事;旧实现把计轮塞在它里面,关知识面会连带静默杀死提醒。
954
+ if (event.type === 'user/message' && event.data.source?.kind === 'user'
955
+ && !isRelayedMessage(event.data.source) && sid && reminderInterval > 0) {
956
+ const n = (userTurns.get(sid) ?? 0) + 1
957
+ userTurns.set(sid, n)
958
+ if (shouldRemindTurn(n, reminderInterval)) {
959
+ pendingReminder.set(sid, escapePromptBraces(formatTurnReminder(n)))
960
+ }
961
+ }
932
962
  if (event.type === 'user/message' && opts.userMessage) {
933
963
  // 落盘审计(issue #56):source.kind 分布——先于两级判据记录**完整**输入分布
934
964
  // (含被滤与放行),「宿主到底给这条消息标了什么 kind」是排障第一问。
@@ -1028,8 +1058,11 @@ export function installMemoryHooks(ctx: Context, mdcg: MdcgClient | null, opts:
1028
1058
  * 不等收尾」。zcode 端由 `scripts/zcode_window_hook.py` 注入提醒;**DSH 端此前
1029
1059
  * 完全没有实现**——纪律在产物里、机制不在,代理只能靠自觉(实测:整场长会话
1030
1060
  * 一次归档都没做)。本函数是该缺口的判定单点。 */
1031
- export function shouldRemindTurn(n: number): boolean {
1032
- return Number.isFinite(n) && n >= 10 && n % 10 === 0
1061
+ export function shouldRemindTurn(n: number, interval = 10): boolean {
1062
+ if (!Number.isFinite(n) || !Number.isFinite(interval)) return false
1063
+ const step = Math.floor(interval)
1064
+ if (step <= 0) return false
1065
+ return n >= step && n % step === 0
1033
1066
  }
1034
1067
 
1035
1068
  /** 提醒文本(不含注入边界转义——转义在 push 站点做,与其它块同规)。 */
package/src/index.ts CHANGED
@@ -176,6 +176,9 @@ export const Config: z<Config> = z.object({
176
176
  autoRecallLimit: z.number().default(4),
177
177
  /** issue #635:self/anchor 层单列「身份锚点」块(默认 false = 维持既有行为)。 */
178
178
  autoRecallIdentity: z.boolean().default(false),
179
+ /** 逢十轮提醒(纪律第 16 条;issue #645):缺省 10 = 每 10 个真实用户回合;
180
+ * false = 关闭;数字 = 自定义间隔(1~100)。 */
181
+ turnReminder: z.union([z.boolean(), z.number()]).default(10),
179
182
  desensitize: z.boolean().default(true),
180
183
  /** **短期会话窗口**(滑动窗口,2026-10-06)——「短期保留近 N 条对话记录」
181
184
  * 的机制实现(长期记忆仍走灵枢的显式调用)。
@@ -199,7 +202,7 @@ export const Config: z<Config> = z.object({
199
202
  })
200
203
  .default({ enabled: true, turns: 10 }),
201
204
  })
202
- .default({ userMessage: true, assistantMessage: false, toolResult: false, importance: 0.6, autoRecall: true, autoRecallLimit: 4, autoRecallIdentity: false, desensitize: true, contextWindow: { enabled: true, turns: 10 } }),
205
+ .default({ userMessage: true, assistantMessage: false, toolResult: false, importance: 0.6, autoRecall: true, autoRecallLimit: 4, autoRecallIdentity: false, turnReminder: 10, desensitize: true, contextWindow: { enabled: true, turns: 10 } }),
203
206
  toolCallTimeoutMs: z.number().default(60_000),
204
207
  maxRetryDelayMs: z.number().default(30_000),
205
208
  failOnStartupError: z.boolean().default(false),
package/zcode/AGENTS.md CHANGED
@@ -1,8 +1,8 @@
1
- # 工作纪律(工作纪律_认知图条目_v1.1)· 18 条
1
+ # 工作纪律(工作纪律_认知图条目_v1.1)· 19 条
2
2
 
3
3
  > 本文件由 `scripts/render_discipline.py` 从真源
4
4
  > `docs/工作纪律_认知图条目_v1.1.json` 渲染生成,**请勿手改**;改真源后重跑渲染。
5
- > 真源指纹(SHA256 前16位):9486668b0dadac39
5
+ > 真源指纹(SHA256 前16位):aea28906043ba9a2
6
6
 
7
7
  ## 概述
8
8
 
@@ -204,7 +204,7 @@
204
204
 
205
205
  **版本**:v1.1 | **状态**:待校准(未对外发布)
206
206
 
207
- ### 附录:本仓 18 条纪律(语义 / 触发 / 动作 / 声明出口)
207
+ ### 附录:本仓 19 条纪律(语义 / 触发 / 动作 / 声明出口)
208
208
 
209
209
  1. **1.理论先行**
210
210
  - 触发:重要项目|长期任务
@@ -278,6 +278,10 @@
278
278
  - 触发:查找工作区文件|需要了解工作区结构|跨目录检索定位|长会话续接/上下文压缩后查找工作区文件
279
279
  - 动作:定位工作区文件→先读 WORKSPACE_INDEX.md(仓根)→有则按表中职责/关键入口直接定位→无则先 python scripts/workspace_index.py --write 生成再读→守卫报陈化先重生成→不以重复全盘浏览代替; 新增顶层目录/根级文件须在脚本 DIR_ROLES/ROOT_FILES 登记后重生成; 上下文压缩/长会话续接后, 先 cg route『工作区索引』重建纪律视野(压缩会丢弃未留下执行痕迹的纪律, 只剩被声明过的条目——须主动召回); 压缩/续接后三步=route『工作区索引』→输出声明→回取本会话近10轮窗口重建上下文(cg(op=recent)/session_recall/会话 md 镜像)
280
280
  - 声明:按工作纪律第18条: 工作区索引优先——查工作区文件先读 WORKSPACE_INDEX.md(仓根, 管线生成); 无则先跑 scripts/workspace_index.py --write 生成再读, 不以重复全盘浏览代替。 压缩续接后并回取本会话窗口(最近10轮)重建上下文。
281
+ 19. **19.输出单元细则(echo三问/D_out/版本锚)**
282
+ - 触发:对外交付|对外材料/公开文档|回答外部提问|发版说明|对外数据集产出
283
+ - 动作:对外交付前→①按三问写 echo 页(<=200 字, 第二问必须指认判据 id/测试名/读数) ②补版本锚三元(理论/架构/本投影) ③跑 python scripts/gate_output.py 判绿 ④附当期 D_out 读数(首次允许很差, 但必须留基线)→任一不满足不得对外; 改口径先改真源再重渲染, 不得手改产物; 材料与实现版本不一致时以版本锚为准, 先修锚再发
284
+ - 声明:按工作纪律第19条: 输出单元细则——对外交付先写 echo 三问页(<=200字, 第二问须指认判据/断言id/读数)、带版本锚三元、跑 gate_output 并留当期 D_out 读数; 缺一不对外, 不做说服率/好感度测量。
281
285
 
282
286
  ## 声明出口(`response.direct` 原文 · 未输出即未执行)
283
287
 
@@ -301,6 +305,7 @@
301
305
  | 16 | 按工作纪律第16条: 任务收尾归档——每次任务执行完只提炼核心修改(内容/原因/位置/验证结论)并按 CCG 六要素(功能名/生效条件/子功能/执行/验证方式/不适用条件)成文存入灵枢记忆(text 类六要素缺失会被写入闸门当场拒绝并返回缺失清单——补齐后重写即可, 不必等读回确认才发现), 写入后发起一次读取查询确认写入成功且可检索, 禁写中间过程/试错/调试等无效信息, 与第2条形成「查记忆→执行→写记忆→读回确认」闭环。 |
302
306
  | 17 | 按工作纪律第17条: 任务派发统一走蜂巢——任何执行性任务经蜂巢 spawn/submit 执行并留痕(spec/status/result), agent本体只做编排; 宿主自带subagent/team不是等价通道(zcode端的工作流工具为等效蜂巢工具——使用者2026-10-04裁定; 蜂巢功能完全完善之前, zcode端可优先使用zcode工作流处理), 兜底须声明。L1只读判定(产物落点=不改仓库/外部状态)可直跑, 须输出「L1 直跑:<命令> — 风险/频次/可逆性」留痕。 |
303
307
  | 18 | 按工作纪律第18条: 工作区索引优先——查工作区文件先读 WORKSPACE_INDEX.md(仓根, 管线生成); 无则先跑 scripts/workspace_index.py --write 生成再读, 不以重复全盘浏览代替。 压缩续接后并回取本会话窗口(最近10轮)重建上下文。 |
308
+ | 19 | 按工作纪律第19条: 输出单元细则——对外交付先写 echo 三问页(<=200字, 第二问须指认判据/断言id/读数)、带版本锚三元、跑 gate_output 并留当期 D_out 读数; 缺一不对外, 不做说服率/好感度测量。 |
304
309
 
305
310
  ## 记忆接口速查(`cg` / `stg`)
306
311
 
package/zcode/README.md CHANGED
@@ -1,41 +1,41 @@
1
- # ZCode 端 · 灵枢接入配置
2
-
3
- 本目录 = **ZCode harness 专属配置**。ZCode 与 CodeBuddy 同构:在**会话起始读取项目根的 `AGENTS.md`**
4
- 全文注入,因此本端产物同样采用 `full` 变体。
5
-
6
- ## 目录内容
7
-
8
- | 文件 | 作用 | 性质 |
9
- |---|---|---|
10
- | `AGENTS.md` | 18 条工作纪律全文(会话起始注入) | **渲染产物**,勿手改 |
11
- | `README.md` | 本文件(接入说明) | 手写 |
12
-
13
- ## 接入
14
-
15
- 把 `zcode/AGENTS.md` 复制到**你项目的根目录**,新建会话即生效。
16
-
17
- ZCode 侧的记忆访问复用同一套 MCP 大脑,配置方式与 CodeBuddy 一致
18
- (见 [`../codebuddy/mcp.json`](../codebuddy/mcp.json) 与 [`../codebuddy/README.md`](../codebuddy/README.md)),
19
- 只需把 `MDCG_ACTOR` 改为 `zcode`。
20
-
21
- 该模板同源含第二条 MCP server `hive`(蜂巢:多智能体并发 + 任务上下文管理),一并合并即可;
22
- ZCode 与 CodeBuddy 指向同一仓库时**共享同一并发池**。语义与边界见
23
- [`../hive/README.md`](../hive/README.md) 的「各 harness 注册」。
24
-
25
- ## 与 CodeBuddy 并存
26
-
27
- 两者互不干扰——CodeBuddy 读根目录 `CODEBUDDY.md`,ZCode 读根目录 `AGENTS.md`;
28
- 若项目同时使用两端,各自放入对应文件即可(内容同源,均为真源渲染产物)。
29
-
30
- ## 记忆策略
31
-
32
- 同 CodeBuddy 端:**只记重要内容(核心修改:内容/原因/位置/验证结论)+ 对话记录**,
33
- 其余一律经写入闸门过滤。详见 [`../codebuddy/README.md`](../codebuddy/README.md) 的「记忆策略」一节。
34
-
35
- ## 维护(面向灵枢维护者)
36
-
37
- - `AGENTS.md` 由 `scripts/render_discipline.py` 从**唯一真源** `docs/工作纪律_认知图条目_v1.1.json`
38
- 渲染生成,矩阵见 `docs/discipline/harnesses.yaml`(`zcode` 槽位)。
39
- - 改纪律 → 改真源 → `python scripts/render_discipline.py --target zcode --write`
40
- → `python scripts/verify_discipline.py --target zcode` 通过 → 提交。
41
- - **手改本目录的 `AGENTS.md` 会被 `verify_discipline.py` 判为漂移**。
1
+ # ZCode 端 · 灵枢接入配置
2
+
3
+ 本目录 = **ZCode harness 专属配置**。ZCode 与 CodeBuddy 同构:在**会话起始读取项目根的 `AGENTS.md`**
4
+ 全文注入,因此本端产物同样采用 `full` 变体。
5
+
6
+ ## 目录内容
7
+
8
+ | 文件 | 作用 | 性质 |
9
+ |---|---|---|
10
+ | `AGENTS.md` | 19 条工作纪律全文(会话起始注入) | **渲染产物**,勿手改 |
11
+ | `README.md` | 本文件(接入说明) | 手写 |
12
+
13
+ ## 接入
14
+
15
+ 把 `zcode/AGENTS.md` 复制到**你项目的根目录**,新建会话即生效。
16
+
17
+ ZCode 侧的记忆访问复用同一套 MCP 大脑,配置方式与 CodeBuddy 一致
18
+ (见 [`../codebuddy/mcp.json`](../codebuddy/mcp.json) 与 [`../codebuddy/README.md`](../codebuddy/README.md)),
19
+ 只需把 `MDCG_ACTOR` 改为 `zcode`。
20
+
21
+ 该模板同源含第二条 MCP server `hive`(蜂巢:多智能体并发 + 任务上下文管理),一并合并即可;
22
+ ZCode 与 CodeBuddy 指向同一仓库时**共享同一并发池**。语义与边界见
23
+ [`../hive/README.md`](../hive/README.md) 的「各 harness 注册」。
24
+
25
+ ## 与 CodeBuddy 并存
26
+
27
+ 两者互不干扰——CodeBuddy 读根目录 `CODEBUDDY.md`,ZCode 读根目录 `AGENTS.md`;
28
+ 若项目同时使用两端,各自放入对应文件即可(内容同源,均为真源渲染产物)。
29
+
30
+ ## 记忆策略
31
+
32
+ 同 CodeBuddy 端:**只记重要内容(核心修改:内容/原因/位置/验证结论)+ 对话记录**,
33
+ 其余一律经写入闸门过滤。详见 [`../codebuddy/README.md`](../codebuddy/README.md) 的「记忆策略」一节。
34
+
35
+ ## 维护(面向灵枢维护者)
36
+
37
+ - `AGENTS.md` 由 `scripts/render_discipline.py` 从**唯一真源** `docs/工作纪律_认知图条目_v1.1.json`
38
+ 渲染生成,矩阵见 `docs/discipline/harnesses.yaml`(`zcode` 槽位)。
39
+ - 改纪律 → 改真源 → `python scripts/render_discipline.py --target zcode --write`
40
+ → `python scripts/verify_discipline.py --target zcode` 通过 → 提交。
41
+ - **手改本目录的 `AGENTS.md` 会被 `verify_discipline.py` 判为漂移**。