dsh-statcheck 0.0.0-stage → 0.1.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/LICENSE +201 -0
  3. package/README-zh.md +117 -0
  4. package/README.md +116 -2
  5. package/cordis.patch.yml +18 -0
  6. package/lib/check.d.ts +92 -0
  7. package/lib/check.d.ts.map +1 -0
  8. package/lib/check.js +250 -0
  9. package/lib/check.js.map +1 -0
  10. package/lib/config.d.ts +37 -0
  11. package/lib/config.d.ts.map +1 -0
  12. package/lib/config.js +44 -0
  13. package/lib/config.js.map +1 -0
  14. package/lib/index.d.ts +36 -0
  15. package/lib/index.d.ts.map +1 -0
  16. package/lib/index.js +50 -0
  17. package/lib/index.js.map +1 -0
  18. package/lib/math.d.ts +76 -0
  19. package/lib/math.d.ts.map +1 -0
  20. package/lib/math.js +218 -0
  21. package/lib/math.js.map +1 -0
  22. package/lib/report.d.ts +41 -0
  23. package/lib/report.d.ts.map +1 -0
  24. package/lib/report.js +91 -0
  25. package/lib/report.js.map +1 -0
  26. package/lib/runtime.d.ts +104 -0
  27. package/lib/runtime.d.ts.map +1 -0
  28. package/lib/runtime.js +235 -0
  29. package/lib/runtime.js.map +1 -0
  30. package/lib/tools/shared.d.ts +127 -0
  31. package/lib/tools/shared.d.ts.map +1 -0
  32. package/lib/tools/shared.js +61 -0
  33. package/lib/tools/shared.js.map +1 -0
  34. package/lib/tools/stat-check.d.ts +12 -0
  35. package/lib/tools/stat-check.d.ts.map +1 -0
  36. package/lib/tools/stat-check.js +83 -0
  37. package/lib/tools/stat-check.js.map +1 -0
  38. package/lib/tools/stat-recompute.d.ts +12 -0
  39. package/lib/tools/stat-recompute.d.ts.map +1 -0
  40. package/lib/tools/stat-recompute.js +82 -0
  41. package/lib/tools/stat-recompute.js.map +1 -0
  42. package/lib/tools/stat-report.d.ts +10 -0
  43. package/lib/tools/stat-report.d.ts.map +1 -0
  44. package/lib/tools/stat-report.js +66 -0
  45. package/lib/tools/stat-report.js.map +1 -0
  46. package/lib/version.d.ts +7 -0
  47. package/lib/version.d.ts.map +1 -0
  48. package/lib/version.js +7 -0
  49. package/lib/version.js.map +1 -0
  50. package/package.json +82 -4
  51. package/src/check.ts +308 -0
  52. package/src/config.ts +71 -0
  53. package/src/index.ts +75 -0
  54. package/src/math.ts +205 -0
  55. package/src/report.ts +113 -0
  56. package/src/runtime.ts +293 -0
  57. package/src/tools/shared.ts +77 -0
  58. package/src/tools/stat-check.ts +83 -0
  59. package/src/tools/stat-recompute.ts +82 -0
  60. package/src/tools/stat-report.ts +68 -0
  61. package/src/version.ts +7 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,49 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Fixed
10
+
11
+ - Re-checking unchanged text no longer fails with `STORE_ERROR`: evidence
12
+ identity is the immutable snapshot plus the findings, and retrieval times
13
+ come from the snapshot, so unchanged analysis dedupes while a different
14
+ findings cap produces distinct evidence.
15
+ - `stat_report` no longer throws when a finding's recomputed p is `null` (the
16
+ JSON form of the NaN emitted for an impossible df); Markdown shows `n/a` and
17
+ SARIF records `recomputedP: null`.
18
+ - A per-call `maxFindings` is clamped to the configured hard cap instead of
19
+ overriding it.
20
+ - Negative F and χ² values are rejected as out of domain instead of being
21
+ mapped to p = 1.
22
+ - `stat_report` accepts an optional `text` and maps each finding's `charStart`
23
+ to a real SARIF line/column; without it the old line-1 fallback remains.
24
+
25
+ ## [0.1.0] - 2026-11-08
26
+
27
+ First release: statistical consistency checking.
28
+
29
+ ### Added
30
+
31
+ - `stat_check`: APA-style parsing of t/F/χ²/r/z with p values and 95% CIs,
32
+ recomputation of p (two-tailed t/r/z, upper-tail F/χ²) from zero-dependency
33
+ distributions, and self-consistency findings with exact character locators.
34
+ - `stat_recompute`: single-statistic recomputation with the same documented
35
+ rounding rule.
36
+ - `stat_report`: Markdown table and SARIF 2.1.0 output.
37
+ - REP v1 integration: the analyzed text becomes an immutable snapshot, findings
38
+ become evidence checks (pass/fail/skipped), and a sealed-able record is written.
39
+ - Distribution implementations validated against published critical values
40
+ (t, F, χ², r, z) in the test suite.
41
+ - 42 tests; benchmark on `dsh-research-bench` stats v0.1.0 (30 cases): precision
42
+ 1.00, recall 1.00, clean false-positive rate 0.00, exact accuracy 1.00.
43
+
44
+ ### Notes
45
+
46
+ - Findings mean "the reported p does not follow from the reported statistic";
47
+ they are not misconduct claims and are not a substitute for a statistician.
48
+ - One-sided tests, Welch fractional df and table-embedded statistics are out of
49
+ scope in v0.1.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README-zh.md ADDED
@@ -0,0 +1,117 @@
1
+ # dsh-statcheck
2
+
3
+ **重算稿件报告的统计数据 —— 并把对不上的那些标出来。**
4
+
5
+ *这是算术,不是指控:每条 finding 都会给出报告的统计量、它实际蕴含的 p 值,以及它所依据的精确字符位置。*
6
+
7
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
8
+ [![Node](https://img.shields.io/badge/node-%5E22.19%20%7C%7C%20%3E%3D24.9-brightgreen.svg)]()
9
+
10
+ [English](README.md) · 简体中文
11
+
12
+ ---
13
+
14
+ ## 它做什么
15
+
16
+ - 解析 APA 风格的报告:`t(df)`、`F(df1, df2)`、`χ²(df)`、`r(df)`、`z`,每一项都带邻近的 `p = …`、`p < …` 或 `p > …`,以及可选的 `95% CI [lo, hi]`。
17
+ - 用零依赖的分布函数,从报告的统计量重算 p 值(t/r/z 双尾,F/χ² 上尾)。
18
+ - 用报告值、重算值、字符区间与稳定的 issue code 标出自相矛盾之处。
19
+ - 校验 CI 与显著性是否一致(p 显著,但 CI 包含 0,就是矛盾)。
20
+ - 输出 Markdown 与 **SARIF 2.1.0**,并把被分析的文本注册为一条 REP v1 证据,其检查项就是这些 findings。
21
+
22
+ ## 它不做什么
23
+
24
+ - **不重新分析数据。** 它无从判断报告的统计量是否适合该研究设计。
25
+ - **不做学术不端指控。** 一条 finding 的含义只是“报告的 p 无法由报告的统计量推出”。它是供人工复核的候选,绝不是对作者的定论。
26
+ - **不读 PDF/OCR。** 请先用 `dsh-doc-anchor` 抽取文本,再传入 `text` 或 `.txt/.md/.tex/.html` 路径。
27
+ - **不做模型/假设检查**,不做多重比较校正,也不做样本量推断。
28
+ - **不静默放宽容差。** 舍入规则固定且已写明;被标出的值始终是标出的。
29
+
30
+ ## 兼容性
31
+
32
+ | | |
33
+ |---|---|
34
+ | DeepSeek Harness | **`dsh-v0.2.1-rc.5`**(2026-11-08 实测);peer 区间 `>=0.2.1-0 <0.3.0 \|\| >=0.2.2-0 <0.3.0` |
35
+ | Node | `^22.19.0 \|\| >=24.9.0`(实测 `24.22.1`),仅 ESM |
36
+ | Peer | `@perrylink/dsh-research-core ^0.1.0`、`@deepseek-ai/cordis ^4.0.5-alpha.1`、`@deepseek-ai/dsh-tools`、`@deepseek-ai/schemastery ^3.18.5-alpha.1` |
37
+ | 运行时依赖 | **零** |
38
+
39
+ ```sh
40
+ dsh plugin --profile <name> add @perrylink/dsh-research-core dsh-statcheck
41
+ dsh --profile <name> --dump-config | grep dsh-statcheck
42
+ dsh plugin --profile <name> remove dsh-statcheck
43
+ ```
44
+
45
+ ## 工具
46
+
47
+ ### `stat_check`
48
+
49
+ `{ text?, path?, persist?, maxFindings? }` → `{ ok, summary, findings[], source, evidenceId?, recordPath? }`。
50
+
51
+ 每条 finding:`statistic`、`df`、`text`、`charStart`、`charEnd`、`reported { statistic, p, pKind, pValue, ci? }`、`recomputed { p }`、`status`(`consistent`/`inconsistent`/`unparsed`)、`issue?`(`p-value`/`p-threshold`/`ci`/`format`/`df`)、`severity`、`detail`。
52
+
53
+ ### `stat_recompute`
54
+
55
+ `{ statistic: 't'|'F'|'chi2'|'r'|'z', value, df[], p? }` → `{ ok, p, judgment? }`。
56
+ t/r/z 为双尾,F/χ² 为上尾。`p` 使用与 `stat_check` 相同的舍入规则。
57
+
58
+ ### `stat_report`
59
+
60
+ `{ findings, text? }` → `{ ok, markdown, sarif, summary }`。SARIF 中每条不一致的 finding 对应一个 error 结果。传入原始稿件文本,才能把每条 finding 的 `charStart` 映射为真实的 SARIF `startLine`/`startColumn`;不传 `text` 时,区域退化为第 1 行加字符列(`properties.charStart`/`charEnd` 始终精确)。
61
+
62
+ ### 错误码
63
+
64
+ `INVALID_INPUT` · `NOT_FOUND` · `PATH_ESCAPE` · `NOT_A_FILE` · `TOO_LARGE` · `OUT_OF_DOMAIN` · `STORE_ERROR`
65
+
66
+ ## 舍入规则(写明,不是调出来的)
67
+
68
+ 报告的 `p = x` 视为一致,当且仅当 `|recomputed − x| ≤ 0.5 × 10^-decimals + 0.001`。
69
+ 多出的 `0.001` 用来吸收一个事实:统计量本身也经常是四舍五入后报告的(例如 `t = 2.50` 蕴含 p ≈ .01855,通常写作 `.019`)。`p < X` 在重算值低于 `X` 时一致;`p > X` 在重算值高于 `X` 时一致。
70
+
71
+ ## 配置
72
+
73
+ | 键 | 默认 | 含义 |
74
+ |---|---|---|
75
+ | `enabled` | `true` | `false` 时不挂载任何内容 |
76
+ | `root` | `.statcheck` | 存储与记录的根目录 |
77
+ | `workspaceRoot` | `process.cwd()` | 稿件路径必须解析到该目录内 |
78
+ | `maxChars` | `2000000` | 分析字符数上限(超出即失败,绝不截断) |
79
+ | `maxFindings` | `500` | 单次调用的 findings 上限 |
80
+ | `persist` | `true` | 写入快照与 REP 记录 |
81
+
82
+ ## 评测
83
+
84
+ ### 基准评测 —— `dsh-research-bench` stats v0.1.0(30 条用例)
85
+
86
+ ```sh
87
+ pnpm run bench:stats
88
+ ```
89
+
90
+ | 指标 | 值 |
91
+ |---|---:|
92
+ | 不一致 precision | **1.00** |
93
+ | 不一致 recall | **1.00** |
94
+ | 不一致 F1 | **1.00** |
95
+ | 干净样本误报率 | **0.00** |
96
+ | 标出时 issue 的准确率 | **1.00** |
97
+ | 整案完全一致率 | **1.00** |
98
+
99
+ 逐案原始预测:[`bench/results-stats.json`](bench/results-stats.json)。
100
+
101
+ **范围警告**:数据集规模小、是合成的且干净(围绕已发表的临界值构造的 10 条一致句子 + 20 条不一致句子)。满分只说明解析器与重算逻辑在这些构造上与临界值标签一致;它**并不**估计真实稿件上的准确率。舍入规则与 issue code 都已写明,因此读者可以具体地不同意某条 finding。
102
+
103
+ ### 测试
104
+
105
+ - **42 个测试,分布在 5 个文件**:对照已发表的临界值检验分布尾概率(t/F/χ²/r/z);解析(所有统计族、偏移、阈值、CI、多统计量、无法解析);判定(p 值、阈值、格式、CI、df、负的 F/χ² 定义域);运行时(证据 + 合法 REP 记录、不产生证据冲突的重复检查、findings 上限的截断、文件与媒体类型、persist=false、路径逃逸、大小上限);工具(schema、成功/失败、含重算 p 为 null 的 SARIF,以及由可选 text 提供的行列映射);包契约。
106
+
107
+ ## 已知限制(v0.1)
108
+
109
+ - 不建模单侧检验、Welch 分数自由度、多模型表格,以及“见 Table 2”这类正文内引用。
110
+ - 只解析 APA 风格的行内报告;表格中的 `p` 值不在范围内。
111
+ - CI 与 p 的一致性检查假设对同一效应做双侧检验,α = .05。
112
+ - 不做多重比较校正。
113
+ - SARIF 的行列映射需要可选的 `stat_report` `text`;不提供时,区域为第 1 行加字符列(精确的 `charStart`/`charEnd` 属性始终存在)。
114
+
115
+ ## 许可
116
+
117
+ Apache-2.0。运行时不含任何第三方代码。
package/README.md CHANGED
@@ -1,3 +1,117 @@
1
- # Temporary Holding Version
1
+ # dsh-statcheck
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Recompute the statistics a manuscript reports — and flag the ones that do not add up.**
4
+
5
+ *It is arithmetic, not accusation: each finding shows the reported statistic, the p value it actually implies, and the exact characters it came from.*
6
+
7
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
8
+ [![Node](https://img.shields.io/badge/node-%5E22.19%20%7C%7C%20%3E%3D24.9-brightgreen.svg)]()
9
+
10
+ English · [简体中文](README-zh.md)
11
+
12
+ ---
13
+
14
+ ## What it does
15
+
16
+ - Parses APA-style reports: `t(df)`, `F(df1, df2)`, `χ²(df)`, `r(df)`, `z`, each with a nearby `p = …`, `p < …` or `p > …` and an optional `95% CI [lo, hi]`.
17
+ - Recomputes the p value from the reported statistic with zero-dependency distributions (two-tailed t/r/z, upper-tail F/χ²).
18
+ - Flags self-inconsistency with the reported value, the recomputed value, the character range and a stable issue code.
19
+ - Checks the CI against significance (a significant p with a CI that includes 0 is a contradiction).
20
+ - Emits Markdown and **SARIF 2.1.0**, and registers the analyzed text as a REP v1 evidence item whose checks are the findings.
21
+
22
+ ## What it does not do
23
+
24
+ - **No data re-analysis.** It cannot know whether the reported statistic is appropriate for the design.
25
+ - **No misconduct claims.** A finding means “the reported p does not follow from the reported statistic”. It is a candidate for human review, never a verdict about authors.
26
+ - **No PDF/OCR.** Extract text first (`dsh-doc-anchor`) and pass `text` or a `.txt/.md/.tex/.html` path.
27
+ - **No model/assumption checks**, no multiple-comparison correction, no sample-size inference.
28
+ - **No silent tolerance widening.** The rounding rule is fixed and documented; a flagged value stays flagged.
29
+
30
+ ## Compatibility
31
+
32
+ | | |
33
+ |---|---|
34
+ | DeepSeek Harness | **`dsh-v0.2.1-rc.5`** (verified 2026-11-08); peer line `>=0.2.1-0 <0.3.0 \|\| >=0.2.2-0 <0.3.0` |
35
+ | Node | `^22.19.0 \|\| >=24.9.0` (tested on `24.22.1`), ESM only |
36
+ | Peers | `@perrylink/dsh-research-core ^0.1.0`, `@deepseek-ai/cordis ^4.0.5-alpha.1`, `@deepseek-ai/dsh-tools`, `@deepseek-ai/schemastery ^3.18.5-alpha.1` |
37
+ | Runtime dependencies | **zero** |
38
+
39
+ ```sh
40
+ dsh plugin --profile <name> add @perrylink/dsh-research-core dsh-statcheck
41
+ dsh --profile <name> --dump-config | grep dsh-statcheck
42
+ dsh plugin --profile <name> remove dsh-statcheck
43
+ ```
44
+
45
+ ## Tools
46
+
47
+ ### `stat_check`
48
+
49
+ `{ text?, path?, persist?, maxFindings? }` → `{ ok, summary, findings[], source, evidenceId?, recordPath? }`.
50
+
51
+ Each finding: `statistic`, `df`, `text`, `charStart`, `charEnd`, `reported { statistic, p, pKind, pValue, ci? }`, `recomputed { p }`, `status` (`consistent`/`inconsistent`/`unparsed`), `issue?` (`p-value`/`p-threshold`/`ci`/`format`/`df`), `severity`, `detail`.
52
+
53
+ ### `stat_recompute`
54
+
55
+ `{ statistic: 't'|'F'|'chi2'|'r'|'z', value, df[], p? }` → `{ ok, p, judgment? }`.
56
+ t/r/z are two-tailed; F/χ² upper-tail. `p` uses the same rounding rule as `stat_check`.
57
+
58
+ ### `stat_report`
59
+
60
+ `{ findings, text? }` → `{ ok, markdown, sarif, summary }`. SARIF carries one error result per inconsistent finding. Pass the original manuscript text to map each finding's `charStart` to a real SARIF `startLine`/`startColumn`; without `text`, the region falls back to line 1 plus a character column (the `properties.charStart`/`charEnd` are always exact).
61
+
62
+ ### Error codes
63
+
64
+ `INVALID_INPUT` · `NOT_FOUND` · `PATH_ESCAPE` · `NOT_A_FILE` · `TOO_LARGE` · `OUT_OF_DOMAIN` · `STORE_ERROR`
65
+
66
+ ## The rounding rule (documented, not tuned)
67
+
68
+ A reported `p = x` is consistent when `|recomputed − x| ≤ 0.5 × 10^-decimals + 0.001`.
69
+ The extra `0.001` absorbs the fact that the statistic itself is often reported rounded (e.g. `t = 2.50` implies p ≈ .01855, commonly written `.019`). `p < X` is consistent when the recomputed value is below `X`; `p > X` when above.
70
+
71
+ ## Configuration
72
+
73
+ | Key | Default | Meaning |
74
+ |---|---|---|
75
+ | `enabled` | `true` | `false` mounts nothing |
76
+ | `root` | `.statcheck` | store + records root |
77
+ | `workspaceRoot` | `process.cwd()` | manuscript paths must resolve inside it |
78
+ | `maxChars` | `2000000` | analyzed-character cap (over-limit fails, never truncates) |
79
+ | `maxFindings` | `500` | findings per call |
80
+ | `persist` | `true` | store a snapshot + REP record |
81
+
82
+ ## Evaluation
83
+
84
+ ### Benchmark — `dsh-research-bench` stats v0.1.0 (30 cases)
85
+
86
+ ```sh
87
+ pnpm run bench:stats
88
+ ```
89
+
90
+ | metric | value |
91
+ |---|---:|
92
+ | inconsistent precision | **1.00** |
93
+ | inconsistent recall | **1.00** |
94
+ | inconsistent F1 | **1.00** |
95
+ | clean false-positive rate | **0.00** |
96
+ | issue accuracy when flagged | **1.00** |
97
+ | exact accuracy | **1.00** |
98
+
99
+ Raw per-case predictions: [`bench/results-stats.json`](bench/results-stats.json).
100
+
101
+ **Scope warning**: the dataset is small, synthetic and clean (10 consistent + 20 inconsistent sentences around published critical values). A perfect score shows the parser and the recomputation agree with the critical-value labels on these constructions; it does **not** estimate real-manuscript accuracy. The rounding rule and issue codes are documented so a reader can disagree with a specific finding.
102
+
103
+ ### Tests
104
+
105
+ - **42 tests across 5 files**: distribution tails against published critical values (t/F/χ²/r/z), parsing (all families, offsets, thresholds, CIs, multiple statistics, unparsed), judging (p-value, threshold, format, CI, df, negative F/χ² domains), runtime (evidence + valid REP record, re-check without an evidence conflict, findings-cap clamp, file/media type, persist=false, path escapes, size cap), tools (schemas, success/failure, SARIF incl. a null recomputed p and line/column mapping from optional text), package contract.
106
+
107
+ ## Known limitations (v0.1)
108
+
109
+ - One-sided tests, fractional Welch df, multi-model tables and within-text references such as “see Table 2” are not modeled.
110
+ - Only APA-style inline reports are parsed; `p` values in tables are out of scope.
111
+ - CI-versus-p checking assumes a two-sided test of the same effect at α = .05.
112
+ - No correction for multiple comparisons.
113
+ - SARIF line/column mapping needs the optional `stat_report` `text`; without it the region is line 1 + character column (the exact `charStart`/`charEnd` properties are always present).
114
+
115
+ ## License
116
+
117
+ Apache-2.0. No third-party runtime code.
@@ -0,0 +1,18 @@
1
+ # dsh-statcheck bundle patch: mount the statistical consistency tools.
2
+ #
3
+ # Every key below is a Config field (Schemastery schema); invalid values fail
4
+ # the profile load loudly. Analysis is local and deterministic — no network.
5
+ - insert:
6
+ - id: dsh-statcheck
7
+ name: dsh-statcheck
8
+ config:
9
+ # Master switch. On by default; `false` mounts no tools at all.
10
+ enabled: true
11
+ # Store/record root, resolved against the harness working directory.
12
+ root: .statcheck
13
+ # Hard cap on analyzed characters; over-limit input fails, never truncates.
14
+ maxChars: 2000000
15
+ # Hard cap on findings per call.
16
+ maxFindings: 500
17
+ # Persist the analyzed text as a REP snapshot + record.
18
+ persist: true
package/lib/check.d.ts ADDED
@@ -0,0 +1,92 @@
1
+ /**
2
+ * APA-style statistical reporting parser and consistency judge.
3
+ *
4
+ * It recognizes `t(df)`, `F(df1, df2)`, `χ²(df)`, `r(df)` and `z` with a nearby
5
+ * p value (and optional 95% CI), recomputes the p value from the reported
6
+ * statistic, and decides whether the report is self-consistent. It never
7
+ * re-analyses the data, never judges the model and never calls a result
8
+ * "fraudulent": a finding is "the reported p does not follow from the reported
9
+ * statistic", with both numbers shown.
10
+ *
11
+ * @module dsh-statcheck/check
12
+ */
13
+ /** Supported statistic families. */
14
+ export type StatisticKind = 't' | 'F' | 'chi2' | 'r' | 'z';
15
+ /** Consistency verdict of one reported statistic. */
16
+ export type StatStatus = 'consistent' | 'inconsistent' | 'unparsed';
17
+ /** What kind of problem was found. */
18
+ export type StatIssue = 'p-value' | 'p-threshold' | 'ci' | 'format' | 'df';
19
+ /** One parsed and judged statistical report. */
20
+ export interface StatFinding {
21
+ readonly findingId: string;
22
+ readonly statistic: StatisticKind;
23
+ /** The matched source text. */
24
+ readonly text: string;
25
+ readonly charStart: number;
26
+ readonly charEnd: number;
27
+ /** Degrees of freedom as reported. */
28
+ readonly df: readonly number[];
29
+ readonly reported: {
30
+ readonly statistic: number;
31
+ /** The p value as written (`".018"`, `"<.001"` …). */
32
+ readonly p?: string;
33
+ readonly pKind?: 'equal' | 'less' | 'greater';
34
+ readonly pValue?: number;
35
+ readonly ci?: readonly [number, number];
36
+ };
37
+ /** The p value recomputed from the reported statistic. */
38
+ readonly recomputed: {
39
+ readonly p: number;
40
+ };
41
+ readonly status: StatStatus;
42
+ readonly issue?: StatIssue;
43
+ readonly severity: 'info' | 'warning' | 'error';
44
+ readonly detail: string;
45
+ }
46
+ /** Aggregate counts. */
47
+ export interface StatSummary {
48
+ readonly total: number;
49
+ readonly consistent: number;
50
+ readonly inconsistent: number;
51
+ readonly unparsed: number;
52
+ }
53
+ /** Thrown for an impossible recomputation request (bad df/statistic). */
54
+ export declare class StatInputError extends Error {
55
+ /** Stable code. */
56
+ readonly code: 'INVALID_INPUT' | 'OUT_OF_DOMAIN';
57
+ constructor(code: 'INVALID_INPUT' | 'OUT_OF_DOMAIN', message: string);
58
+ }
59
+ /**
60
+ * Recompute the two-tailed (t/r/z) or upper-tail (F/χ²) p value.
61
+ * @param input - statistic kind, value and df.
62
+ * @returns the recomputed p value.
63
+ * @throws StatInputError when the request is outside the distribution's domain.
64
+ */
65
+ export declare function recomputeP(input: {
66
+ statistic: StatisticKind;
67
+ value: number;
68
+ df: readonly number[];
69
+ }): number;
70
+ /** Judge one reported p against the recomputed one. */
71
+ export declare function judgeP(input: {
72
+ pRaw: string;
73
+ pKind: 'equal' | 'less' | 'greater';
74
+ recomputed: number;
75
+ }): {
76
+ status: 'consistent' | 'inconsistent';
77
+ issue?: StatIssue;
78
+ detail: string;
79
+ };
80
+ /**
81
+ * Analyze a block of text.
82
+ * @param text - the manuscript text (untrusted data).
83
+ * @param options - `maxFindings` caps the output (default 500).
84
+ * @returns the findings and their aggregate counts.
85
+ */
86
+ export declare function analyzeText(text: string, options?: {
87
+ maxFindings?: number;
88
+ }): {
89
+ findings: StatFinding[];
90
+ summary: StatSummary;
91
+ };
92
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.d.ts","source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