dsh-trajectory-traceview-plus 0.10.0 → 0.11.0

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.
@@ -8,11 +8,11 @@
8
8
 
9
9
  ## 一、文件级
10
10
 
11
- 上游共 10 个文件,其中 4 个一字未改:
11
+ 上游共 10 个文件,其中 2 个一字未改:
12
12
 
13
13
  | 文件 | 状态 |
14
14
  | --- | --- |
15
- | `.gitignore` | 原样保留 |
15
+ | `.gitignore` | 已修改 |
16
16
  | `LICENSE` | 原样保留 |
17
17
  | `README.en.md` | 已修改 |
18
18
  | `README.md` | 已修改 |
@@ -20,19 +20,26 @@
20
20
  | `lib/client.js` | 已修改 |
21
21
  | `lib/index.js` | 原样保留 |
22
22
  | `package.json` | 已修改 |
23
- | `screenshot/overview.jpg` | 原样保留 |
23
+ | `screenshot/overview.jpg` | 已改名 → `screenshot/overview.png` |
24
24
  | `test/smoke.test.cjs` | 已修改 |
25
25
 
26
26
  本仓新增的文件:
27
27
 
28
+ - `.github/workflows/check.yml`
28
29
  - `CHANGELOG.md`
29
30
  - `docs/DESIGN.md`
30
31
  - `docs/PROVENANCE.md`
32
+ - `package-lock.json`
31
33
  - `scripts/bench-fold.mjs`
32
34
  - `scripts/browser-check.mjs`
33
35
  - `scripts/browser-harness.mjs`
34
36
  - `scripts/build-client.mjs`
37
+ - `scripts/doc-heading-check.mjs`
38
+ - `scripts/doc-ref-check.mjs`
35
39
  - `scripts/provenance.mjs`
40
+ - `scripts/readme-numbers.mjs`
41
+ - `scripts/release-status.mjs`
42
+ - `scripts/version-check.mjs`
36
43
  - `src/00-locale.js`
37
44
  - `src/10-styles.js`
38
45
  - `src/20-fields.js`
@@ -40,19 +47,7 @@
40
47
  - `src/40-view.js`
41
48
  - `src/50-entry.js`
42
49
  - `test/browser/fixture.js`
43
- - `test/browser/harness.html`
44
50
  - `test/browser/probe.js`
45
- - `test/browser/shots/screenshot-1795154191788.png`
46
- - `test/browser/shots/screenshot-1795155420814.png`
47
- - `test/browser/shots/screenshot-1795155624093.png`
48
- - `test/browser/shots/screenshot-1795155625388.png`
49
- - `test/browser/shots/screenshot-1795155846462.png`
50
- - `test/browser/shots/screenshot-1795155847319.png`
51
- - `test/browser/shots/screenshot-1795155941576.png`
52
- - `test/browser/shots/screenshot-1795155942686.png`
53
- - `test/browser/shots/screenshot-1795156006157.png`
54
- - `test/browser/shots/screenshot-1795157356099.png`
55
- - `test/browser/shots/screenshot-1795157357144.png`
56
51
 
57
52
  ## 二、`lib/client.js` 函数级
58
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-trajectory-traceview-plus",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "轨迹视图增强版(Plus):在「轨迹」标签旁新增可回放的横向时间轴——minimap、窗口内检索(显式标注覆盖边界)、回放、轮次跳转、跟随模式、历史分页、步骤/子调用耗时与吞吐、时钟轴切换、稳定锚点复制与深链、孤立工具结果站点、提示词变更对比、原始请求分析与 Markdown 导出。基于 AFAP/dsh-trajectory-traceview (MIT) 改造。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -10,7 +10,7 @@
10
10
  "./package.json": "./package.json"
11
11
  },
12
12
  "engines": {
13
- "dsh": "=0.2.2-rc.2",
13
+ "dsh": ">=0.2.2-rc.2 <0.2.3-0",
14
14
  "node": ">=24.9.0"
15
15
  },
16
16
  "dsh": {
@@ -62,7 +62,8 @@
62
62
  },
63
63
  "scripts": {
64
64
  "build": "node scripts/build-client.mjs",
65
- "check": "node scripts/build-client.mjs --check && node test/smoke.test.cjs",
66
- "test": "node test/smoke.test.cjs"
65
+ "check": "node scripts/build-client.mjs --check && node scripts/provenance.mjs --check && node scripts/version-check.mjs && node scripts/doc-ref-check.mjs && node scripts/doc-heading-check.mjs && node test/smoke.test.cjs && node scripts/readme-numbers.mjs",
66
+ "test": "node test/smoke.test.cjs",
67
+ "prepublishOnly": "npm run check"
67
68
  }
68
69
  }
@@ -62,7 +62,12 @@ console.log("browser-check: stations=" + parsed.info.stations +
62
62
  " copied=" + parsed.info.copied +
63
63
  " replay=" + parsed.info.replay);
64
64
  if (parsed.failures.length === 0) {
65
- console.log("browser-check: PASS (" + Object.keys(parsed.info).length + " checks recorded)");
65
+ // This count is the number of observation groups in `info`, NOT the number of
66
+ // assertions — probe.js makes 47 of those. Reporting it as "checks" made the
67
+ // README claim "13 项行为" for a file with 47 assertions, which undersold the
68
+ // coverage by 3.5x. Say what it actually counts.
69
+ const groups = Object.keys(parsed.info).length;
70
+ console.log("browser-check: PASS (" + groups + " observation groups recorded, 0 failures)");
66
71
  process.exit(0);
67
72
  }
68
73
  console.log("browser-check: FAIL");
@@ -42,12 +42,28 @@ const MODULES = {
42
42
  * hand-written light values — good enough for layout, not for judging dark contrast.
43
43
  */
44
44
  function findHostThemeCss() {
45
- const npmRoot = process.env.DSH_THEME_CSS;
46
- const candidates = [
47
- npmRoot,
48
- "/Users/mison/.nvm/versions/node/v24.22.1/lib/node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai/dsh-client-ui-theme/src/styles/design-platform.css"
49
- ].filter(Boolean);
50
- for (const c of candidates) {
45
+ const candidates = [process.env.DSH_THEME_CSS];
46
+
47
+ // Derive it instead of hardcoding. The old version embedded one machine's absolute
48
+ // path, which silently fell back to hand-written colours everywhere else — so dark
49
+ // contrast was only ever judged on one developer's laptop, and a reader of this repo
50
+ // had no way to know the stylesheet was missing.
51
+ //
52
+ // Resolve `dsh` by walking PATH rather than shelling out to `which`: no shell, no
53
+ // quoting surprises, and it works the same on every platform.
54
+ const suffixes = process.platform === "win32" ? [".cmd", ".exe", ""] : [""];
55
+ for (const dir of (process.env.PATH ?? "").split(path.delimiter)) {
56
+ if (dir === "") continue;
57
+ for (const suffix of suffixes) {
58
+ let real;
59
+ try { real = fs.realpathSync(path.join(dir, "dsh" + suffix)); } catch { continue; }
60
+ // <prefix>/lib/node_modules/@deepseek-ai/dsh/lib/bin.js -> <prefix>/lib/node_modules
61
+ const modules = path.dirname(path.dirname(path.dirname(path.dirname(real))));
62
+ candidates.push(path.join(modules, "@deepseek-ai/dsh", "node_modules", "@deepseek-ai/dsh-client-ui-theme", "src", "styles", "design-platform.css"));
63
+ }
64
+ }
65
+
66
+ for (const c of candidates.filter(Boolean)) {
51
67
  try { if (fs.statSync(c).size > 0) return fs.readFileSync(c, "utf8"); } catch { /* next */ }
52
68
  }
53
69
  return null;
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Fail when `docs/DESIGN.md` contains heading-like lines that Markdown will not
4
+ * render as headings.
5
+ *
6
+ * CommonMark requires a space (or end of line) after the `#` run. `###13.25` is
7
+ * therefore **paragraph text**, not a heading — GitHub renders it as a literal
8
+ * `###13.25` paragraph. That is invisible while editing and only shows up when
9
+ * someone reads the document on GitHub and finds no section structure at all.
10
+ *
11
+ * This had already happened here: 10 `###` and 39 `####` headings were written
12
+ * without the space, so most of §13.25–§13.34 rendered as a wall of text, and one
13
+ * prose line beginning `#7 ...` silently became an `<h1>`.
14
+ *
15
+ * Also flags a trailing `#`-closing mismatch, which is the other ATX foot-gun.
16
+ *
17
+ * And it checks code spans, for the same reason: a single-backtick span cannot
18
+ * contain a backtick, so `` `case\`text\`` never closes. The source reads fine and
19
+ * renders as a mess. A code span containing a backtick must use a longer fence.
20
+ *
21
+ * node scripts/doc-heading-check.mjs
22
+ */
23
+ import { readFileSync } from 'node:fs';
24
+ import { dirname, join } from 'node:path';
25
+ import { fileURLToPath } from 'node:url';
26
+
27
+ const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
28
+ const DOC = join(ROOT, 'docs', 'DESIGN.md');
29
+ const lines = readFileSync(DOC, 'utf8').split('\n');
30
+
31
+ const problems = [];
32
+ let headings = 0;
33
+
34
+ lines.forEach((line, i) => {
35
+ const at = 'line ' + (i + 1) + ': ';
36
+
37
+ // ATX heading that is missing the required space after the # run.
38
+ const noSpace = /^(#{1,6})([^ #\t].*)$/.exec(line);
39
+ if (noSpace !== null) {
40
+ problems.push(at + '`' + line.slice(0, 40) + '` — `#` run must be followed by a space, so this renders as plain text: insert `' + noSpace[1] + ' `');
41
+ return;
42
+ }
43
+
44
+ // A real heading, but with a closing `#` run that does not match the opening one.
45
+ const heading = /^(#{1,6})[ \t]+(.*?)[ \t]*#*[ \t]*$/.exec(line);
46
+ if (heading !== null) {
47
+ headings += 1;
48
+ // A same-line `#` immediately after a number is the usual "#7 ..." mistake.
49
+ if (/^#\d/.test(line)) problems.push(at + '`' + line.slice(0, 40) + '` — prose starting with `#<digit>` becomes a level-1 heading');
50
+ }
51
+
52
+ // Backslash-escaped backticks inside what looks like a code span. A span
53
+ // delimited by N backticks cannot contain a run of N+ backticks, so `a\`b\``
54
+ // never closes and the rest of the line renders as literal backslashes.
55
+ if (/\\`/.test(line)) {
56
+ problems.push(at + '`' + line.slice(0, 40) + '` — a code span delimited by one backtick cannot contain one; use double backticks (``…``) instead of `\\`');
57
+ }
58
+ });
59
+
60
+ console.log('doc-heading-check: ' + headings + ' rendered heading(s)');
61
+ if (problems.length > 0) {
62
+ for (const p of problems) console.error(' ✗ ' + p);
63
+ console.error('doc-heading-check: FAIL (' + problems.length + ' malformed construct(s))');
64
+ process.exit(1);
65
+ }
66
+ console.log('DOC HEADINGS OK');
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Fail when `docs/DESIGN.md` references a section that does not exist.
4
+ *
5
+ * The document has accumulated ~170 `§x.y` references across a few hundred
6
+ * sessions of work. That is enough for real drift: a renumbered section, or a
7
+ * section deleted because its conclusion was withdrawn, leaves the surrounding
8
+ * prose pointing at nothing — and a reader who follows the pointer finds no
9
+ * explanation where one was promised.
10
+ *
11
+ * Two kinds of reference are treated differently on purpose:
12
+ *
13
+ * - a reference to an existing section → fine
14
+ * - a reference to a missing section, on a line
15
+ * that itself says 已删除 / 被我删掉 → allowed, and COUNTED
16
+ * - any other reference to a missing section → failure
17
+ *
18
+ * The middle case is not a loophole: §13.05 argues against a conclusion that
19
+ * used to live in §13.04, and §13.05 would be unreadable without naming it. What
20
+ * the rule forbids is a pointer to nowhere that does not admit it.
21
+ *
22
+ * node scripts/doc-ref-check.mjs
23
+ */
24
+ import { readFileSync } from 'node:fs';
25
+ import { dirname, join } from 'node:path';
26
+ import { fileURLToPath } from 'node:url';
27
+
28
+ const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
29
+ const DOC = join(ROOT, 'docs', 'DESIGN.md');
30
+ const md = readFileSync(DOC, 'utf8');
31
+
32
+ // `\s+`, not `\s*`: a section only counts if the `#` run is followed by a space,
33
+ // which is exactly what Markdown itself requires. With `\s*` this script accepted
34
+ // `###13.25` — a line that renders as plain paragraph text — as a live section, so a
35
+ // `§13.25` pointer would resolve here while leading the reader to nothing on GitHub.
36
+ // doc-heading-check.mjs is the guard that fails on such a line; the two now agree on
37
+ // what a section is instead of disagreeing silently.
38
+ const sections = new Set([...md.matchAll(/^###\s+(\d+\.\d+)/gm)].map((m) => m[1]));
39
+ const lines = md.split('\n');
40
+
41
+ const dangling = [];
42
+ let markedDeleted = 0;
43
+ lines.forEach((line, i) => {
44
+ const refs = [...line.matchAll(/§\s*(\d+\.\d+)/g)].map((m) => m[1]);
45
+ if (refs.length === 0) return;
46
+ // The admission has to be on the same line as the reference: a paragraph-long
47
+ // caveat elsewhere in the section would otherwise excuse every pointer in it.
48
+ const admitsDeletion = /已删除|被我删掉/.test(line);
49
+ for (const ref of refs) {
50
+ if (sections.has(ref)) continue;
51
+ if (admitsDeletion) { markedDeleted += 1; continue; }
52
+ dangling.push('line ' + (i + 1) + ': §' + ref + ' — ' + line.trim().slice(0, 80));
53
+ }
54
+ });
55
+
56
+ console.log('doc-ref-check: ' + sections.size + ' sections, ' + markedDeleted + ' reference(s) to withdrawn sections (explicitly marked)');
57
+
58
+ // ── the READMEs point INTO this document too, and nothing was checking that ──
59
+ //
60
+ // Both READMEs cite `docs/DESIGN.md` §x.y ("why hard pin" -> §12.25-§12.27,
61
+ // `readme-numbers` -> §13.37, the engines range -> §13.43). Those pointers were only
62
+ // ever verified by hand, in a throwaway script, twice — the same "one-off check"
63
+ // failure that §13.42 records for the README counts.
64
+ //
65
+ // A README reference gets a stricter rule than a DESIGN one: there is no "marked as
66
+ // deleted" escape hatch, because a README is the first thing a reader opens and a
67
+ // pointer to a section that no longer exists is just broken.
68
+ const readmeProblems = [];
69
+ for (const file of ['README.md', 'README.en.md']) {
70
+ const body = readFileSync(join(ROOT, file), 'utf8');
71
+ body.split('\n').forEach((line, i) => {
72
+ for (const m of line.matchAll(/§\s*(\d+\.\d+)/g)) {
73
+ if (!sections.has(m[1])) readmeProblems.push(file + ':' + (i + 1) + ': §' + m[1] + ' does not exist in docs/DESIGN.md');
74
+ }
75
+ // `§11`-style references point at the README's OWN numbered sections. `§1.2`
76
+ // was handled above, so only bare integers reach here.
77
+ for (const m of line.matchAll(/§\s*(\d+)(?!\.\d)/g)) {
78
+ const own = new Set([...body.matchAll(/^## (\d+)\./gm)].map((x) => x[1]));
79
+ if (!own.has(m[1])) readmeProblems.push(file + ':' + (i + 1) + ': §' + m[1] + ' is not a section of this file');
80
+ }
81
+ });
82
+ }
83
+
84
+ if (dangling.length > 0) {
85
+ for (const d of dangling) console.error(' ✗ ' + d);
86
+ console.error('doc-ref-check: FAIL (' + dangling.length + ' reference(s) to sections that do not exist)');
87
+ process.exit(1);
88
+ }
89
+ if (readmeProblems.length > 0) {
90
+ for (const p of readmeProblems) console.error(' ✗ ' + p);
91
+ console.error('doc-ref-check: FAIL (' + readmeProblems.length + ' broken README cross-reference(s))');
92
+ process.exit(1);
93
+ }
94
+ console.log('DOC REFS OK');
@@ -72,21 +72,58 @@ for (const name of cur.keys()) if (!up.has(name)) added.push(name);
72
72
  untouched.sort(); modified.sort(); added.sort(); dropped.sort();
73
73
 
74
74
  // File-level map: which upstream files survived byte-for-byte.
75
+ //
76
+ // A renamed upstream file needs its own status. Without it, `git mv a b` reads as
77
+ // "a was deleted" — which is literally true of the *path* but hides the thing the
78
+ // document exists to answer: the content came from upstream and is still here. The
79
+ // rename is detected from git's own similarity matching (`-M`), so a file that was
80
+ // renamed *and* edited shows as a rename rather than being silently filed as new.
75
81
  const upstreamFiles = git('ls-tree', '-r', '--name-only', UPSTREAM_REF).trim().split('\n').filter(Boolean);
82
+
83
+ const renamedFrom = new Map(); // old upstream path -> new path
84
+ for (const extra of [[], ['--cached']]) {
85
+ const raw = git('diff', '--name-status', '-M', '--diff-filter=R', ...extra, UPSTREAM_REF).trim();
86
+ if (raw === '') continue;
87
+ for (const line of raw.split('\n')) {
88
+ const [kind, from, to] = line.split('\t');
89
+ if (kind.startsWith('R') && from && to) renamedFrom.set(from, to);
90
+ }
91
+ }
92
+
76
93
  const fileRows = upstreamFiles.map((file) => {
77
94
  let status;
78
95
  try {
79
96
  const now = readFileSync(join(ROOT, file), 'utf8');
80
97
  status = now === git('show', `${UPSTREAM_REF}:${file}`) ? '原样保留' : '已修改';
81
98
  } catch {
82
- status = '已删除';
99
+ const to = renamedFrom.get(file);
100
+ let renamedTo = null;
101
+ if (to !== undefined) {
102
+ try { readFileSync(join(ROOT, to)); renamedTo = to; } catch { renamedTo = null; }
103
+ }
104
+ status = renamedTo !== null ? `已改名 → \`${renamedTo}\`` : '已删除';
83
105
  }
84
106
  return { file, status };
85
107
  });
86
- // Tracked additions only (`git ls-files`), so the list is stable regardless of
87
- // whether the new files are committed yet, and never picks up untracked scratch.
88
- const addedFiles = execFileSync('git', ['diff', '--name-status', '--diff-filter=A', UPSTREAM_REF], { cwd: ROOT, encoding: 'utf8' })
89
- .trim().split('\n').filter(Boolean).map((line) => line.split('\t')[1])
108
+ // Added files come from THREE sources, all measured against the working tree:
109
+ // 1. `git diff --diff-filter=A` — added and staged/committed
110
+ // 2. `git diff --diff-filter=A --cached` — added and staged but not yet committed
111
+ // 3. `git ls-files --others` — created on disk, not yet added at all
112
+ //
113
+ // Source 3 is what makes this trustworthy and it was missing. `provenance` is
114
+ // normally run *before* committing (the docs tell you to regenerate after adding
115
+ // a file), but `git diff` cannot see a file that is not in the index yet. So the
116
+ // regenerated document omitted the new file, and `--check` then failed on the
117
+ // commit the user was about to make — twice in one session, both times in CI
118
+ // after a push, which is the most expensive possible moment to learn about a
119
+ // missing line. Ignored paths are excluded by `--exclude-standard`, so local
120
+ // scratch never leaks in.
121
+ const addedFiles = [...new Set([
122
+ ...git('diff', '--name-status', '--diff-filter=A', UPSTREAM_REF).trim().split('\n').filter(Boolean).map((line) => line.split('\t')[1]),
123
+ ...git('diff', '--name-status', '--diff-filter=A', '--cached', UPSTREAM_REF).trim().split('\n').filter(Boolean).map((line) => line.split('\t')[1]),
124
+ ...git('ls-files', '--others', '--exclude-standard').trim().split('\n').filter(Boolean),
125
+ ])]
126
+ .filter((f) => !upstreamFiles.includes(f))
90
127
  .concat(['docs/PROVENANCE.md', 'scripts/provenance.mjs'])
91
128
  .filter((f, i, all) => all.indexOf(f) === i)
92
129
  .sort();
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Fail when a count stated in the READMEs disagrees with the thing it counts.
4
+ *
5
+ * Three numbers in the docs are derived, not invented, and every one of them has
6
+ * drifted at least once:
7
+ *
8
+ * - "CI 门禁 7 项" ← the number of named steps in check.yml, minus Install
9
+ * - "npm run check 跑 N 步" ← the number of `&&` segments in package.json
10
+ * - "13 组观测 / 47 条断言" ← probe.js: `info.X =` assignments, `fail(` calls
11
+ *
12
+ * Reading the README and comparing it to the workflow by eye already failed twice
13
+ * (the directory tree said "5 项门禁" for weeks after the count became 7). A number
14
+ * that can be computed should never be typed.
15
+ *
16
+ * Every count is derived STATICALLY — no browser, no agent-browser, no network — so
17
+ * this can run as a gate anywhere, including CI.
18
+ *
19
+ * node scripts/readme-numbers.mjs # check
20
+ * node scripts/readme-numbers.mjs --print # show what it thinks the counts are
21
+ */
22
+ import { readFileSync } from 'node:fs';
23
+ import { dirname, join } from 'node:path';
24
+ import { fileURLToPath } from 'node:url';
25
+
26
+ const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
27
+ const read = (rel) => readFileSync(join(ROOT, rel), 'utf8');
28
+
29
+ // ── the three truths, each taken from the file that defines it ────────────────
30
+ const wf = read('.github/workflows/check.yml');
31
+ const namedSteps = [...wf.matchAll(/^\s+- name: (.+)$/gm)].map((m) => m[1]);
32
+ const ciGates = namedSteps.filter((n) => n !== 'Install').length;
33
+
34
+ const pkg = JSON.parse(read('package.json'));
35
+ const localSteps = pkg.scripts.check.split('&&').map((s) => s.trim()).filter(Boolean).length;
36
+
37
+ const probe = read('test/browser/probe.js');
38
+ const observedGroups = new Set([...probe.matchAll(/info\.([a-zA-Z]\w*)\s*=/g)].map((m) => m[1]));
39
+ const assertions = [...probe.matchAll(/\bfail\(/g)].length;
40
+
41
+ const truth = { ciGates, localSteps, groups: observedGroups.size, assertions };
42
+
43
+ if (process.argv.includes('--print')) {
44
+ console.log('CI 门禁 ' + ciGates + ' 项(workflow 具名步骤 ' + namedSteps.length + ' − Install)');
45
+ console.log('npm run check ' + localSteps + ' 步');
46
+ console.log('probe.js 观测组 ' + truth.groups + ' 个 / 断言 ' + assertions + ' 条');
47
+ process.exit(0);
48
+ }
49
+
50
+ // ── what each README claims, matched by the sentence it appears in ────────────
51
+ //
52
+ // The line's CONTEXT decides which number it is, not the number's suffix. The first
53
+ // version of this audit classified "门禁本身是 7 项" as a browser-check count because
54
+ // it looked for `N 项` — the audit was wrong, not the document. Anchoring on the
55
+ // sentence is what made it correct.
56
+ const problems = [];
57
+ const counted = { ciGates: 0, localSteps: 0, groups: 0, assertions: 0 };
58
+
59
+ const claim = (file, lineNo, kind, found, want) => {
60
+ counted[kind] += 1;
61
+ if (found !== want) {
62
+ problems.push(file + ':' + lineNo + ' — ' + kind + ' says ' + found + ', actual ' + want);
63
+ }
64
+ };
65
+
66
+ for (const file of ['README.md', 'README.en.md']) {
67
+ read(file).split('\n').forEach((line, i) => {
68
+ const at = i + 1;
69
+
70
+ // "CI:7 项门禁" / "the seven gates" / "门禁本身是 7 项" / "those 7 gates"
71
+ for (const m of line.matchAll(/(\d+)\s*项门禁/g)) claim(file, at, 'ciGates', Number(m[1]), ciGates);
72
+ for (const m of line.matchAll(/(\d+)\s*gates\b/g)) claim(file, at, 'ciGates', Number(m[1]), ciGates);
73
+ for (const m of line.matchAll(/门禁(?:本身)?是\s*(\d+)\s*项/g)) claim(file, at, 'ciGates', Number(m[1]), ciGates);
74
+
75
+ // "其中 6 步" / "6 of them"
76
+ for (const m of line.matchAll(/(\d+)\s*步/g)) {
77
+ // "7 项门禁(…)" style lines also contain 步 sometimes; require the verb nearby.
78
+ if (!/跑|runs?|其中|of them/.test(line)) continue;
79
+ claim(file, at, 'localSteps', Number(m[1]), localSteps);
80
+ }
81
+ for (const m of line.matchAll(/(\d+)\s*of them/g)) claim(file, at, 'localSteps', Number(m[1]), localSteps);
82
+
83
+ // "跑 47 条断言 / 记录 13 组观测" and its English twin
84
+ for (const m of line.matchAll(/(\d+)\s*条断言/g)) claim(file, at, 'assertions', Number(m[1]), assertions);
85
+ for (const m of line.matchAll(/(\d+)\s*assertions?/g)) claim(file, at, 'assertions', Number(m[1]), assertions);
86
+ for (const m of line.matchAll(/(\d+)\s*组观测/g)) claim(file, at, 'groups', Number(m[1]), truth.groups);
87
+ for (const m of line.matchAll(/(\d+)\s*recorded groups/g)) claim(file, at, 'groups', Number(m[1]), truth.groups);
88
+ });
89
+ }
90
+
91
+ // ── the `npm run check` comment must enumerate the steps that are really there ──
92
+ //
93
+ // The count check above ("7 步") caught the number but not the LIST. Both READMEs
94
+ // said `npm run check # build --check + version-check + smoke` long after the
95
+ // command had grown to seven steps — the number was right three lines further down
96
+ // while the comment beside the command was three versions out of date. A reader who
97
+ // trusts the comment would skip provenance, both doc gates and the numbers gate.
98
+ //
99
+ // Scope: this fires on a line that *attempts an enumeration* — one whose comment
100
+ // names at least one real step. A bare `npm run check # 5. run the gates` in the
101
+ // release ritual makes no claim about WHICH steps, so demanding all seven there
102
+ // would be this gate inventing a rule the prose never stated. The second half of the
103
+ // guard keeps that from becoming an escape hatch: each README must still contain at
104
+ // least one real enumeration.
105
+ const checkScripts = [...pkg.scripts.check.matchAll(/node (scripts\/[\w.-]+\.mjs|test\/[\w.-]+\.cjs)/g)]
106
+ .map((m) => m[1]);
107
+ // Normalize to the word the prose uses: `scripts/build-client.mjs` -> `build-client`,
108
+ // `test/smoke.test.cjs` -> `smoke` (the `.test` infix is not spoken).
109
+ const shortOf = (script) => script
110
+ .replace(/^scripts\//, '').replace(/^test\//, '')
111
+ .replace(/\.mjs$/, '').replace(/\.test\.cjs$/, '').replace(/\.cjs$/, '');
112
+ const aliasOf = (short) => (short === 'build-client' ? /build(?: --check)?/ : null);
113
+ const names = (block, script) => {
114
+ const alias = aliasOf(shortOf(script));
115
+ return alias !== null ? alias.test(block) : block.includes(shortOf(script));
116
+ };
117
+
118
+ let listChecked = 0;
119
+ for (const file of ['README.md', 'README.en.md']) {
120
+ let enumerations = 0;
121
+ const lines = read(file).split('\n');
122
+ lines.forEach((line, i) => {
123
+ // Matches the code-block comment AND the prose enumeration (the 'local `npm run
124
+ // check` runs 7 of them (...)' sentence). The historical staleness happened in the
125
+ // code block, but the prose copy makes the same claim and drifts the same way.
126
+ if (!/npm run check\b/.test(line)) return;
127
+ listChecked += 1;
128
+ // The comment may continue on the next line (it is long); join both.
129
+ const block = line + ' ' + (lines[i + 1] ?? '');
130
+ // Does this line attempt an enumeration at all?
131
+ if (!checkScripts.some((s) => names(block, s))) return;
132
+ enumerations += 1;
133
+ for (const script of checkScripts) {
134
+ if (!names(block, script)) problems.push(file + ':' + (i + 1) + ' — `npm run check` list omits ' + script);
135
+ }
136
+ });
137
+ if (enumerations === 0) {
138
+ problems.push(file + ' — no `npm run check` line enumerates the steps any more; the guard has nothing to check');
139
+ }
140
+ }
141
+
142
+ const total = Object.values(counted).reduce((a, b) => a + b, 0);
143
+ if (total === 0 || listChecked === 0) {
144
+ // A gate that matches nothing is worse than no gate: it reports success forever.
145
+ console.error('readme-numbers: found NO claim to check (numbers ' + total + ', `npm run check` lines '
146
+ + listChecked + ') — the patterns have drifted from the prose');
147
+ process.exit(1);
148
+ }
149
+
150
+ console.log('readme-numbers: 核对 ' + total + ' 处数字(门禁 ' + ciGates + ' / 本地 ' + localSteps
151
+ + ' / 观测组 ' + truth.groups + ' / 断言 ' + assertions + ')');
152
+ if (problems.length > 0) {
153
+ for (const p of problems) console.error(' ✗ ' + p);
154
+ console.error('readme-numbers: FAIL (' + problems.length + ' 处不一致)');
155
+ process.exit(1);
156
+ }
157
+ console.log('README NUMBERS OK');
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Report the three places a release has to exist, side by side.
4
+ *
5
+ * §13.43, §13.45 and §13.47 are the same failure three times: the repository was
6
+ * self-consistent while an outside world disagreed.
7
+ *
8
+ * git tag ← what this checkout claims
9
+ * GitHub Release ← what the badge on the repo page reads
10
+ * npm registry ← what `npm i <name>` actually installs
11
+ *
12
+ * Each one is invisible from inside the others. After `git push` + `git tag` +
13
+ * `gh release create` the repo looks finished; if `npm publish` never ran, everyone
14
+ * installing by package name still gets the previous version and nothing errors.
15
+ *
16
+ * NOT a CI gate, deliberately: it needs network access to registry.npmjs.org and
17
+ * api.github.com, and a gate that fails when the network is flaky trains people to
18
+ * ignore it. Run it before announcing a release:
19
+ *
20
+ * node scripts/release-status.mjs # report; exit 1 if npm is behind
21
+ * node scripts/release-status.mjs --warn # report only, always exit 0
22
+ */
23
+ import { execFileSync } from 'node:child_process';
24
+ import { readFileSync } from 'node:fs';
25
+ import { dirname, join } from 'node:path';
26
+ import { fileURLToPath } from 'node:url';
27
+
28
+ const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
29
+ const WARN_ONLY = process.argv.includes('--warn');
30
+
31
+ const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
32
+ const version = String(pkg.version);
33
+ const name = String(pkg.name);
34
+
35
+ const run = (cmd, args) => {
36
+ try {
37
+ return { ok: true, out: execFileSync(cmd, args, { cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim() };
38
+ } catch (e) {
39
+ return { ok: false, out: ((e.stdout ?? '') + (e.stderr ?? '')).trim() };
40
+ }
41
+ };
42
+
43
+ const rows = [];
44
+
45
+ // 1. git tag — local truth, no network.
46
+ const tag = run('git', ['tag', '--list', 'v' + version]);
47
+ const headTagged = run('git', ['describe', '--tags', '--exact-match', 'HEAD']);
48
+ rows.push({
49
+ place: 'git tag',
50
+ present: tag.out.split('\n').filter(Boolean).includes('v' + version),
51
+ detail: headTagged.ok ? 'HEAD is exactly v' + version : 'HEAD is not exactly v' + version,
52
+ missing: 'git tag -a v' + version + ' -m "…" && git push origin v' + version,
53
+ });
54
+
55
+ // 2. GitHub Release — what the repo-page badge reads. No gh? Then say so, don't guess.
56
+ const gh = run('gh', ['api', 'repos/' + (run('git', ['remote', 'get-url', 'origin']).out.match(/github\.com[:/]([^/]+\/[^/.]+)/) ?? [])[1] + '/releases/tags/v' + version]);
57
+ rows.push({
58
+ place: 'GitHub Release',
59
+ present: gh.ok,
60
+ detail: gh.ok ? 'exists (the version badge resolves)' : 'not found — the badge shows a red "no releases"',
61
+ missing: 'gh release create v' + version + ' --notes-file …',
62
+ });
63
+
64
+ // 3. npm registry — what `npm i <name>@latest` installs.
65
+ const npmView = run('npm', ['view', name + '@' + version, 'version']);
66
+ const latest = run('npm', ['view', name, 'dist-tags.latest']);
67
+ rows.push({
68
+ place: 'npm registry',
69
+ present: npmView.ok && npmView.out.includes(version),
70
+ detail: npmView.ok && npmView.out.includes(version)
71
+ ? 'published' + (latest.ok ? ' (dist-tags.latest = ' + latest.out + ')' : '')
72
+ : 'MISSING — `npm i ' + name + '@latest` still installs ' + (latest.ok ? latest.out : '(unknown)'),
73
+ missing: 'npm publish',
74
+ });
75
+
76
+ const pad = (s, n) => s + ' '.repeat(Math.max(0, n - [...s].length));
77
+ console.log('release-status: ' + name + '@' + version + '\n');
78
+ for (const r of rows) console.log(' ' + (r.present ? '●' : '○') + ' ' + pad(r.place, 16) + r.detail);
79
+ const absent = rows.filter((r) => !r.present);
80
+ if (absent.length > 0) {
81
+ console.log('\nmissing from ' + absent.length + ' place(s):');
82
+ for (const r of absent) console.log(' ' + r.place + ': ' + r.missing);
83
+ }
84
+ if (absent.some((r) => r.place === 'npm registry')) {
85
+ const msg = 'release-status: ' + version + ' is tagged but NOT on npm — anyone installing by package name gets the old version';
86
+ if (WARN_ONLY) console.log('\n' + msg + ' (warn only)');
87
+ else {
88
+ console.error('\n' + msg);
89
+ process.exit(1);
90
+ }
91
+ }
92
+ console.log('\nrelease-status: consistent everywhere');