focus-guard 3.5.2 → 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.
- package/README.md +15 -3
- package/README.zh-CN.md +14 -4
- package/assets/NOTICE.md +3 -1
- package/docs/ARCH-MAP.md +302 -74
- package/docs/BENCH.md +28 -13
- package/docs/RELEASE-POLICY.md +74 -17
- package/docs/RULES.md +98 -60
- package/docs/THREAT-MODEL.md +3 -3
- package/docs/WRITING-STYLE.md +40 -2
- package/package.json +11 -5
- package/skills/focus-plan/SKILL.md +77 -0
- package/skills/focus-rules/SKILL.md +267 -0
- package/skills/focus-thinking/SKILL.md +8 -255
- package/src/adapters/dsh/eligibility-gate.mjs +75 -35
- package/src/adapters/dsh/session.mjs +22 -0
- package/src/{dsh → adapters/dsh}/toolName.mjs +6 -0
- package/src/core/approvals.mjs +10 -4
- package/src/core/audit-writer.mjs +5 -2
- package/src/core/auditActions.mjs +214 -0
- package/src/core/checkEligibility.mjs +193 -130
- package/src/core/constants.mjs +8 -4
- package/src/core/decisionEngine.mjs +16 -13
- package/src/core/env.mjs +37 -2
- package/src/core/patterns.mjs +3 -1
- package/src/core/prefixStability.mjs +27 -3
- package/src/core/profileLoader.mjs +96 -3
- package/src/core/scratch.mjs +288 -0
- package/src/core/session.mjs +23 -0
- package/src/core/state.mjs +3 -3
- package/src/dsh/audit.mjs +45 -170
- package/src/dsh/bridgeCheck.mjs +81 -0
- package/src/dsh/compactionWatch/announce.mjs +2 -1
- package/src/dsh/compactionWatch.mjs +2 -1
- package/src/dsh/cost-ledger.mjs +174 -0
- package/src/dsh/guard/authz.mjs +3 -3
- package/src/dsh/guard/evidence.mjs +19 -0
- package/src/dsh/guard/retryGuard.mjs +96 -0
- package/src/dsh/guard/risk.mjs +61 -16
- package/src/dsh/guard/tooling.mjs +20 -13
- package/src/dsh/{value-gate.mjs → guard/value-gate.mjs} +6 -0
- package/src/dsh/guard/writing-gate.mjs +117 -0
- package/src/dsh/index.js +4 -7
- package/src/dsh/pipeline.mjs +72 -8
- package/src/dsh/postProgress.mjs +81 -40
- package/src/dsh/preGuard.mjs +12 -3
- package/src/dsh/repeatGuard.mjs +5 -4
- package/src/dsh/seams/pre-step.mjs +74 -23
- package/src/dsh/seams/prompt-rules.mjs +91 -5
- package/src/dsh/{guard → seams}/runtime.mjs +41 -10
- package/src/dsh/seams/session-start.mjs +33 -10
- package/src/dsh/seams/shared.mjs +8 -5
- package/src/dsh/search-hints.mjs +15 -1
- package/src/dsh/sessionScope.mjs +11 -11
- package/src/dsh/stopGuard.mjs +2 -7
- package/src/dsh/tools.mjs +39 -1
- package/src/dsh/traceMeta.mjs +5 -11
- package/src/memory/index.mjs +7 -5
- package/src/memory/workspace.mjs +41 -19
- package/src/profiles/deepseek-flash.mjs +10 -8
- package/src/profiles/deepseek-pro.mjs +9 -8
- package/src/profiles/default.mjs +14 -8
- package/src/profiles/glm.mjs +9 -8
- package/src/profiles/gpt-astra.mjs +11 -9
- package/tools/audit-chain.mjs +29 -4
- package/tools/collect-panel.mjs +3 -24
- package/tools/dead-export.mjs +2 -17
- package/tools/docs-book.mjs +234 -0
- package/tools/docs-drift.mjs +143 -0
- package/tools/docs-lint.mjs +76 -9
- package/tools/docs-refs.mjs +343 -0
- package/tools/gate-audit.mjs +3 -24
- package/tools/handoff.mjs +4 -2
- package/tools/index-stale.mjs +124 -0
- package/tools/install-check.mjs +107 -9
- package/tools/knowledge.mjs +53 -4
- package/tools/layering-audit.mjs +7 -1
- package/tools/legacy-audit.mjs +83 -0
- package/tools/lib/book-style.mjs +42 -1
- package/tools/lib/case-tool.mjs +9 -3
- package/tools/lib/cli.mjs +35 -0
- package/tools/lib/docs-ack.mjs +97 -0
- package/tools/lib/docs-core.mjs +84 -45
- package/tools/lib/docs-files.mjs +73 -0
- package/tools/lib/docs-scope.mjs +46 -0
- package/tools/lib/docs-status.mjs +148 -0
- package/tools/lib/docs-typography.mjs +91 -0
- package/tools/lib/docs-version.mjs +8 -5
- package/tools/lib/dup-block.mjs +117 -0
- package/tools/lib/idioms.mjs +149 -0
- package/tools/lib/import-graph.mjs +8 -3
- package/tools/lib/index-io.mjs +4 -4
- package/tools/lib/index-registry.mjs +101 -0
- package/tools/lib/legacy-core.mjs +178 -0
- package/tools/lib/markdown.mjs +202 -0
- package/tools/lib/modules-doc.mjs +103 -0
- package/tools/lib/modules-list.mjs +396 -0
- package/tools/lib/modules.mjs +360 -0
- package/tools/lib/mutation-ops.mjs +63 -0
- package/tools/lib/parse-block.mjs +58 -0
- package/tools/lib/prefix-cost.mjs +5 -3
- package/tools/lib/ratchet.mjs +22 -8
- package/tools/lib/release-faces.mjs +144 -0
- package/tools/lib/repo-copy.mjs +34 -0
- package/tools/lib/survey-report.mjs +57 -0
- package/tools/lib/where.mjs +139 -0
- package/tools/library-book.mjs +7 -92
- package/tools/library-build.mjs +15 -3
- package/tools/lint.mjs +24 -13
- package/tools/log-audit.mjs +76 -0
- package/tools/memory-audit.mjs +32 -6
- package/tools/memory-distill.mjs +14 -1
- package/tools/memory-recall-eval.mjs +408 -0
- package/tools/module-audit.mjs +2 -17
- package/tools/modules-audit.mjs +110 -0
- package/tools/mutate.mjs +120 -74
- package/tools/panel-baseline.mjs +172 -0
- package/tools/prefix-audit.mjs +10 -2
- package/tools/prefix-drift.mjs +10 -5
- package/tools/registry-check.mjs +200 -0
- package/tools/release.mjs +322 -0
- package/tools/smells.mjs +97 -139
- package/tools/version.mjs +12 -8
- package/docs/AB-PROMPTS.md +0 -123
- package/docs/AB-SESSION.md +0 -161
- package/docs/BENCH-BASELINE.json +0 -95
- package/docs/BRAIN-VIZ.md +0 -94
- package/docs/GATE-INPUTS.json +0 -10
- package/docs/HANDOFF-2026-10-27.md +0 -736
- package/docs/HOOK-ORDERING.md +0 -139
- package/docs/LEGISLATION-LAW.md +0 -104
- package/docs/MCP-4.0-PLAN.md +0 -184
- package/docs/MEMORY-4.5-PLAN.md +0 -415
- package/docs/PROFILE-TUNING.md +0 -147
- package/docs/RATCHET.json +0 -80
- package/docs/TOOL-SCHEMA.json +0 -6
- package/docs/VERSION-PLAN.md +0 -604
- package/docs/architecture-map.mermaid +0 -186
- package/docs/deepseek-pricing-audit.md +0 -65
- package/src/core/staleCleanup.mjs +0 -224
- package/src/dsh/guard/superpowers.mjs +0 -70
- package/src/dsh/workspace.mjs +0 -5
- package/tools/library-index.mjs +0 -91
package/tools/audit-chain.mjs
CHANGED
|
@@ -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 =
|
|
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(
|
|
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 =
|
|
89
|
-
const parentFirst =
|
|
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
|
}
|
package/tools/collect-panel.mjs
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
* node packages/core/tools/collect-panel.mjs panel.json --json
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import { decodeSession as decode } from './lib/sessionDump.mjs'
|
|
26
|
-
import { existsSync, readFileSync,
|
|
25
|
+
import { decodeSession as decode, walkSessionFiles } from './lib/sessionDump.mjs'
|
|
26
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
27
27
|
import { dirname, join } from 'node:path'
|
|
28
28
|
import { fileURLToPath } from 'node:url'
|
|
29
29
|
|
|
@@ -49,28 +49,7 @@ function isPeak(at) {
|
|
|
49
49
|
// 官方价目是 USD/1M,故按汇率换算后与面板核对;汇率可被 FG_USD_CNY 覆盖(默认 7.1)。
|
|
50
50
|
const USD_CNY = Number(process.env.FG_USD_CNY || 7.1)
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
let entries = []
|
|
54
|
-
try {
|
|
55
|
-
entries = readdirSync(dir)
|
|
56
|
-
} catch {
|
|
57
|
-
return out
|
|
58
|
-
}
|
|
59
|
-
for (const e of entries) {
|
|
60
|
-
const p = join(dir, e)
|
|
61
|
-
let st
|
|
62
|
-
try {
|
|
63
|
-
st = statSync(p)
|
|
64
|
-
} catch {
|
|
65
|
-
continue
|
|
66
|
-
}
|
|
67
|
-
if (st.isDirectory()) walk(p, out)
|
|
68
|
-
else if (e === 'session.v4.jsonl.zstd') out.push(p)
|
|
69
|
-
}
|
|
70
|
-
return out
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const FILES = walk(SESSIONS)
|
|
52
|
+
const FILES = walkSessionFiles(SESSIONS).map((x) => x.f)
|
|
74
53
|
|
|
75
54
|
/** 从会话记录取结构指标:steps / denies / 工具调用 / 时长。 */
|
|
76
55
|
function structureOf(sidPrefix) {
|
package/tools/dead-export.mjs
CHANGED
|
@@ -3,30 +3,15 @@
|
|
|
3
3
|
* 死导出检查(2026-10-25):找出"导出了但没人调用"的符号——模块活着、功能没接上的典型形态。
|
|
4
4
|
* 只读。排除:tests/ 内的引用不算使用者;同名不同文件的第二个实现会单独列出。
|
|
5
5
|
*/
|
|
6
|
-
import { readFileSync
|
|
6
|
+
import { readFileSync } from 'node:fs'
|
|
7
7
|
import { dirname, join, relative } from 'node:path'
|
|
8
8
|
import { fileURLToPath } from 'node:url'
|
|
9
|
+
import { walk } from './lib/import-graph.mjs'
|
|
9
10
|
|
|
10
11
|
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
11
12
|
const CORE = join(HERE, '..')
|
|
12
13
|
const ROOTS = ['src', 'hooks', 'tools']
|
|
13
14
|
|
|
14
|
-
function walk(dir, out = []) {
|
|
15
|
-
let entries = []
|
|
16
|
-
try {
|
|
17
|
-
entries = readdirSync(dir)
|
|
18
|
-
} catch {
|
|
19
|
-
return out
|
|
20
|
-
}
|
|
21
|
-
for (const e of entries) {
|
|
22
|
-
const p = join(dir, e)
|
|
23
|
-
const st = statSync(p)
|
|
24
|
-
if (st.isDirectory()) walk(p, out)
|
|
25
|
-
else if (/\.(mjs|js)$/.test(e)) out.push(p)
|
|
26
|
-
}
|
|
27
|
-
return out
|
|
28
|
-
}
|
|
29
|
-
|
|
30
15
|
const files = ROOTS.flatMap((r) => walk(join(CORE, r)))
|
|
31
16
|
const sources = new Map()
|
|
32
17
|
for (const f of files) sources.set(f, readFileSync(f, 'utf8'))
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 全仓文档书(tools/docs-book.mjs,2026-11-19)
|
|
4
|
+
*
|
|
5
|
+
* 把 `listMarkdownFiles` 认到的每一份 `.md` 编成**一本单文件 HTML**:
|
|
6
|
+
* 左侧按状态分组(权威 / 参考 / 台账 / 归档),右侧连续阅读,带搜索与阅读进度。
|
|
7
|
+
*
|
|
8
|
+
* ## 为什么是单文件
|
|
9
|
+
*
|
|
10
|
+
* 双击就开,不起服务器。`file://` 下 `fetch` 本地文件会被 CORS 拦,
|
|
11
|
+
* 所以 40 份正文必须**内嵌**进 HTML——这也是 `library-book.mjs` 早就定下的同一取舍。
|
|
12
|
+
*
|
|
13
|
+
* ## 与 `library-book.mjs` 的分工
|
|
14
|
+
*
|
|
15
|
+
* - `library-book`:读 `.ai/output/library` 的**卡片**,给私有研读资料成书(卡片体例 `.h/.act/.ref`)。
|
|
16
|
+
* - 本脚本:读**仓库里的文档**,按状态分组,给「这份文档落后多少」一个可翻阅的视图。
|
|
17
|
+
* - 渲染器**共用** `lib/markdown.mjs`,版式**共用** `lib/book-style.mjs`。
|
|
18
|
+
* 两个入口、一套实现——不共用的话,两本书对同一段 markdown 会给出不同结果。
|
|
19
|
+
*
|
|
20
|
+
* ## 数据从哪来
|
|
21
|
+
*
|
|
22
|
+
* 状态、适用版本、最后核对一律走 `collectDocStatus`,与 `docs/STATUS.md` **同一份真值**。
|
|
23
|
+
* 本书不另算落后档数:两处各算一遍,迟早算出两个数。
|
|
24
|
+
*
|
|
25
|
+
* 用法:
|
|
26
|
+
* node packages/core/tools/docs-book.mjs # 写 docs/book.html
|
|
27
|
+
* node packages/core/tools/docs-book.mjs --out <file>
|
|
28
|
+
* node packages/core/tools/docs-book.mjs --label 我的书
|
|
29
|
+
*/
|
|
30
|
+
import { readFileSync, writeFileSync } from 'node:fs'
|
|
31
|
+
import { dirname, join, relative, resolve } from 'node:path'
|
|
32
|
+
import { fileURLToPath } from 'node:url'
|
|
33
|
+
import { listMarkdownFiles } from './lib/docs-core.mjs'
|
|
34
|
+
import { collectDocStatus, parseStatusHeader } from './lib/docs-status.mjs'
|
|
35
|
+
import { mdToHtml } from './lib/markdown.mjs'
|
|
36
|
+
import { BOOK_CSS } from './lib/book-style.mjs'
|
|
37
|
+
|
|
38
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
39
|
+
const ROOT = resolve(HERE, '..', '..', '..')
|
|
40
|
+
const argv = process.argv.slice(2)
|
|
41
|
+
const arg = (k, d) => (argv.includes(k) ? argv[argv.indexOf(k) + 1] : d)
|
|
42
|
+
const OUT = resolve(ROOT, arg('--out', 'docs/book.html'))
|
|
43
|
+
const LABEL = arg('--label', 'Focus Guard 文档全集')
|
|
44
|
+
|
|
45
|
+
const { current, rows } = collectDocStatus(ROOT)
|
|
46
|
+
const byRel = new Map(rows.map((r) => [r.rel, r]))
|
|
47
|
+
|
|
48
|
+
/** 去掉首个 H1 与紧随其后的状态块:标题与版本已经在文章头上,正文里再来一遍是重复。 */
|
|
49
|
+
function stripHead(text) {
|
|
50
|
+
const lines = text.split('\n')
|
|
51
|
+
let i = 0
|
|
52
|
+
while (i < lines.length && !lines[i].startsWith('# ')) i += 1
|
|
53
|
+
if (i < lines.length) i += 1
|
|
54
|
+
while (i < lines.length && !lines[i].trim()) i += 1
|
|
55
|
+
return lines.slice(i).join('\n')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const GROUP_ORDER = ['权威', '参考', '台账', '归档', '未标']
|
|
59
|
+
|
|
60
|
+
const docs = listMarkdownFiles(ROOT)
|
|
61
|
+
.map((file) => {
|
|
62
|
+
const rel = relative(ROOT, file).split('\\').join('/')
|
|
63
|
+
const text = readFileSync(file, 'utf8')
|
|
64
|
+
// `collectDocStatus` 有意把 `docs/STATUS.md` 自己排除(自引用会让总表行数漂移),
|
|
65
|
+
// 但书里要收它,所以这里单独读一次它自己的状态头,而不是让它显示成「未标」。
|
|
66
|
+
const meta = byRel.get(rel) || parseStatusHeader(text) || {}
|
|
67
|
+
const title = (text.split('\n').find((l) => l.startsWith('# ')) || '').replace(/^#\s*/, '').trim() || rel
|
|
68
|
+
return {
|
|
69
|
+
id: rel,
|
|
70
|
+
title,
|
|
71
|
+
group: meta.status || '未标',
|
|
72
|
+
version: meta.version || '—',
|
|
73
|
+
date: meta.date || '—',
|
|
74
|
+
behind: meta.status === '权威' && typeof meta.behind === 'number' && meta.behind > 0 ? meta.behind : 0,
|
|
75
|
+
chars: text.length,
|
|
76
|
+
html: mdToHtml(stripHead(text), { hShift: 0, cardClasses: false }),
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
.sort((a, b) => {
|
|
80
|
+
const ga = GROUP_ORDER.indexOf(a.group)
|
|
81
|
+
const gb = GROUP_ORDER.indexOf(b.group)
|
|
82
|
+
if (ga !== gb) return (ga < 0 ? 9 : ga) - (gb < 0 ? 9 : gb)
|
|
83
|
+
return a.id.localeCompare(b.id)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const groups = []
|
|
87
|
+
for (const d of docs) {
|
|
88
|
+
const last = groups[groups.length - 1]
|
|
89
|
+
if (last && last.name === d.group) last.docs.push(d)
|
|
90
|
+
else groups.push({ name: d.group, docs: [d] })
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const totalChars = docs.reduce((a, d) => a + d.chars, 0)
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 文档书比资料书多出的排版。
|
|
97
|
+
*
|
|
98
|
+
* `BOOK_CSS` 只定义了 `.body h3` / `.body h4`——那是按资料书的卡片层级写的
|
|
99
|
+
* (卡片里最高只到 `###`)。文档的 `##` 会渲染成 `<h2>`,落在这里就没有样式,
|
|
100
|
+
* 退回浏览器默认的 1.5em 粗体,和正文打架。表格与代码块同理:资料书里一个都没有。
|
|
101
|
+
* 所以这一段是**补缺**,不是覆盖:BOOK_CSS 里有的(行宽、纸色、衬线)一概不动。
|
|
102
|
+
*/
|
|
103
|
+
const DOCS_CSS = `
|
|
104
|
+
.body h1{font-size:1.42em;line-height:1.3;margin:1.6em 0 .6em}
|
|
105
|
+
.body h2{font-size:1.2em;line-height:1.35;margin:1.7em 0 .5em;padding-bottom:.28em;border-bottom:1px solid var(--line)}
|
|
106
|
+
.body h3{font-size:1.04em;margin:1.3em 0 .4em}
|
|
107
|
+
.body h4{font-size:1em;margin:1.1em 0 .3em}
|
|
108
|
+
.body table{width:100%;border-collapse:collapse;margin:1em 0;font-size:.9em}
|
|
109
|
+
.body th,.body td{border:1px solid var(--line);padding:.42em .6em;text-align:left;vertical-align:top}
|
|
110
|
+
.body th{background:var(--soft);font-weight:600;white-space:nowrap}
|
|
111
|
+
.body pre{background:var(--panel);border:1px solid var(--line);border-radius:6px;padding:.8em 1em;overflow:auto;font-size:.84em;line-height:1.55}
|
|
112
|
+
.body code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.9em}
|
|
113
|
+
.body :not(pre)>code{background:var(--soft);padding:.1em .34em;border-radius:4px;word-break:break-word}
|
|
114
|
+
.body a{color:var(--accent);text-decoration:none;border-bottom:1px solid var(--soft)}
|
|
115
|
+
.body a:hover{border-bottom-color:var(--accent)}
|
|
116
|
+
.body blockquote{border-left:3px solid var(--soft);margin:1em 0;padding:.1em 0 .1em 1em;color:var(--ink2)}
|
|
117
|
+
.body blockquote p{margin:.35em 0}
|
|
118
|
+
.body hr{border:0;border-top:1px solid var(--line);margin:2em 0}
|
|
119
|
+
.body img{max-width:100%}
|
|
120
|
+
.body details>summary{cursor:pointer;color:var(--dim);margin:.6em 0}
|
|
121
|
+
`
|
|
122
|
+
|
|
123
|
+
const HTML = `<!DOCTYPE html>
|
|
124
|
+
<html lang="zh-CN">
|
|
125
|
+
<head>
|
|
126
|
+
<meta charset="utf-8">
|
|
127
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
128
|
+
<title>${LABEL}</title>
|
|
129
|
+
<style>${BOOK_CSS}${DOCS_CSS}</style>
|
|
130
|
+
</head>
|
|
131
|
+
<body>
|
|
132
|
+
<aside>
|
|
133
|
+
<div class="brand">
|
|
134
|
+
<div class="kicker">Documents</div>
|
|
135
|
+
<h1>${LABEL}</h1>
|
|
136
|
+
<div class="meta">${docs.length} 份 · ${(totalChars / 10000).toFixed(1)} 万字 · 版本 ${current}</div>
|
|
137
|
+
</div>
|
|
138
|
+
<div class="search"><input id="q" placeholder="搜索文档名或路径" autocomplete="off"></div>
|
|
139
|
+
<nav id="tree"></nav>
|
|
140
|
+
<div class="aside-foot">权威在前,落后的在前<br>滚轮连续读 · 点目录跳章</div>
|
|
141
|
+
</aside>
|
|
142
|
+
<main><div id="bar"><i></i></div><div class="wrap" id="book"></div></main>
|
|
143
|
+
<script>
|
|
144
|
+
const DATA = ${JSON.stringify(groups).replace(/</g, '\\u003c')};
|
|
145
|
+
const esc = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' })[c]);
|
|
146
|
+
const tree = document.getElementById('tree');
|
|
147
|
+
const book = document.getElementById('book');
|
|
148
|
+
const TOTAL = DATA.reduce((a, g) => a + g.docs.length, 0);
|
|
149
|
+
const LONG = 20000;
|
|
150
|
+
let n = 0;
|
|
151
|
+
for (const g of DATA) {
|
|
152
|
+
const h = document.createElement('div');
|
|
153
|
+
h.className = 'grp';
|
|
154
|
+
h.textContent = g.name + ' · ' + g.docs.length;
|
|
155
|
+
tree.appendChild(h);
|
|
156
|
+
for (const d of g.docs) {
|
|
157
|
+
n += 1;
|
|
158
|
+
const a = document.createElement('a');
|
|
159
|
+
a.className = 'item';
|
|
160
|
+
a.dataset.id = d.id;
|
|
161
|
+
a.dataset.title = (d.title + ' ' + d.id).toLowerCase();
|
|
162
|
+
a.innerHTML = '<span class="n">' + String(n).padStart(2, '0') + '</span><span class="t">' + esc(d.title) + '</span>';
|
|
163
|
+
// getElementById 按字面匹配,不要用 CSS.escape:它会把点和斜杠转义,
|
|
164
|
+
// 拼出来的字符串与真实 id 不同,跳转会静默失效(2026-11-19 初版踩过)。
|
|
165
|
+
a.onclick = () => document.getElementById('blk-' + d.id).scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
166
|
+
tree.appendChild(a);
|
|
167
|
+
|
|
168
|
+
const art = document.createElement('article');
|
|
169
|
+
art.id = 'blk-' + d.id;
|
|
170
|
+
art.innerHTML =
|
|
171
|
+
'<header class="ch">' +
|
|
172
|
+
'<div class="no">' + String(n).padStart(2, '0') + ' / ' + String(TOTAL).padStart(2, '0') + '</div>' +
|
|
173
|
+
'<h2>' + esc(d.title) + '</h2>' +
|
|
174
|
+
'<div class="src">' + esc(d.id) + ' · ' + esc(d.version) + ' · 核对 ' + esc(d.date) +
|
|
175
|
+
(d.behind ? ' · <b>落后 ' + d.behind + ' 档</b>' : '') +
|
|
176
|
+
' · ' + d.chars + ' 字</div>' +
|
|
177
|
+
'</header>' +
|
|
178
|
+
'<div class="body">' +
|
|
179
|
+
(d.chars > LONG ? '<details><summary>' + d.chars + ' 字,点开</summary>' + d.html + '</details>' : d.html) +
|
|
180
|
+
'</div>';
|
|
181
|
+
book.appendChild(art);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 搜索:只过滤目录项,不动正文——正文一次性全渲染,按需滚动。
|
|
186
|
+
const q = document.getElementById('q');
|
|
187
|
+
q.addEventListener('input', () => {
|
|
188
|
+
const k = q.value.trim().toLowerCase();
|
|
189
|
+
for (const a of document.querySelectorAll('.item')) {
|
|
190
|
+
a.style.display = !k || a.dataset.title.includes(k) ? '' : 'none';
|
|
191
|
+
}
|
|
192
|
+
for (const g of document.querySelectorAll('.grp')) {
|
|
193
|
+
let el = g.nextElementSibling;
|
|
194
|
+
let any = false;
|
|
195
|
+
while (el && el.classList.contains('item')) {
|
|
196
|
+
if (el.style.display !== 'none') any = true;
|
|
197
|
+
el = el.nextElementSibling;
|
|
198
|
+
}
|
|
199
|
+
g.style.display = any ? '' : 'none';
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// 阅读进度:细线贴顶,只在 main 里滚时变。
|
|
204
|
+
const mainEl = document.querySelector('main');
|
|
205
|
+
const barEl = document.querySelector('#bar i');
|
|
206
|
+
const paint = () => {
|
|
207
|
+
const max = mainEl.scrollHeight - mainEl.clientHeight;
|
|
208
|
+
barEl.style.width = (max > 0 ? (mainEl.scrollTop / max) * 100 : 0) + '%';
|
|
209
|
+
};
|
|
210
|
+
mainEl.addEventListener('scroll', paint, { passive: true });
|
|
211
|
+
window.addEventListener('resize', paint);
|
|
212
|
+
paint();
|
|
213
|
+
|
|
214
|
+
// 目录高亮:IntersectionObserver 比 scroll 事件省。
|
|
215
|
+
const links = new Map([...document.querySelectorAll('.item')].map((a) => [a.dataset.id, a]));
|
|
216
|
+
const io = new IntersectionObserver((entries) => {
|
|
217
|
+
for (const e of entries) {
|
|
218
|
+
if (!e.isIntersecting) continue;
|
|
219
|
+
const id = e.target.id.replace(/^blk-/, '');
|
|
220
|
+
for (const a of links.values()) a.classList.remove('on');
|
|
221
|
+
const a = links.get(id);
|
|
222
|
+
if (a) a.classList.add('on');
|
|
223
|
+
}
|
|
224
|
+
}, { rootMargin: '0px 0px -70% 0px' });
|
|
225
|
+
for (const art of document.querySelectorAll('article')) io.observe(art);
|
|
226
|
+
</script>
|
|
227
|
+
</body>
|
|
228
|
+
</html>
|
|
229
|
+
`
|
|
230
|
+
|
|
231
|
+
writeFileSync(OUT, HTML)
|
|
232
|
+
process.stdout.write(
|
|
233
|
+
`[docs-book] ${relative(ROOT, OUT).split('\\').join('/')}:${docs.length} 份 / ${groups.length} 组 / ${(HTML.length / 1024).toFixed(0)} KB\n`,
|
|
234
|
+
)
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* docs:drift(2026-11-22)
|
|
4
|
+
*
|
|
5
|
+
* 文档漂移扫描器:把「文档里写死的事实」拿代码对一遍,出清单而不是靠人眼。
|
|
6
|
+
* 三类判据(都只认可机器验证的):
|
|
7
|
+
* 1. `npm run <script>`:package.json 的 scripts 里必须存在;
|
|
8
|
+
* 2. 反引号里的仓库相对路径:文件/目录必须存在(占位符与通配符跳过);
|
|
9
|
+
* 3. `FG_*` 环境变量:`packages/core/src` 里必须出现过。
|
|
10
|
+
*
|
|
11
|
+
* 不判:示例里的外部 URL、<占位符>、执行结果、版本号(版本面已由 docs:lint / version.mjs 管)。
|
|
12
|
+
*
|
|
13
|
+
* 用法:
|
|
14
|
+
* node packages/core/tools/docs-drift.mjs # 人读清单
|
|
15
|
+
* node packages/core/tools/docs-drift.mjs --json # 机器读
|
|
16
|
+
* node packages/core/tools/docs-drift.mjs --strict # 有漂移则退出码 1(默认 0,只报告)
|
|
17
|
+
*/
|
|
18
|
+
import { readFileSync, existsSync, statSync, readdirSync } from 'node:fs'
|
|
19
|
+
import { dirname, join, resolve, relative } from 'node:path'
|
|
20
|
+
|
|
21
|
+
import { ROOT, docScope } from './lib/docs-scope.mjs'
|
|
22
|
+
|
|
23
|
+
const args = process.argv.slice(2)
|
|
24
|
+
const asJson = args.includes('--json')
|
|
25
|
+
const strict = args.includes('--strict')
|
|
26
|
+
|
|
27
|
+
// 扫描范围与 docs:refs 共用一份清单,别在这里另抄——抄两份必然分叉(`lib/docs-scope.mjs`)。
|
|
28
|
+
const FILES = docScope()
|
|
29
|
+
|
|
30
|
+
const scripts = Object.keys(JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).scripts || {})
|
|
31
|
+
|
|
32
|
+
/** FG_* 变量名集合:从 src 全量收集(只读,不猜)。 */
|
|
33
|
+
function collectEnvNames() {
|
|
34
|
+
const names = new Set()
|
|
35
|
+
const walk = (dir) => {
|
|
36
|
+
let entries
|
|
37
|
+
try {
|
|
38
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
39
|
+
} catch {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
for (const e of entries) {
|
|
43
|
+
if (e.name === 'node_modules') continue
|
|
44
|
+
const p = join(dir, e.name)
|
|
45
|
+
if (e.isDirectory()) walk(p)
|
|
46
|
+
else if (/\.(mjs|js)$/.test(e.name)) {
|
|
47
|
+
const text = readFileSync(p, 'utf8')
|
|
48
|
+
for (const m of text.matchAll(/\bFG_[A-Z0-9_]+\b/g)) names.add(m[0])
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
walk(join(ROOT, 'packages/core'))
|
|
53
|
+
return names
|
|
54
|
+
}
|
|
55
|
+
const ENV_NAMES = collectEnvNames()
|
|
56
|
+
|
|
57
|
+
const SKIP_PATH = /\s|<|>|\*|\?|\{|\}|\.\.\.|…|^https?:|^file:|^[A-Za-z]:|^~|^\$|^%|^you$|^\.\.$/
|
|
58
|
+
|
|
59
|
+
/** 运行期产物目录:文档里写它们只在说「会生成到哪」,不该被要求当前就存在。 */
|
|
60
|
+
const RUNTIME_PREFIX = /^(?:\.focus-guard|\.ai|\.stryker-tmp|reports|\.dsh|library|notes|output|archive)\//
|
|
61
|
+
|
|
62
|
+
/** 只认本仓自己的目录前缀;`memory-core/`、`plugins/` 这类是外部项目引用,不归本仓查。 */
|
|
63
|
+
const REPO_PREFIX = /^(?:packages|docs|\.ai|\.githooks|\.github|\.claude-plugin|\.zcode-plugin|src|tests|tools|hooks|skills|presets|assets|scripts)\//
|
|
64
|
+
const PATHISH = /^(?:packages|docs|\.ai|\.githooks|\.github|\.claude-plugin|\.zcode-plugin)\//
|
|
65
|
+
const EXT = /\.(?:md|mjs|js|json|yml|yaml|html|css|txt|sh|ps1|bat)$/
|
|
66
|
+
|
|
67
|
+
const rows = []
|
|
68
|
+
function report(file, line, rule, snippet, detail) {
|
|
69
|
+
rows.push({ file: relative(ROOT, file).replace(/\\/g, '/'), line, rule, snippet, detail })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function checkScript(file, line, name) {
|
|
73
|
+
const head = name.split(/\s+/)[0]
|
|
74
|
+
if (!head || head.startsWith('-')) return
|
|
75
|
+
if (scripts.includes(head)) return
|
|
76
|
+
report(file, line, 'npm-script', `npm run ${head}`, `package.json scripts 里没有 ${head}`)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function checkPath(file, line, token, lineText = '') {
|
|
80
|
+
const t = token.trim()
|
|
81
|
+
if (!t || SKIP_PATH.test(t)) return
|
|
82
|
+
const bare = t.replace(/[.,;:))】]+$/, '').replace(/^['"]|['"]$/g, '')
|
|
83
|
+
if (!REPO_PREFIX.test(bare) && !PATHISH.test(bare)) return
|
|
84
|
+
if (RUNTIME_PREFIX.test(bare)) return
|
|
85
|
+
if (!EXT.test(bare) && !bare.endsWith('/')) return
|
|
86
|
+
if (bare.includes('*')) return
|
|
87
|
+
// 文档里的路径有三种写法,逐一试:仓库根相对、文档同目录相对、包内相对(packages/core/…)。
|
|
88
|
+
const candidates = [
|
|
89
|
+
join(ROOT, bare),
|
|
90
|
+
resolve(dirname(file), bare),
|
|
91
|
+
resolve(dirname(file), '..', bare),
|
|
92
|
+
join(ROOT, 'packages/core', bare),
|
|
93
|
+
join(ROOT, 'packages/core/src', bare),
|
|
94
|
+
join(ROOT, 'packages/core/src/dsh', bare),
|
|
95
|
+
]
|
|
96
|
+
for (const c of candidates) {
|
|
97
|
+
try {
|
|
98
|
+
if (existsSync(c) && statSync(c)) return
|
|
99
|
+
} catch {
|
|
100
|
+
/* keep trying */
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// 计划/设计类段落里的路径是「将来要建」,不是当前事实;只报告已建成文档里的死路径。
|
|
104
|
+
// `待建` 于 2026-11-26 加入:`VERSION-PLAN` 的落点表要写「这条任务要新建哪个文件」,
|
|
105
|
+
// 那类路径按定义还不存在。只收这一个词,不收「新增」——后者在既成事实的叙述里太常见
|
|
106
|
+
// (「新增 X 工具」),加进去等于把闸门关掉一半。
|
|
107
|
+
if (/计划|待做|未做|目标|将|拟|设计|待建/.test(lineText)) return
|
|
108
|
+
report(file, line, 'repo-path', bare, '文件或目录不存在')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function checkEnv(file, line, name) {
|
|
112
|
+
if (ENV_NAMES.has(name)) return
|
|
113
|
+
report(file, line, 'fg-env', name, 'packages/core/src 里没有这个环境变量')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const file of FILES) {
|
|
117
|
+
const lines = readFileSync(file, 'utf8').split('\n')
|
|
118
|
+
lines.forEach((text, i) => {
|
|
119
|
+
const line = i + 1
|
|
120
|
+
for (const m of text.matchAll(/npm run ([A-Za-z0-9:_-]+)/g)) checkScript(file, line, m[1])
|
|
121
|
+
for (const m of text.matchAll(/\bFG_[A-Z0-9_]+\b/g)) checkEnv(file, line, m[0])
|
|
122
|
+
// 只查反引号包裹的路径;代码块里没有反引号,靠行内格式,避免把命令参数当路径。
|
|
123
|
+
for (const m of text.matchAll(/`([^`\n]+)`/g)) checkPath(file, line, m[1], text)
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
rows.sort((a, b) => (a.file === b.file ? a.line - b.line : a.file < b.file ? -1 : 1))
|
|
128
|
+
|
|
129
|
+
if (asJson) {
|
|
130
|
+
console.log(JSON.stringify({ scanned: FILES.length, issues: rows.length, rows }, null, 2))
|
|
131
|
+
} else {
|
|
132
|
+
console.log(`[docs:drift] 扫描 ${FILES.length} 份文档 → 漂移 ${rows.length} 条`)
|
|
133
|
+
let last = ''
|
|
134
|
+
for (const r of rows) {
|
|
135
|
+
if (r.file !== last) {
|
|
136
|
+
console.log(`\n${r.file}`)
|
|
137
|
+
last = r.file
|
|
138
|
+
}
|
|
139
|
+
console.log(` :${r.line} [${r.rule}] ${r.snippet} — ${r.detail}`)
|
|
140
|
+
}
|
|
141
|
+
if (!rows.length) console.log(' 无漂移。')
|
|
142
|
+
}
|
|
143
|
+
process.exit(strict && rows.length ? 1 : 0)
|
package/tools/docs-lint.mjs
CHANGED
|
@@ -4,18 +4,25 @@
|
|
|
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
|
|
10
|
+
* node packages/core/tools/docs-lint.mjs --sync-status # 重新生成 docs/STATUS.md
|
|
9
11
|
*
|
|
10
12
|
* 闸门是棘轮:`BUDGET` 记当前存量(初始 0),只许降不许升。
|
|
11
13
|
* 这是 3.5「文档重置完成」的前置尺子(D5);README 硬指标、数字单点、状态头分别归 D1/D4/D2。
|
|
14
|
+
*
|
|
15
|
+
* 报点:一律 `文件:行号`(见 `lib/where.mjs`)。行号找不到时只给文件名,
|
|
16
|
+
* **不拿第 1 行顶替**——假行号会让人跳到文件开头再自己找,比没有行号更费时。
|
|
12
17
|
*/
|
|
13
|
-
import {
|
|
18
|
+
import { writeFileSync } from 'node:fs'
|
|
19
|
+
import { join } from 'node:path'
|
|
14
20
|
import {
|
|
15
21
|
listMarkdownFiles,
|
|
16
22
|
checkVersionFace,
|
|
17
23
|
checkRelativeLinks,
|
|
18
24
|
checkCodePathRefs,
|
|
25
|
+
checkScriptRefs,
|
|
19
26
|
checkStatusHeaders,
|
|
20
27
|
checkIndexCoverage,
|
|
21
28
|
allDocFiles,
|
|
@@ -23,14 +30,24 @@ import {
|
|
|
23
30
|
checkCitationStyle,
|
|
24
31
|
} from './lib/docs-core.mjs'
|
|
25
32
|
import { checkVersionClaims, checkReadmeVersionFace } from './lib/docs-version.mjs'
|
|
33
|
+
import { checkAckFreshness } from './lib/docs-ack.mjs'
|
|
34
|
+
import { checkDocTypography } from './lib/docs-typography.mjs'
|
|
35
|
+
import { STATUS_DOC, collectDocStatus, renderStatusTable, checkStatusTable } from './lib/docs-status.mjs'
|
|
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'
|
|
26
39
|
|
|
27
|
-
const ROOT =
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const STRICT =
|
|
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')
|
|
32
46
|
const BUDGET = 0
|
|
33
47
|
|
|
48
|
+
/** brief 超限时逐条列出的上限:够看出"该怎么改",又不至于把 CI 日志淹掉。 */
|
|
49
|
+
const BRIEF_SHOW = 8
|
|
50
|
+
|
|
34
51
|
/**
|
|
35
52
|
* 按规则的存量豁免(3.3 A)。
|
|
36
53
|
*
|
|
@@ -38,19 +55,43 @@ const BUDGET = 0
|
|
|
38
55
|
* 2026-11-07 历史段(≤3.0.7)原样移入 `docs/archive/`(不在扫描面内),存量归零,额度一并收回。
|
|
39
56
|
* 判据:豁免是**存量**的记账。存量没了还留着额度,等于给未来的死链预留藏身处。
|
|
40
57
|
*/
|
|
41
|
-
const RULE_BUDGET = {
|
|
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
|
+
}
|
|
42
66
|
|
|
43
67
|
const files = listMarkdownFiles(ROOT)
|
|
68
|
+
|
|
69
|
+
// `--sync-status` 只做生成,不跑判据:生成器不该顺便当闸门,否则"红着生成"会把人搞糊涂。
|
|
70
|
+
if (SYNC_STATUS) {
|
|
71
|
+
const data = collectDocStatus(ROOT, files)
|
|
72
|
+
writeFileSync(join(ROOT, STATUS_DOC), renderStatusTable(data))
|
|
73
|
+
console.log(`已生成 ${STATUS_DOC}:${data.rows.length} 份文档,当前版本 ${data.current}。`)
|
|
74
|
+
process.exit(0)
|
|
75
|
+
}
|
|
76
|
+
|
|
44
77
|
const findings = [
|
|
45
78
|
...checkVersionFace(ROOT),
|
|
46
79
|
...checkRelativeLinks(ROOT, files),
|
|
47
80
|
...checkCodePathRefs(ROOT, files),
|
|
81
|
+
...checkScriptRefs(ROOT, files),
|
|
48
82
|
...checkStatusHeaders(ROOT),
|
|
49
83
|
...checkIndexCoverage(ROOT, allDocFiles(ROOT)),
|
|
84
|
+
...checkStatusTable(ROOT, files),
|
|
85
|
+
...checkModulePaths(ROOT),
|
|
86
|
+
...checkModuleIds(ROOT),
|
|
87
|
+
...checkModuleOverlap(ROOT),
|
|
88
|
+
...checkModuleCoverage(ROOT),
|
|
50
89
|
...checkReadmeMetrics(ROOT),
|
|
51
90
|
...checkCitationStyle(ROOT),
|
|
91
|
+
...checkDocTypography(ROOT, files),
|
|
52
92
|
...checkVersionClaims(ROOT),
|
|
53
93
|
...checkReadmeVersionFace(ROOT),
|
|
94
|
+
...checkAckFreshness(ROOT, files),
|
|
54
95
|
]
|
|
55
96
|
const byRule = {}
|
|
56
97
|
for (const f of findings) byRule[f.rule] = (byRule[f.rule] || 0) + 1
|
|
@@ -60,20 +101,46 @@ const over = Object.entries(byRule).reduce(
|
|
|
60
101
|
0,
|
|
61
102
|
)
|
|
62
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
|
+
|
|
63
127
|
if (AS_JSON) {
|
|
64
128
|
console.log(JSON.stringify({ files: files.length, findings, byRule, budget: BUDGET, ruleBudget: RULE_BUDGET, over }, null, 2))
|
|
65
129
|
} else if (BRIEF) {
|
|
66
130
|
const parts = Object.entries(byRule)
|
|
67
131
|
.sort((a, b) => b[1] - a[1])
|
|
68
132
|
.map(([r, n]) => `${r} ${n}${RULE_BUDGET[r] ? `(豁免${RULE_BUDGET[r]})` : ''}`)
|
|
69
|
-
|
|
133
|
+
// 红的那一行要报**实际超出多少条**。写 `超上限 ${BUDGET}` 在 BUDGET=0 时输出「超上限 0」,
|
|
134
|
+
// 读起来是「超了 0 条」,与前面的 ❌ 自相矛盾——报点的数字一旦对不上,人连红绿都不信了。
|
|
135
|
+
const gate = over > BUDGET ? `❌ 超限 ${over} 条 / 上限 ${BUDGET}` : `✅ 上限 ${BUDGET}`
|
|
70
136
|
console.log(`文档口径:${files.length} 个 md,问题 ${findings.length} 条${parts.length ? `(${parts.join(' / ')})` : ''};${gate}`)
|
|
137
|
+
if (over > BUDGET) console.log(offenders().join('\n'))
|
|
71
138
|
} else {
|
|
72
139
|
console.log(`文档口径:${files.length} 个 md,问题 ${findings.length} 条\n`)
|
|
73
140
|
if (!findings.length) console.log('无问题(版本面一致 / 相对链接全部可达 / 行内路径全部可达)。')
|
|
74
141
|
for (const f of findings) {
|
|
75
142
|
const allow = RULE_BUDGET[f.rule] ? '(存量豁免)' : ''
|
|
76
|
-
console.log(`${f
|
|
143
|
+
console.log(`${renderFinding(f, { root: ROOT, withSource: WHERE })}${allow}`)
|
|
77
144
|
}
|
|
78
145
|
console.log(`\n闸门口径:超限 ${over} 条 / 上限 ${BUDGET}(棘轮,只许降不许升)。`)
|
|
79
146
|
for (const [rule, n] of Object.entries(RULE_BUDGET)) {
|