focus-guard 3.5.3 → 3.5.4

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 (84) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +1 -1
  3. package/assets/NOTICE.md +1 -1
  4. package/docs/ARCH-MAP.md +298 -83
  5. package/docs/BENCH.md +10 -4
  6. package/docs/RELEASE-POLICY.md +25 -12
  7. package/docs/RULES.md +34 -16
  8. package/docs/THREAT-MODEL.md +3 -3
  9. package/docs/WRITING-STYLE.md +40 -2
  10. package/package.json +1 -1
  11. package/skills/focus-rules/SKILL.md +9 -9
  12. package/skills/focus-thinking/SKILL.md +3 -3
  13. package/src/adapters/dsh/eligibility-gate.mjs +32 -12
  14. package/src/{dsh → adapters/dsh}/toolName.mjs +6 -0
  15. package/src/core/auditActions.mjs +214 -0
  16. package/src/core/checkEligibility.mjs +3 -1
  17. package/src/core/constants.mjs +8 -4
  18. package/src/core/env.mjs +21 -4
  19. package/src/core/profileLoader.mjs +96 -3
  20. package/src/core/scratch.mjs +288 -0
  21. package/src/core/state.mjs +3 -3
  22. package/src/dsh/audit.mjs +24 -163
  23. package/src/dsh/cost-ledger.mjs +174 -0
  24. package/src/dsh/guard/authz.mjs +1 -1
  25. package/src/dsh/guard/evidence.mjs +19 -0
  26. package/src/dsh/guard/tooling.mjs +15 -4
  27. package/src/dsh/{value-gate.mjs → guard/value-gate.mjs} +6 -0
  28. package/src/dsh/index.js +1 -1
  29. package/src/dsh/pipeline.mjs +6 -3
  30. package/src/dsh/postProgress.mjs +81 -40
  31. package/src/dsh/preGuard.mjs +1 -1
  32. package/src/dsh/seams/pre-step.mjs +74 -23
  33. package/src/dsh/seams/prompt-rules.mjs +91 -5
  34. package/src/dsh/{guard → seams}/runtime.mjs +12 -6
  35. package/src/dsh/seams/session-start.mjs +14 -0
  36. package/src/dsh/tools.mjs +1 -1
  37. package/src/memory/index.mjs +3 -1
  38. package/src/profiles/deepseek-flash.mjs +10 -8
  39. package/src/profiles/deepseek-pro.mjs +9 -8
  40. package/src/profiles/default.mjs +14 -8
  41. package/src/profiles/glm.mjs +9 -8
  42. package/src/profiles/gpt-astra.mjs +11 -9
  43. package/tools/audit-chain.mjs +29 -4
  44. package/tools/docs-drift.mjs +7 -29
  45. package/tools/docs-lint.mjs +54 -11
  46. package/tools/docs-refs.mjs +343 -0
  47. package/tools/handoff.mjs +1 -1
  48. package/tools/index-stale.mjs +124 -0
  49. package/tools/knowledge.mjs +53 -4
  50. package/tools/lib/book-style.mjs +42 -1
  51. package/tools/lib/case-tool.mjs +1 -1
  52. package/tools/lib/cli.mjs +35 -0
  53. package/tools/lib/docs-ack.mjs +4 -2
  54. package/tools/lib/docs-core.mjs +46 -23
  55. package/tools/lib/docs-scope.mjs +46 -0
  56. package/tools/lib/docs-status.mjs +8 -3
  57. package/tools/lib/docs-typography.mjs +91 -0
  58. package/tools/lib/docs-version.mjs +8 -5
  59. package/tools/lib/dup-block.mjs +117 -0
  60. package/tools/lib/index-io.mjs +4 -4
  61. package/tools/lib/index-registry.mjs +101 -0
  62. package/tools/lib/modules-doc.mjs +8 -1
  63. package/tools/lib/modules-list.mjs +22 -8
  64. package/tools/lib/modules.mjs +57 -9
  65. package/tools/lib/mutation-ops.mjs +63 -0
  66. package/tools/lib/parse-block.mjs +58 -0
  67. package/tools/lib/ratchet.mjs +22 -8
  68. package/tools/lib/release-faces.mjs +144 -0
  69. package/tools/lib/repo-copy.mjs +34 -0
  70. package/tools/lib/survey-report.mjs +57 -0
  71. package/tools/lib/where.mjs +139 -0
  72. package/tools/library-build.mjs +15 -3
  73. package/tools/lint.mjs +19 -13
  74. package/tools/log-audit.mjs +76 -0
  75. package/tools/memory-distill.mjs +14 -1
  76. package/tools/modules-audit.mjs +11 -9
  77. package/tools/mutate.mjs +120 -74
  78. package/tools/prefix-drift.mjs +1 -1
  79. package/tools/registry-check.mjs +16 -10
  80. package/tools/release.mjs +54 -106
  81. package/tools/smells.mjs +97 -139
  82. package/src/core/staleCleanup.mjs +0 -224
  83. package/src/dsh/workspace.mjs +0 -5
  84. package/tools/library-index.mjs +0 -91
@@ -10,14 +10,22 @@
10
10
  */
11
11
  import { SESSION_RULES } from '../../core/constants.mjs'
12
12
  import { pendingPatternStubs } from '../../core/patterns.mjs'
13
- import { projDirOf } from './shared.mjs'
13
+ import { probeShells } from '../../core/env.mjs'
14
+ import { loadState, saveState, statePath } from '../../core/state.mjs'
15
+ import { projDirOf, sidOf } from './shared.mjs'
14
16
 
15
17
  export function systemPromptRulesListener({ warn } = {}) {
16
18
  return async (assembly, context, next) => {
17
19
  let downstream
18
20
  try {
19
21
  downstream = await next()
20
- return withRulesSection(downstream, patternsNotice(context))
22
+ // 顺序有意:常量段(执行体)在前,可变段(经验库)垫尾。
23
+ // section 是按序拼接的,把「会消失的那段」放最后,它消失时前缀不跟着变。
24
+ return withRulesSection(downstream, [
25
+ ['focus-guard-env', execNotice()],
26
+ ['focus-guard-patterns', patternsNotice(context)],
27
+ ['focus-guard-scratch', scratchNotice(context)],
28
+ ])
21
29
  } catch (error) {
22
30
  if (typeof warn === 'function') warn('常驻规则注入异常(不阻塞):', (error && error.message) || error)
23
31
  return downstream
@@ -25,6 +33,51 @@ export function systemPromptRulesListener({ warn } = {}) {
25
33
  }
26
34
  }
27
35
 
36
+ /**
37
+ * 执行体约束(2026-11-28)。
38
+ *
39
+ * 病根:`platform-deny` 拦得对,但**只拦不前置**。实测 19 天审计日志:
40
+ * bash 里敲 `Select-Object` 被拦 11 次(跨 8 个回合、跨 2 天),pwsh 里用 `&&`
41
+ * 被拦 8 次(跨 6 个回合)。不是同一回合试错——是跨回合遗忘。
42
+ * 拦下只改当次调用,改不了下一回合的默认写法,于是同一条命令被拦第二遍。
43
+ *
44
+ * 为什么独立 section 而不写进 `SESSION_RULES`:那段是逐字镜像,222 字基准被
45
+ * `RULES.md` 第四部分与 `BENCH.md` 同时锁着,改它要动三处口径;而且它对所有平台
46
+ * 都成立,塞进平台专用文本会让非 Windows 用户白付这段字。
47
+ *
48
+ * 为什么按「本机有没有这个 shell」生成、不按会话:`shellIdForTool` 已经确立了
49
+ * 「执行体按工具判」——同一会话 bash / PowerShell 可以并存(本机就是)。所以这段
50
+ * 描述的是**闸门会怎么判**,不是「你这个会话是什么」。两者混着写,迟早对不上。
51
+ *
52
+ * 字节稳定:模块级 lazy 常量,本进程只算一次;非 Windows 返回空串,零注入成本。
53
+ */
54
+ let execNoticeCache
55
+ function execNotice() {
56
+ if (execNoticeCache !== undefined) return execNoticeCache
57
+ execNoticeCache = ''
58
+ try {
59
+ if (process.platform !== 'win32') return execNoticeCache
60
+ const shells = probeShells()
61
+ const parts = []
62
+ if (shells.includes('bash')) {
63
+ parts.push('bash 工具跑 bash:Select-Object / Get-ChildItem 等 PowerShell cmdlet 不存在,改用 cat / grep / sed / tee')
64
+ }
65
+ if (shells.includes('powershell') || shells.includes('pwsh7')) {
66
+ // 2026-11-28:原先一律写「PowerShell 工具禁 &&」。实测本机 pwsh 与 DSH 的 PowerShell
67
+ // 工具都是 7.7 Core,`&&` 合法——把 5.1 的限制套到 7 上,等于教模型写更啰嗦的命令。
68
+ parts.push(
69
+ shells.includes('pwsh7')
70
+ ? 'PowerShell:pwsh7 可用 &&,5.1 禁 &&;两者都禁 bash 管道工具'
71
+ : 'Windows PowerShell 5.1 禁 &&(用 ;)与 bash 管道工具',
72
+ )
73
+ }
74
+ if (parts.length) execNoticeCache = `【执行体】${parts.join(';')}。拦下≠环境故障。`
75
+ } catch {
76
+ execNoticeCache = ''
77
+ }
78
+ return execNoticeCache
79
+ }
80
+
28
81
  /**
29
82
  * 经验库「教训」待补提醒(2026-11-08)。
30
83
  *
@@ -48,11 +101,44 @@ function patternsNotice(context) {
48
101
  }
49
102
  }
50
103
 
51
- /** 下游是预期 assembly 形状时追加独立 section;否则原样透传(不强行改写)。 */
52
- function withRulesSection(downstream, extra) {
104
+ /**
105
+ * 临时资源清理失败的整改要求(2026-11-28)。
106
+ *
107
+ * 为什么要有这一段:清理器原来把失败全吞进 `catch {}`,于是「删不掉」与「没有可删」
108
+ * 在外部完全同形——三次失效(旧位置误删 / 测试产物不清 / 目录漏清)全靠人翻 `%TEMP%`
109
+ * 才发现。失败现在由 `session-start` 写进 `state.scratchAlert`,这里取出并**报告一次**。
110
+ *
111
+ * 只报一次是有意的:同一条失败每步复述,模型会当背景噪声忽略;而它下次会话启动
112
+ * 若仍失败,会重新写入——所以「持续失败」照样会被看见,只是不刷屏。
113
+ *
114
+ * 不作判定:清理不了是环境问题(文件被占用)还是判据问题(名字对不上),
115
+ * 上下文只有模型有——例如它刚跑过测试、或知道某个进程还没退。
116
+ */
117
+ function scratchNotice(context) {
118
+ try {
119
+ const sid = sidOf(context && context.agent)
120
+ if (!sid) return ''
121
+ const file = statePath(sid)
122
+ const st = loadState(file)
123
+ if (!st || !st.scratchAlert) return ''
124
+ const line = String(st.scratchAlert)
125
+ st.scratchAlert = null
126
+ saveState(file, st)
127
+ return line
128
+ } catch {
129
+ return ''
130
+ }
131
+ }
132
+
133
+ /**
134
+ * 下游是预期 assembly 形状时追加独立 section;否则原样透传(不强行改写)。
135
+ *
136
+ * `extras` 是 `[段名, 文本]` 对:文本为空即跳过,所以「本机不适用」的段一个字节都不占。
137
+ */
138
+ function withRulesSection(downstream, extras = []) {
53
139
  if (downstream && typeof downstream === 'object' && Array.isArray(downstream.sections)) {
54
140
  const sections = [...downstream.sections, { name: 'focus-guard-rules', text: SESSION_RULES }]
55
- if (extra) sections.push({ name: 'focus-guard-patterns', text: extra })
141
+ for (const [name, text] of extras) if (text) sections.push({ name, text })
56
142
  return { ...downstream, sections }
57
143
  }
58
144
  return downstream
@@ -4,13 +4,20 @@
4
4
  * ① system-prompt/assemble:峰谷成本提示行注入;
5
5
  * ② tools/post-execute:token 用量折算 → 成本台账落卷(只观测,不改决策)。
6
6
  * 外加「磁盘代码 vs 内存实例」一致性提示(FG 是 link 挂载,启动后改盘不会热更)。
7
+ *
8
+ * 2026-11-30 从 `guard/` 移入 `seams/`:本文件导出的是两条缝的监听器
9
+ * (`systemPromptListener` / `postExecuteListener`),由 `index.js` 注册到
10
+ * `system-prompt/assemble` 与 `tools/post-execute`,判定链上没有「版本/成本」这一段。
11
+ * 此前住在闸目录里,`pipeline.mjs` 的头注释便把它当成「各层实现」之一列出——
12
+ * 目录放错会让读代码的人误判判定链有几段。
7
13
  */
8
14
  import { statSync } from 'node:fs'
9
15
  import { fileURLToPath } from 'node:url'
10
- import { appendCostRow } from '../audit.mjs'
16
+ import { appendCostRow } from '../cost-ledger.mjs'
11
17
  import { projDirOf } from '../sessionScope.mjs'
12
18
  import { isPeakAt, isSaveStreamEnabled } from '../../peak-cost.mjs'
13
- import { recordToolResult } from './retryGuard.mjs'
19
+ import { recordToolResult } from '../guard/retryGuard.mjs'
20
+ import { modelIdOf } from '../guard/tooling.mjs'
14
21
  import { fmtTime } from '../../core/state.mjs'
15
22
 
16
23
  /** 每次改动流水线递增;用于磁盘/内存版本一致性提示 */
@@ -158,10 +165,9 @@ export function postExecuteListener({ warn }) {
158
165
  usageOf(result && result.meta && result.meta.usage)
159
166
  if (usage) {
160
167
  costMissStreak = 0
161
- const model =
162
- (exec && ((exec.agent && (exec.agent.model || exec.agent.modelId)) || exec.model)) ||
163
- (result && result.model) ||
164
- 'unknown'
168
+ // 模型标识与画像共用同一个出口(tooling.modelIdOf):两处各写一份时,补了会话头路径的
169
+ // 那份会生效、漏补的那份恒记 unknown——成本台账与画像就会指向两个不同的模型。
170
+ const model = modelIdOf(exec) || (result && result.model) || 'unknown'
165
171
  const { inPeak } = isPeakAt(new Date())
166
172
  // 传会话项目目录:成本台账必须落进**这份**卷宗,而不是插件安装目录下的另一份。
167
173
  // 时间走 fmtTime(本地、无 `Z`):同一份卷宗里【一】【三】【四】都是本地时间,
@@ -24,7 +24,9 @@ import {
24
24
  ensureCaseFile,
25
25
  loadCaseRecords,
26
26
  fmtTime,
27
+ cleanStaleTemp,
27
28
  } from '../../core/state.mjs'
29
+ import { scratchAlert } from '../../core/scratch.mjs'
28
30
  import { noteFail } from '../../core/audit.mjs'
29
31
  import { detectEnv, probeShells, quickShellId } from '../../core/env.mjs'
30
32
  import { bridgeNotice } from '../bridgeCheck.mjs'
@@ -93,6 +95,18 @@ export function sessionStartListener({ warn } = {}) {
93
95
  detectEnvInto(state, projDir)
94
96
  if (projDir) prepareProject({ sid, projDir, state })
95
97
 
98
+ // ── 临时资源统一调度(2026-11-28)─────────────────────────────────
99
+ // 此前 `cleanStaleTemp` 只挂在 ZCode 通道的 `hooks/guard.mjs`。ZCode 已退役,
100
+ // 于是**面向大众的这条通道从来没清理过**——补丁打了三次,一次都没在这条路上跑。
101
+ // 现在它是这里的固定一步:同步执行(一次 readdir + 每项一次 lstat),失败不阻塞,
102
+ // 但必须让模型看见:写进 state,由 `prompt-rules` 的下一步注入一次。
103
+ try {
104
+ const report = cleanStaleTemp(sid)
105
+ state.scratchAlert = scratchAlert(report) || null
106
+ } catch (error) {
107
+ warn('临时资源调度异常(不阻塞):', (error && error.message) || error)
108
+ }
109
+
96
110
  // 官方桥版本核验(2026-11-22):桥由官方仓库维护,适配层只支持已验证区间;
97
111
  // 区间外报警并给升级/回退命令,不静默跑(只 warn,不阻断)。
98
112
  const bridgeLine = bridgeNotice()
package/src/dsh/tools.mjs CHANGED
@@ -18,7 +18,7 @@ import { applyEligibility, grantFromAppeal, FG_APPLY_TOOL_SPEC, FG_APPEAL_TOOL_S
18
18
  import { ABSOLUTE_REDLINES } from '../core/redlines.mjs'
19
19
  import { sidOf } from './sessionScope.mjs'
20
20
  import { livenessBadge } from './heartbeat.mjs'
21
- import { readWorkspace, renderWorkspaceSection } from '../memory/workspace.mjs'
21
+ import { readWorkspace, renderWorkspaceSection } from '../memory/index.mjs'
22
22
 
23
23
  /** 简化参数表({type,required,description,enum})→ JSON Schema。 */
24
24
  function specToJsonSchema(spec = {}) {
@@ -2,7 +2,9 @@
2
2
  * 记忆模块唯一入口(4.5 M1,2026-11-02)。
3
3
  *
4
4
  * 分层纪律:本模块不 import 任何 `src/dsh/`;宿主适配层只准 import 这里。
5
- * 旧路径 `src/dsh/workspace.mjs` 保留转发,调用方不必改。
5
+ * 2026-11-30:旧路径转发壳 `src/dsh/workspace.mjs` 已删。它是反的——让 `dsh/` 里留一个
6
+ * memory 的出口,等于把上一条纪律的例外做成常设。现所有调用方(含 `dsh/tools.mjs`,
7
+ * 它此前直接 import `memory/workspace.mjs` 也属违纪)一律走本文件。
6
8
  *
7
9
  * 注入边界(2026-11-02 定,2026-11-22 更新):
8
10
  * ① 不新开 `focus-guard-memory` 段;原 `focus-guard-workspace` 段自 2026-11-22 起
@@ -15,16 +15,18 @@ export default {
15
15
  evasionRisk: 'high', // TODO(实测):未校准,'high' = 与 3.0.8 行为一致(全部高危类别需审批)
16
16
 
17
17
  // —— 治理层开关(每个维度独立)——
18
- stalledFuse: { enabled: true, threshold: 3 }, // TODO(实测):停滞熔断阈值
19
- budgetGate: { enabled: true, ceiling: 200 }, // TODO(实测):预算上限
20
- reasoningWatch: { enabled: true, maxSeconds: 90 }, // TODO:引擎未实现,仅登记
18
+ // 2026-11-29 数值来自行为实测(5 个最大 DSH 会话:7,121 步 / 约 7,000 次工具调用):
19
+ // 同工具同目标连 ≥3 次占 2.1%,≥5 次占 0.3% → 阈值 5 只碰真打转;
20
+ // 单回合不同调用 p95 30 / max 61 → 上限 100 留 1.6 倍余量。
21
+ stalledFuse: { enabled: true, threshold: 5 }, // 实测 2026-11-29
22
+ budgetGate: { enabled: true, ceiling: 100 }, // 实测 2026-11-29
23
+ reasoningWatch: { enabled: true, maxSeconds: 90 }, // 引擎未实现,已排期 3.6.8;判据改「模型侧时长」(实测 max 58.7s),现值待批
21
24
  evidenceGate: { enabled: true }, // L4 未取证
22
- emotionFilter: { enabled: true }, // TODO:引擎未实现,仅登记
23
25
  approvalGate: { enabled: true }, // L3 高危资格(scope 派生自 evasionRisk,显式 scope 优先)
24
26
  redlineGate: { enabled: true }, // L2 绝对红线
25
27
 
26
- // —— API 兼容度(供适配层选路)——
27
- apiCompat: 'openai-strict',
28
- toolCallFormat: 'standard',
29
- supportsParallelTools: true,
28
+ // —— 已下架封存(2026-11-29):不读取、不报告、不执行 ——
29
+ // 原因:治理层写不出判据(情绪不是一次工具调用的属性),人格层未立项(VERSION-PLAN §4.5.2 档 3)。
30
+ // 字段保留只为画像维度齐全;恢复条件三条见 core/profileLoader.mjs 的 RETIRED_SWITCHES。
31
+ emotionFilter: { enabled: true },
30
32
  }
@@ -15,16 +15,17 @@ export default {
15
15
 
16
16
  // —— 治理层开关(每个维度独立)——
17
17
  // 相对 flash:推理更强、可容忍更长停滞与更高预算,其余治理层不放松。
18
- stalledFuse: { enabled: true, threshold: 4 }, // TODO(实测):停滞熔断阈值
19
- budgetGate: { enabled: true, ceiling: 300 }, // TODO(实测):预算上限
20
- reasoningWatch: { enabled: true, maxSeconds: 180 }, // TODO:引擎未实现,仅登记
18
+ // 2026-11-29:pro 在本机无真实流量(会话记录里 model 全为 deepseek-flash),以下为按 flash
19
+ // 实测基线外推的保守值,标注「待实测」;一旦出现 pro 流量,用同一套行为统计回填。
20
+ stalledFuse: { enabled: true, threshold: 6 }, // 待实测:flash 5 + 1
21
+ budgetGate: { enabled: true, ceiling: 150 }, // 待实测:flash 100 ×1.5
22
+ reasoningWatch: { enabled: true, maxSeconds: 180 }, // 引擎未实现,已排期 3.6.8;判据改「模型侧时长」,现值待批(无 pro 流量)
21
23
  evidenceGate: { enabled: true }, // L4 未取证
22
- emotionFilter: { enabled: true }, // TODO:引擎未实现,仅登记
23
24
  approvalGate: { enabled: true }, // L3 高危资格(scope 派生自 evasionRisk,显式 scope 优先)
24
25
  redlineGate: { enabled: true }, // L2 绝对红线
25
26
 
26
- // —— API 兼容度(供适配层选路)——
27
- apiCompat: 'openai-strict',
28
- toolCallFormat: 'standard',
29
- supportsParallelTools: true,
27
+ // —— 已下架封存(2026-11-29):不读取、不报告、不执行 ——
28
+ // 原因:治理层写不出判据(情绪不是一次工具调用的属性),人格层未立项(VERSION-PLAN §4.5.2 档 3)。
29
+ // 字段保留只为画像维度齐全;恢复条件三条见 core/profileLoader.mjs 的 RETIRED_SWITCHES。
30
+ emotionFilter: { enabled: true },
30
31
  }
@@ -5,6 +5,9 @@
5
5
  //
6
6
  // 兜底策略:行为未知的模型按**最严治理**处理——所有治理层开启,
7
7
  // 未知 API 兼容度按最保守取值,不假设支持并行工具调用。
8
+ //
9
+ // 2026-11-29 补一句:**最严 ≠ 阈值最小**。阈值 3 会把 2.1% 的正常重试判成空转(误伤即治理失败),
10
+ // 故兜底画像与 flash 同取 5/100;真正「严」的是开关全开、API 兼容度按 unknown 取值。
8
11
 
9
12
  export default {
10
13
  id: 'default',
@@ -16,16 +19,19 @@ export default {
16
19
  evasionRisk: 'high', // TODO(实测):兜底画像不得低设,除非人类明确指定
17
20
 
18
21
  // —— 治理层开关(每个维度独立)——
19
- stalledFuse: { enabled: true, threshold: 3 }, // TODO(实测):停滞熔断阈值
20
- budgetGate: { enabled: true, ceiling: 200 }, // TODO(实测):预算上限
21
- reasoningWatch: { enabled: true, maxSeconds: 90 }, // TODO:引擎未实现,仅登记
22
+ // 2026-11-29 数值来自行为实测(5 个最大 DSH 会话:7,121 步 / 约 7,000 次工具调用):
23
+ // 同工具同目标连 ≥3 次占 2.1%,≥5 次占 0.3% → 阈值 3 会把正常重试判成空转,5 只碰真打转;
24
+ // 单回合不同调用 p95 30 / max 61 → 上限 100 留 1.6 倍余量,200 等于没设。
25
+ // 此前这两个字段写了两个月但**全仓无读取点**(运行时恒用常量 5/200),本次一并接上(T9–T11)。
26
+ stalledFuse: { enabled: true, threshold: 5 }, // 实测 2026-11-29:≥5 连停仅 0.3%
27
+ budgetGate: { enabled: true, ceiling: 100 }, // 实测 2026-11-29:单回合最高 61 次
28
+ reasoningWatch: { enabled: true, maxSeconds: 90 }, // 引擎未实现,已排期 3.6.8;判据改「模型侧时长」(实测 max 58.7s),现值待批
22
29
  evidenceGate: { enabled: true }, // L4 未取证
23
- emotionFilter: { enabled: true }, // TODO:引擎未实现,仅登记
24
30
  approvalGate: { enabled: true }, // L3 高危资格(scope 派生自 evasionRisk,显式 scope 优先)
25
31
  redlineGate: { enabled: true }, // L2 绝对红线
26
32
 
27
- // —— API 兼容度(未知即保守)——
28
- apiCompat: 'unknown', // TODO(实测)
29
- toolCallFormat: 'standard', // TODO(实测)
30
- supportsParallelTools: false, // TODO(实测):未知模型不假设支持
33
+ // —— 已下架封存(2026-11-29):不读取、不报告、不执行 ——
34
+ // 原因:治理层写不出判据(情绪不是一次工具调用的属性),人格层未立项(VERSION-PLAN §4.5.2 档 3)。
35
+ // 字段保留只为画像维度齐全;恢复条件三条见 core/profileLoader.mjs 的 RETIRED_SWITCHES。
36
+ emotionFilter: { enabled: true },
31
37
  }
@@ -16,16 +16,17 @@ export default {
16
16
  evasionRisk: 'high', // TODO(实测):未校准,'high' = 与 3.0.8 行为一致
17
17
 
18
18
  // —— 治理层开关(每个维度独立)——
19
- stalledFuse: { enabled: true, threshold: 3 }, // TODO(实测):停滞熔断阈值
20
- budgetGate: { enabled: true, ceiling: 200 }, // TODO(实测):预算上限
21
- reasoningWatch: { enabled: true, maxSeconds: 120 }, // TODO:引擎未实现,仅登记
19
+ // 2026-11-29:GLM 在本机无真实流量(会话记录里 model 全为 deepseek-flash),
20
+ // 阈值与 flash 相同、不改判据;有流量后再用同一套行为统计回填。
21
+ stalledFuse: { enabled: true, threshold: 5 }, // 待实测:与 flash 同值
22
+ budgetGate: { enabled: true, ceiling: 100 }, // 待实测:与 flash 同值
23
+ reasoningWatch: { enabled: true, maxSeconds: 120 }, // 引擎未实现,已排期 3.6.8;判据改「模型侧时长」,现值待批
22
24
  evidenceGate: { enabled: true }, // L4 未取证
23
- emotionFilter: { enabled: true }, // TODO:引擎未实现,仅登记
24
25
  approvalGate: { enabled: true }, // L3 高危资格(scope 派生自 evasionRisk,显式 scope 优先)
25
26
  redlineGate: { enabled: true }, // L2 绝对红线
26
27
 
27
- // —— API 兼容度(供适配层选路)——
28
- apiCompat: 'openai-strict', // TODO(实测):GLM 走 OpenAI 兼容接口
29
- toolCallFormat: 'standard', // TODO(实测)
30
- supportsParallelTools: true, // TODO(实测)
28
+ // —— 已下架封存(2026-11-29):不读取、不报告、不执行 ——
29
+ // 原因:治理层写不出判据(情绪不是一次工具调用的属性),人格层未立项(VERSION-PLAN §4.5.2 档 3)。
30
+ // 字段保留只为画像维度齐全;恢复条件三条见 core/profileLoader.mjs 的 RETIRED_SWITCHES。
31
+ emotionFilter: { enabled: true },
31
32
  }
@@ -7,7 +7,7 @@
7
7
  // 与 deepseek-flash 的差异(用于验收「同请求不同画像决策不同」):
8
8
  // evidenceGate off → L4 未取证不再 deny
9
9
  // stalledFuse off → 停滞熔断子判据不启用
10
- // emotionFilter off → 仅登记项,本就不绑定执行
10
+ // emotionFilter → 已下架封存,不读取不报告(见 core/profileLoader.mjs RETIRED_SWITCHES)
11
11
  // approvalGate scope: 'irreversible' → 高危资格收窄到不可逆操作
12
12
  // evasionRisk: 'low' → 与上面同向;但**显式 scope 优先**,本文件保留显式值作数据
13
13
 
@@ -20,16 +20,18 @@ export default {
20
20
  evasionRisk: 'low', // TODO(实测):未校准;下方 approvalGate.scope 是显式值,优先于本派生
21
21
 
22
22
  // —— 治理层开关(每个维度独立)——
23
- stalledFuse: { enabled: false, threshold: 3 }, // TODO(实测):关闭
24
- budgetGate: { enabled: true, ceiling: 200 }, // TODO(实测):预算上限
25
- reasoningWatch: { enabled: true, maxSeconds: 90 }, // TODO:引擎未实现,仅登记
23
+ // 2026-11-29:`stalledFuse.enabled:false` 此前是死配置——postProgress 从不读画像,
24
+ // 关掉也不生效;接线后它第一次真正生效(见 core/profileLoader.mjs 的 governanceLimitsOf)。
25
+ stalledFuse: { enabled: false, threshold: 5 }, // 差异化:关闭(现已真正生效);阈值列出仅为可读
26
+ budgetGate: { enabled: true, ceiling: 100 }, // 2026-11-29:无流量,与 flash 同值(不放宽无依据的档位)
27
+ reasoningWatch: { enabled: true, maxSeconds: 90 }, // 引擎未实现,已排期 3.6.8;判据改「模型侧时长」(实测 max 58.7s),现值待批
26
28
  evidenceGate: { enabled: false }, // 差异化:关闭 L4 未取证闸
27
- emotionFilter: { enabled: false }, // TODO:引擎未实现,仅登记
28
29
  approvalGate: { enabled: true, scope: 'irreversible' }, // L3:仅不可逆操作需审批(显式 scope 优先于 evasionRisk)
29
30
  redlineGate: { enabled: true }, // L2 绝对红线
30
31
 
31
- // —— API 兼容度(供适配层选路)——
32
- apiCompat: 'openai-strict',
33
- toolCallFormat: 'standard',
34
- supportsParallelTools: true,
32
+ // —— 已下架封存(2026-11-29):不读取、不报告、不执行 ——
33
+ // 原因:治理层写不出判据(情绪不是一次工具调用的属性),人格层未立项(VERSION-PLAN §4.5.2 档 3)。
34
+ // 这里的 false 不是"关掉了一项治理"——它本来就没有执行物;字段保留只为画像维度齐全,
35
+ // 恢复条件三条见 core/profileLoader.mjs 的 RETIRED_SWITCHES。
36
+ emotionFilter: { enabled: false },
35
37
  }
@@ -65,13 +65,38 @@ function textTree(recs, chainFilter) {
65
65
  return out.join("\n");
66
66
  }
67
67
 
68
+ /**
69
+ * 索引**一次**,之后全部 O(1) 取。
70
+ *
71
+ * 2026-11-28 改:原实现在两个循环里各调一次 `recs.find(...)`(按 seq 取节点、
72
+ * 按 chain 取链首事件),复杂度 O(n²)。实测 2 万行 532ms → 6 万行 3042ms(行数 3 倍、耗时 5.7 倍)。
73
+ * AUDIT.log 体积轮转上限 5MB ≈ 2 万条,正好落在曲线上翘的那一段。
74
+ *
75
+ * 同文件的 `textTree` 早就建了 `bySeq`,只有 mermaid 这条路径没建——同一个文件里两份口径。
76
+ *
77
+ * 语义必须与原 `find` 一致:**同 seq 重复时取首条**(`find` 的语义),
78
+ * 而 `new Map(recs.map(...))` 是后者覆盖前者。本仓真实日志出现过 17 组 seq 撞号
79
+ * (见 `core/audit-writer.mjs` 的 nextSeq 注释),所以这里显式 `if (!has) set`。
80
+ */
81
+ function indexRecords(recs) {
82
+ const bySeq = new Map();
83
+ const firstOfChain = new Map();
84
+ for (const r of recs) {
85
+ if (!bySeq.has(r.seq)) bySeq.set(r.seq, r);
86
+ const c = r.chain || "(无链)";
87
+ if (!firstOfChain.has(c)) firstOfChain.set(c, r);
88
+ }
89
+ return { bySeq, firstOfChain };
90
+ }
91
+
68
92
  function mermaid(recs, chainFilter) {
93
+ const { bySeq, firstOfChain } = indexRecords(recs);
69
94
  const ids = new Map();
70
95
  let n = 0;
71
96
  for (const r of recs) if (!chainFilter || r.chain === chainFilter) ids.set(r.seq, `E${++n}`);
72
97
  const lines = ["graph TD"];
73
98
  for (const [seq, id] of ids) {
74
- const r = recs.find((x) => x.seq === seq);
99
+ const r = bySeq.get(seq);
75
100
  lines.push(` ${id}["${short(label(r), 46).replace(/"/g, "'")}"]`);
76
101
  }
77
102
  for (const r of recs) {
@@ -81,12 +106,12 @@ function mermaid(recs, chainFilter) {
81
106
  }
82
107
  }
83
108
  // 链间的父子关系:子代理链首事件 ref 指向父链派单事件
84
- const chains = new Set(recs.filter((r) => !chainFilter).map((r) => r.chain || "(无链)"));
109
+ const chains = new Set((chainFilter ? [] : recs).map((r) => r.chain || "(无链)"));
85
110
  for (const c of chains) {
86
111
  const m = String(c).match(/^(.+)\/d\d+$/);
87
112
  if (m && chains.has(m[1])) {
88
- const childFirst = recs.find((r) => r.chain === c);
89
- const parentFirst = recs.find((r) => r.chain === m[1]);
113
+ const childFirst = firstOfChain.get(c);
114
+ const parentFirst = firstOfChain.get(m[1]);
90
115
  if (childFirst && parentFirst && ids.has(childFirst.seq) && ids.has(parentFirst.seq)) {
91
116
  lines.push(` ${ids.get(parentFirst.seq)} -.-> ${ids.get(childFirst.seq)}`);
92
117
  }
@@ -17,40 +17,15 @@
17
17
  */
18
18
  import { readFileSync, existsSync, statSync, readdirSync } from 'node:fs'
19
19
  import { dirname, join, resolve, relative } from 'node:path'
20
- import { fileURLToPath } from 'node:url'
21
20
 
22
- const HERE = dirname(fileURLToPath(import.meta.url))
23
- const ROOT = resolve(HERE, '..', '..', '..')
21
+ import { ROOT, docScope } from './lib/docs-scope.mjs'
24
22
 
25
23
  const args = process.argv.slice(2)
26
24
  const asJson = args.includes('--json')
27
25
  const strict = args.includes('--strict')
28
26
 
29
- /** 扫描范围:docs 树 + 入口文档;归档与 vault 笔记不扫(历史材料,改了也不该被当前事实约束)。 */
30
- function walkDocs(dir, out = []) {
31
- let entries
32
- try {
33
- entries = readdirSync(dir, { withFileTypes: true })
34
- } catch {
35
- return out
36
- }
37
- for (const e of entries) {
38
- if (e.name === 'archive' || e.name === 'vault-notes' || e.name === 'node_modules') continue
39
- const p = join(dir, e.name)
40
- if (e.isDirectory()) walkDocs(p, out)
41
- else if (e.name.endsWith('.md')) out.push(p)
42
- }
43
- return out
44
- }
45
-
46
- const FILES = [
47
- ...walkDocs(join(ROOT, 'docs')),
48
- ...walkDocs(join(ROOT, 'packages/core/docs')),
49
- join(ROOT, 'README.md'),
50
- join(ROOT, 'INSTALL.md'),
51
- join(ROOT, 'packages/core/README.md'),
52
- join(ROOT, 'packages/core/README.zh-CN.md'),
53
- ].filter((f) => existsSync(f) && !/HANDOFF-/.test(f))
27
+ // 扫描范围与 docs:refs 共用一份清单,别在这里另抄——抄两份必然分叉(`lib/docs-scope.mjs`)。
28
+ const FILES = docScope()
54
29
 
55
30
  const scripts = Object.keys(JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).scripts || {})
56
31
 
@@ -126,7 +101,10 @@ function checkPath(file, line, token, lineText = '') {
126
101
  }
127
102
  }
128
103
  // 计划/设计类段落里的路径是「将来要建」,不是当前事实;只报告已建成文档里的死路径。
129
- if (/计划|待做|未做|目标|将|拟|设计/.test(lineText)) return
104
+ // `待建` 于 2026-11-26 加入:`VERSION-PLAN` 的落点表要写「这条任务要新建哪个文件」,
105
+ // 那类路径按定义还不存在。只收这一个词,不收「新增」——后者在既成事实的叙述里太常见
106
+ // (「新增 X 工具」),加进去等于把闸门关掉一半。
107
+ if (/计划|待做|未做|目标|将|拟|设计|待建/.test(lineText)) return
130
108
  report(file, line, 'repo-path', bare, '文件或目录不存在')
131
109
  }
132
110
 
@@ -4,16 +4,19 @@
4
4
  * 用法:
5
5
  * node packages/core/tools/docs-lint.mjs # 明细
6
6
  * node packages/core/tools/docs-lint.mjs --brief # 一行(供 npm run check)
7
+ * node packages/core/tools/docs-lint.mjs --where # 每条问题附上出错那一行原文
7
8
  * node packages/core/tools/docs-lint.mjs --json # 机器读
8
9
  * node packages/core/tools/docs-lint.mjs --strict # 有问题即 exit 1
9
10
  * node packages/core/tools/docs-lint.mjs --sync-status # 重新生成 docs/STATUS.md
10
11
  *
11
12
  * 闸门是棘轮:`BUDGET` 记当前存量(初始 0),只许降不许升。
12
13
  * 这是 3.5「文档重置完成」的前置尺子(D5);README 硬指标、数字单点、状态头分别归 D1/D4/D2。
14
+ *
15
+ * 报点:一律 `文件:行号`(见 `lib/where.mjs`)。行号找不到时只给文件名,
16
+ * **不拿第 1 行顶替**——假行号会让人跳到文件开头再自己找,比没有行号更费时。
13
17
  */
14
18
  import { writeFileSync } from 'node:fs'
15
19
  import { join } from 'node:path'
16
- import { fileURLToPath } from 'node:url'
17
20
  import {
18
21
  listMarkdownFiles,
19
22
  checkVersionFace,
@@ -28,17 +31,23 @@ import {
28
31
  } from './lib/docs-core.mjs'
29
32
  import { checkVersionClaims, checkReadmeVersionFace } from './lib/docs-version.mjs'
30
33
  import { checkAckFreshness } from './lib/docs-ack.mjs'
34
+ import { checkDocTypography } from './lib/docs-typography.mjs'
31
35
  import { STATUS_DOC, collectDocStatus, renderStatusTable, checkStatusTable } from './lib/docs-status.mjs'
32
36
  import { checkModulePaths, checkModuleIds, checkModuleOverlap, checkModuleCoverage } from './lib/modules.mjs'
37
+ import { renderFinding } from './lib/where.mjs'
38
+ import { has, repoRoot } from './lib/cli.mjs'
33
39
 
34
- const ROOT = fileURLToPath(new URL('../../../', import.meta.url))
35
- const argv = process.argv.slice(2)
36
- const AS_JSON = argv.includes('--json')
37
- const BRIEF = argv.includes('--brief')
38
- const STRICT = argv.includes('--strict')
39
- const SYNC_STATUS = argv.includes('--sync-status')
40
+ const ROOT = repoRoot(import.meta.url)
41
+ const AS_JSON = has('--json')
42
+ const BRIEF = has('--brief')
43
+ const WHERE = has('--where')
44
+ const STRICT = has('--strict')
45
+ const SYNC_STATUS = has('--sync-status')
40
46
  const BUDGET = 0
41
47
 
48
+ /** brief 超限时逐条列出的上限:够看出"该怎么改",又不至于把 CI 日志淹掉。 */
49
+ const BRIEF_SHOW = 8
50
+
42
51
  /**
43
52
  * 按规则的存量豁免(3.3 A)。
44
53
  *
@@ -46,7 +55,14 @@ const BUDGET = 0
46
55
  * 2026-11-07 历史段(≤3.0.7)原样移入 `docs/archive/`(不在扫描面内),存量归零,额度一并收回。
47
56
  * 判据:豁免是**存量**的记账。存量没了还留着额度,等于给未来的死链预留藏身处。
48
57
  */
49
- const RULE_BUDGET = { 'dead-code-path': 0 }
58
+ const RULE_BUDGET = {
59
+ 'dead-code-path': 0,
60
+ // 体例存量(2026-11-29 建判据时实测)。`bold-span-long` 当场清零;
61
+ // `table-cell-long` 剩 25 处,全是四列以上的对照表里"说明"那一格——
62
+ // 要动它们得先决定那段话挪到哪,属编辑而非机械,按棘轮记账、只许降不许升。
63
+ 'table-cell-long': 25,
64
+ 'bold-span-long': 0,
65
+ }
50
66
 
51
67
  const files = listMarkdownFiles(ROOT)
52
68
 
@@ -67,11 +83,12 @@ const findings = [
67
83
  ...checkIndexCoverage(ROOT, allDocFiles(ROOT)),
68
84
  ...checkStatusTable(ROOT, files),
69
85
  ...checkModulePaths(ROOT),
70
- ...checkModuleIds(),
86
+ ...checkModuleIds(ROOT),
71
87
  ...checkModuleOverlap(ROOT),
72
88
  ...checkModuleCoverage(ROOT),
73
89
  ...checkReadmeMetrics(ROOT),
74
90
  ...checkCitationStyle(ROOT),
91
+ ...checkDocTypography(ROOT, files),
75
92
  ...checkVersionClaims(ROOT),
76
93
  ...checkReadmeVersionFace(ROOT),
77
94
  ...checkAckFreshness(ROOT, files),
@@ -84,20 +101,46 @@ const over = Object.entries(byRule).reduce(
84
101
  0,
85
102
  )
86
103
 
104
+ /**
105
+ * 超限的规则逐条点名。
106
+ *
107
+ * brief 只报计数时,CI 上看到的是"超限 1 条",然后你得回本地重跑一遍明细才知道是哪一行——
108
+ * **闸门红的那一刻就是最该给出位置的那一刻**,过了那一刻人已经离开了。
109
+ */
110
+ function offenders() {
111
+ const groups = {}
112
+ for (const f of findings) {
113
+ if (!groups[f.rule]) groups[f.rule] = []
114
+ groups[f.rule].push(f)
115
+ }
116
+ const lines = []
117
+ for (const [rule, list] of Object.entries(groups)) {
118
+ const budget = RULE_BUDGET[rule] || 0
119
+ if (list.length <= budget) continue
120
+ lines.push(` 超限 ${rule}:${list.length} 条 / 上限 ${budget}`)
121
+ for (const f of list.slice(0, BRIEF_SHOW)) lines.push(` ${renderFinding(f, { root: ROOT, withSource: WHERE })}`)
122
+ if (list.length > BRIEF_SHOW) lines.push(` …另 ${list.length - BRIEF_SHOW} 条,跑 npm run docs:lint 看全量`)
123
+ }
124
+ return lines
125
+ }
126
+
87
127
  if (AS_JSON) {
88
128
  console.log(JSON.stringify({ files: files.length, findings, byRule, budget: BUDGET, ruleBudget: RULE_BUDGET, over }, null, 2))
89
129
  } else if (BRIEF) {
90
130
  const parts = Object.entries(byRule)
91
131
  .sort((a, b) => b[1] - a[1])
92
132
  .map(([r, n]) => `${r} ${n}${RULE_BUDGET[r] ? `(豁免${RULE_BUDGET[r]})` : ''}`)
93
- const gate = over > BUDGET ? `❌ 超上限 ${BUDGET}` : `✅ 上限 ${BUDGET}`
133
+ // 红的那一行要报**实际超出多少条**。写 `超上限 ${BUDGET}` 在 BUDGET=0 时输出「超上限 0」,
134
+ // 读起来是「超了 0 条」,与前面的 ❌ 自相矛盾——报点的数字一旦对不上,人连红绿都不信了。
135
+ const gate = over > BUDGET ? `❌ 超限 ${over} 条 / 上限 ${BUDGET}` : `✅ 上限 ${BUDGET}`
94
136
  console.log(`文档口径:${files.length} 个 md,问题 ${findings.length} 条${parts.length ? `(${parts.join(' / ')})` : ''};${gate}`)
137
+ if (over > BUDGET) console.log(offenders().join('\n'))
95
138
  } else {
96
139
  console.log(`文档口径:${files.length} 个 md,问题 ${findings.length} 条\n`)
97
140
  if (!findings.length) console.log('无问题(版本面一致 / 相对链接全部可达 / 行内路径全部可达)。')
98
141
  for (const f of findings) {
99
142
  const allow = RULE_BUDGET[f.rule] ? '(存量豁免)' : ''
100
- console.log(`${f.file}:${f.line}\t[${f.rule}]${allow} ${f.detail}`)
143
+ console.log(`${renderFinding(f, { root: ROOT, withSource: WHERE })}${allow}`)
101
144
  }
102
145
  console.log(`\n闸门口径:超限 ${over} 条 / 上限 ${BUDGET}(棘轮,只许降不许升)。`)
103
146
  for (const [rule, n] of Object.entries(RULE_BUDGET)) {