dsh-statcheck 0.0.0-stage → 0.1.1
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/CHANGELOG.md +53 -0
- package/LICENSE +201 -0
- package/README-zh.md +117 -0
- package/README.md +116 -2
- package/SECURITY.md +19 -0
- package/THIRD_PARTY_NOTICES.md +10 -0
- package/cordis.patch.yml +18 -0
- package/lib/check.d.ts +92 -0
- package/lib/check.d.ts.map +1 -0
- package/lib/check.js +250 -0
- package/lib/check.js.map +1 -0
- package/lib/config.d.ts +37 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +44 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +36 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +50 -0
- package/lib/index.js.map +1 -0
- package/lib/math.d.ts +76 -0
- package/lib/math.d.ts.map +1 -0
- package/lib/math.js +218 -0
- package/lib/math.js.map +1 -0
- package/lib/report.d.ts +41 -0
- package/lib/report.d.ts.map +1 -0
- package/lib/report.js +91 -0
- package/lib/report.js.map +1 -0
- package/lib/runtime.d.ts +104 -0
- package/lib/runtime.d.ts.map +1 -0
- package/lib/runtime.js +235 -0
- package/lib/runtime.js.map +1 -0
- package/lib/tools/shared.d.ts +127 -0
- package/lib/tools/shared.d.ts.map +1 -0
- package/lib/tools/shared.js +61 -0
- package/lib/tools/shared.js.map +1 -0
- package/lib/tools/stat-check.d.ts +12 -0
- package/lib/tools/stat-check.d.ts.map +1 -0
- package/lib/tools/stat-check.js +83 -0
- package/lib/tools/stat-check.js.map +1 -0
- package/lib/tools/stat-recompute.d.ts +12 -0
- package/lib/tools/stat-recompute.d.ts.map +1 -0
- package/lib/tools/stat-recompute.js +82 -0
- package/lib/tools/stat-recompute.js.map +1 -0
- package/lib/tools/stat-report.d.ts +10 -0
- package/lib/tools/stat-report.d.ts.map +1 -0
- package/lib/tools/stat-report.js +66 -0
- package/lib/tools/stat-report.js.map +1 -0
- package/lib/version.d.ts +7 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +7 -0
- package/lib/version.js.map +1 -0
- package/package.json +84 -4
- package/src/check.ts +308 -0
- package/src/config.ts +71 -0
- package/src/index.ts +75 -0
- package/src/math.ts +205 -0
- package/src/report.ts +113 -0
- package/src/runtime.ts +293 -0
- package/src/tools/shared.ts +77 -0
- package/src/tools/stat-check.ts +83 -0
- package/src/tools/stat-recompute.ts +82 -0
- package/src/tools/stat-report.ts +68 -0
- package/src/version.ts +7 -0
package/lib/check.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
import { stableId } from '@perrylink/dsh-research-core';
|
|
14
|
+
import { chiSquareUpperP, fUpperP, rTwoTailedP, tTwoTailedP, zTwoTailedP } from "./math.js";
|
|
15
|
+
const P_PATTERN = /\bp\s*(<|>|=|≤|≥)\s*(\.\d+|\d+\.?\d*)/u;
|
|
16
|
+
const CI_PATTERN = /(?:9[05]%\s*)?(?:CI|confidence interval)\s*[:=]?\s*\[?\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)/iu;
|
|
17
|
+
const WINDOW = 120;
|
|
18
|
+
/** Thrown for an impossible recomputation request (bad df/statistic). */
|
|
19
|
+
export class StatInputError extends Error {
|
|
20
|
+
/** Stable code. */
|
|
21
|
+
code;
|
|
22
|
+
constructor(code, message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'StatInputError';
|
|
25
|
+
this.code = code;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Parse the statistic candidates in one text. */
|
|
29
|
+
function candidatesOf(text) {
|
|
30
|
+
const candidates = [];
|
|
31
|
+
const add = (match, kind, statistic, df) => {
|
|
32
|
+
candidates.push({ kind, statistic, df, start: match.index, end: match.index + match[0].length, text: match[0] });
|
|
33
|
+
};
|
|
34
|
+
for (const match of text.matchAll(/\bt\s*\(\s*(\d+(?:\.\d+)?)\s*\)\s*=\s*(-?\d+(?:\.\d+)?)/gu)) {
|
|
35
|
+
add(match, 't', Number(match[2]), [Number(match[1])]);
|
|
36
|
+
}
|
|
37
|
+
for (const match of text.matchAll(/\bF\s*\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*\)\s*=\s*(-?\d+(?:\.\d+)?)/gu)) {
|
|
38
|
+
add(match, 'F', Number(match[3]), [Number(match[1]), Number(match[2])]);
|
|
39
|
+
}
|
|
40
|
+
for (const match of text.matchAll(/(?:χ²|χ2|X²|X2)\s*\(\s*(\d+(?:\.\d+)?)\s*\)\s*=\s*(-?\d+(?:\.\d+)?)/gu)) {
|
|
41
|
+
add(match, 'chi2', Number(match[2]), [Number(match[1])]);
|
|
42
|
+
}
|
|
43
|
+
for (const match of text.matchAll(/\br\s*\(\s*(\d+(?:\.\d+)?)\s*\)\s*=\s*(-?\.?\d+(?:\.\d+)?)/gu)) {
|
|
44
|
+
add(match, 'r', Number(match[2]), [Number(match[1])]);
|
|
45
|
+
}
|
|
46
|
+
for (const match of text.matchAll(/\bz\s*=\s*(-?\d+(?:\.\d+)?)/gu)) {
|
|
47
|
+
add(match, 'z', Number(match[1]), []);
|
|
48
|
+
}
|
|
49
|
+
return candidates.sort((left, right) => left.start - right.start);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Recompute the two-tailed (t/r/z) or upper-tail (F/χ²) p value.
|
|
53
|
+
* @param input - statistic kind, value and df.
|
|
54
|
+
* @returns the recomputed p value.
|
|
55
|
+
* @throws StatInputError when the request is outside the distribution's domain.
|
|
56
|
+
*/
|
|
57
|
+
export function recomputeP(input) {
|
|
58
|
+
const { statistic, value } = input;
|
|
59
|
+
const df = [...input.df];
|
|
60
|
+
if (!Number.isFinite(value))
|
|
61
|
+
throw new StatInputError('INVALID_INPUT', 'statistic must be a finite number');
|
|
62
|
+
if (statistic === 't') {
|
|
63
|
+
const df1 = df[0];
|
|
64
|
+
if (df1 === undefined || df1 <= 0)
|
|
65
|
+
throw new StatInputError('OUT_OF_DOMAIN', 't requires df > 0');
|
|
66
|
+
return tTwoTailedP(value, df1);
|
|
67
|
+
}
|
|
68
|
+
if (statistic === 'F') {
|
|
69
|
+
const [df1, df2] = df;
|
|
70
|
+
if (df1 === undefined || df2 === undefined || df1 <= 0 || df2 <= 0) {
|
|
71
|
+
throw new StatInputError('OUT_OF_DOMAIN', 'F requires df1 > 0 and df2 > 0');
|
|
72
|
+
}
|
|
73
|
+
if (value < 0)
|
|
74
|
+
throw new StatInputError('OUT_OF_DOMAIN', 'F must be >= 0 (a negative F is not a statistic)');
|
|
75
|
+
return fUpperP(value, df1, df2);
|
|
76
|
+
}
|
|
77
|
+
if (statistic === 'chi2') {
|
|
78
|
+
const df1 = df[0];
|
|
79
|
+
if (df1 === undefined || df1 <= 0)
|
|
80
|
+
throw new StatInputError('OUT_OF_DOMAIN', 'chi-square requires df > 0');
|
|
81
|
+
if (value < 0)
|
|
82
|
+
throw new StatInputError('OUT_OF_DOMAIN', 'chi-square must be >= 0 (a negative χ² is not a statistic)');
|
|
83
|
+
return chiSquareUpperP(value, df1);
|
|
84
|
+
}
|
|
85
|
+
if (statistic === 'r') {
|
|
86
|
+
const df1 = df[0];
|
|
87
|
+
if (df1 === undefined || df1 <= 0)
|
|
88
|
+
throw new StatInputError('OUT_OF_DOMAIN', 'r requires df > 0');
|
|
89
|
+
if (Math.abs(value) > 1)
|
|
90
|
+
throw new StatInputError('OUT_OF_DOMAIN', 'r must be in [-1, 1]');
|
|
91
|
+
return rTwoTailedP(value, df1);
|
|
92
|
+
}
|
|
93
|
+
return zTwoTailedP(value);
|
|
94
|
+
}
|
|
95
|
+
/** Decimal places in a reported p string. */
|
|
96
|
+
function decimalsOf(raw) {
|
|
97
|
+
const dot = raw.indexOf('.');
|
|
98
|
+
return dot === -1 ? 0 : raw.length - dot - 1;
|
|
99
|
+
}
|
|
100
|
+
/** Judge one reported p against the recomputed one. */
|
|
101
|
+
export function judgeP(input) {
|
|
102
|
+
const { pRaw, pKind, recomputed } = input;
|
|
103
|
+
const reported = Number(pRaw.startsWith('.') ? `0${pRaw}` : pRaw);
|
|
104
|
+
if (!Number.isFinite(reported) || reported < 0 || reported > 1) {
|
|
105
|
+
return {
|
|
106
|
+
status: 'inconsistent',
|
|
107
|
+
issue: 'format',
|
|
108
|
+
detail: `the reported p ${pKind === 'equal' ? '=' : pKind === 'less' ? '<' : '>'} ${pRaw} is not a probability in [0, 1]`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const shown = recomputed.toFixed(4);
|
|
112
|
+
if (pKind === 'equal' && reported === 0) {
|
|
113
|
+
return {
|
|
114
|
+
status: 'inconsistent',
|
|
115
|
+
issue: 'format',
|
|
116
|
+
detail: `the report says p = ${pRaw}; an exact zero p cannot follow from a finite statistic — APA style requires p < .001 (recomputed ${shown})`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (pKind === 'equal') {
|
|
120
|
+
const tolerance = 0.5 * 10 ** -decimalsOf(pRaw) + 0.001;
|
|
121
|
+
if (Math.abs(recomputed - reported) <= tolerance) {
|
|
122
|
+
return { status: 'consistent', detail: `reported p = ${pRaw}; recomputed ${shown} (within rounding)` };
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
status: 'inconsistent',
|
|
126
|
+
issue: 'p-value',
|
|
127
|
+
detail: `reported p = ${pRaw}, but the reported statistic gives recomputed p = ${shown}`,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (pKind === 'less') {
|
|
131
|
+
if (recomputed < reported - 1e-12) {
|
|
132
|
+
return { status: 'consistent', detail: `reported p < ${pRaw}; recomputed ${shown}` };
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
status: 'inconsistent',
|
|
136
|
+
issue: 'p-threshold',
|
|
137
|
+
detail: `reported p < ${pRaw}, but the reported statistic gives p = ${shown}`,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (recomputed > reported + 1e-12) {
|
|
141
|
+
return { status: 'consistent', detail: `reported p > ${pRaw}; recomputed ${shown}` };
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
status: 'inconsistent',
|
|
145
|
+
issue: 'p-threshold',
|
|
146
|
+
detail: `reported p > ${pRaw}, but the reported statistic gives p = ${shown}`,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** True when a p value is significant at .05. */
|
|
150
|
+
function isSignificant(pValue) {
|
|
151
|
+
return pValue < 0.05;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Analyze a block of text.
|
|
155
|
+
* @param text - the manuscript text (untrusted data).
|
|
156
|
+
* @param options - `maxFindings` caps the output (default 500).
|
|
157
|
+
* @returns the findings and their aggregate counts.
|
|
158
|
+
*/
|
|
159
|
+
export function analyzeText(text, options = {}) {
|
|
160
|
+
const maxFindings = options.maxFindings ?? 500;
|
|
161
|
+
const candidates = candidatesOf(text);
|
|
162
|
+
const findings = [];
|
|
163
|
+
for (const [index, candidate] of candidates.entries()) {
|
|
164
|
+
if (findings.length >= maxFindings)
|
|
165
|
+
break;
|
|
166
|
+
const next = candidates[index + 1]?.start ?? text.length;
|
|
167
|
+
const windowEnd = Math.min(next, candidate.end + WINDOW);
|
|
168
|
+
const window = text.slice(candidate.end, windowEnd);
|
|
169
|
+
const pMatch = P_PATTERN.exec(window);
|
|
170
|
+
const ciMatch = CI_PATTERN.exec(window);
|
|
171
|
+
const findingId = stableId('st', [candidate.kind, candidate.text, candidate.start]);
|
|
172
|
+
const base = {
|
|
173
|
+
findingId,
|
|
174
|
+
statistic: candidate.kind,
|
|
175
|
+
text: candidate.text,
|
|
176
|
+
charStart: candidate.start,
|
|
177
|
+
charEnd: candidate.end,
|
|
178
|
+
df: candidate.df,
|
|
179
|
+
};
|
|
180
|
+
let recomputed;
|
|
181
|
+
try {
|
|
182
|
+
recomputed = recomputeP({ statistic: candidate.kind, value: candidate.statistic, df: candidate.df });
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
findings.push({
|
|
186
|
+
...base,
|
|
187
|
+
reported: { statistic: candidate.statistic },
|
|
188
|
+
recomputed: { p: Number.NaN },
|
|
189
|
+
status: 'inconsistent',
|
|
190
|
+
issue: 'df',
|
|
191
|
+
severity: 'error',
|
|
192
|
+
detail: `cannot recompute: ${error.message}`,
|
|
193
|
+
});
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (pMatch === null) {
|
|
197
|
+
findings.push({
|
|
198
|
+
...base,
|
|
199
|
+
reported: { statistic: candidate.statistic },
|
|
200
|
+
recomputed: { p: recomputed },
|
|
201
|
+
status: 'unparsed',
|
|
202
|
+
severity: 'info',
|
|
203
|
+
detail: `statistic parsed (recomputed p = ${recomputed.toFixed(4)}), but no p value was found next to it`,
|
|
204
|
+
});
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const pKind = pMatch[1] === '<' || pMatch[1] === '≤' ? 'less' : pMatch[1] === '>' || pMatch[1] === '≥' ? 'greater' : 'equal';
|
|
208
|
+
const pRaw = pMatch[2];
|
|
209
|
+
const judgment = judgeP({ pRaw, pKind, recomputed });
|
|
210
|
+
const ci = ciMatch === null ? undefined : [Number(ciMatch[1]), Number(ciMatch[2])];
|
|
211
|
+
let status = judgment.status;
|
|
212
|
+
let issue = judgment.issue;
|
|
213
|
+
let detail = judgment.detail;
|
|
214
|
+
let severity = status === 'consistent' ? 'info' : 'error';
|
|
215
|
+
if (ci !== undefined && status === 'consistent') {
|
|
216
|
+
const reportedP = Number(pRaw.startsWith('.') ? `0${pRaw}` : pRaw);
|
|
217
|
+
const significant = pKind === 'equal' ? isSignificant(reportedP) : isSignificant(recomputed);
|
|
218
|
+
const excludesZero = ci[0] > 0 || ci[1] < 0;
|
|
219
|
+
if (significant && !excludesZero) {
|
|
220
|
+
status = 'inconsistent';
|
|
221
|
+
issue = 'ci';
|
|
222
|
+
severity = 'error';
|
|
223
|
+
detail = `p = ${pRaw} is significant, but the reported 95% CI [${ci[0]}, ${ci[1]}] includes 0`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
findings.push({
|
|
227
|
+
...base,
|
|
228
|
+
reported: {
|
|
229
|
+
statistic: candidate.statistic,
|
|
230
|
+
p: pRaw,
|
|
231
|
+
pKind,
|
|
232
|
+
pValue: Number(pRaw.startsWith('.') ? `0${pRaw}` : pRaw),
|
|
233
|
+
...(ci === undefined ? {} : { ci }),
|
|
234
|
+
},
|
|
235
|
+
recomputed: { p: recomputed },
|
|
236
|
+
status,
|
|
237
|
+
...(issue === undefined ? {} : { issue }),
|
|
238
|
+
severity,
|
|
239
|
+
detail,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
const summary = {
|
|
243
|
+
total: findings.length,
|
|
244
|
+
consistent: findings.filter(finding => finding.status === 'consistent').length,
|
|
245
|
+
inconsistent: findings.filter(finding => finding.status === 'inconsistent').length,
|
|
246
|
+
unparsed: findings.filter(finding => finding.status === 'unparsed').length,
|
|
247
|
+
};
|
|
248
|
+
return { findings, summary };
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=check.js.map
|
package/lib/check.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,8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CAAC,OAAO,CAAC,MAAM,KAAK,cAAc,CAAC,CAAC,MAAM;QAClF,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,MAAM;KAC3E,CAAA;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;AAC9B,CAAC"}
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config schema and resolution for `dsh-statcheck`.
|
|
3
|
+
* @module dsh-statcheck/config
|
|
4
|
+
*/
|
|
5
|
+
import z from '@deepseek-ai/schemastery';
|
|
6
|
+
/** Raw plugin config. */
|
|
7
|
+
export interface Config {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/** Store/record root, resolved against the harness working directory. */
|
|
10
|
+
root?: string;
|
|
11
|
+
/** Workspace root that manuscript paths must stay inside. */
|
|
12
|
+
workspaceRoot?: string;
|
|
13
|
+
/** Hard cap on analyzed characters. */
|
|
14
|
+
maxChars?: number;
|
|
15
|
+
/** Hard cap on findings per call. */
|
|
16
|
+
maxFindings?: number;
|
|
17
|
+
/** Persist a snapshot + REP record (default true). */
|
|
18
|
+
persist?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** Fully resolved config. */
|
|
21
|
+
export interface ResolvedConfig {
|
|
22
|
+
readonly enabled: boolean;
|
|
23
|
+
readonly root: string;
|
|
24
|
+
readonly workspaceRoot: string;
|
|
25
|
+
readonly maxChars: number;
|
|
26
|
+
readonly maxFindings: number;
|
|
27
|
+
readonly persist: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Schemastery schema. */
|
|
30
|
+
export declare const Config: z<Config>;
|
|
31
|
+
/**
|
|
32
|
+
* Validate raw values and fill explicit defaults.
|
|
33
|
+
* @param config - raw plugin config.
|
|
34
|
+
* @returns the fully resolved config.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveConfig(config?: Config): ResolvedConfig;
|
|
37
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,yBAAyB;AACzB,MAAM,WAAW,MAAM;IACrB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,qCAAqC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sDAAsD;IACtD,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,6BAA6B;AAC7B,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAED,0BAA0B;AAC1B,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAO3B,CAAA;AASF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,GAAE,MAAW,GAAG,cAAc,CAejE"}
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config schema and resolution for `dsh-statcheck`.
|
|
3
|
+
* @module dsh-statcheck/config
|
|
4
|
+
*/
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import z from '@deepseek-ai/schemastery';
|
|
7
|
+
/** Schemastery schema. */
|
|
8
|
+
export const Config = z.object({
|
|
9
|
+
enabled: z.boolean().default(true),
|
|
10
|
+
root: z.string().default('.statcheck'),
|
|
11
|
+
workspaceRoot: z.string(),
|
|
12
|
+
maxChars: z.number().default(2_000_000),
|
|
13
|
+
maxFindings: z.number().default(500),
|
|
14
|
+
persist: z.boolean().default(true),
|
|
15
|
+
});
|
|
16
|
+
/** Throw unless the value is a positive safe integer. */
|
|
17
|
+
function assertPositiveInt(name, value) {
|
|
18
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
19
|
+
throw new TypeError(`${name} must be a positive safe integer, got ${String(value)}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validate raw values and fill explicit defaults.
|
|
24
|
+
* @param config - raw plugin config.
|
|
25
|
+
* @returns the fully resolved config.
|
|
26
|
+
*/
|
|
27
|
+
export function resolveConfig(config = {}) {
|
|
28
|
+
const root = config.root ?? '.statcheck';
|
|
29
|
+
if (typeof root !== 'string' || root.trim() === '')
|
|
30
|
+
throw new TypeError('root must be a non-empty path');
|
|
31
|
+
const maxChars = config.maxChars ?? 2_000_000;
|
|
32
|
+
const maxFindings = config.maxFindings ?? 500;
|
|
33
|
+
assertPositiveInt('maxChars', maxChars);
|
|
34
|
+
assertPositiveInt('maxFindings', maxFindings);
|
|
35
|
+
return {
|
|
36
|
+
enabled: config.enabled ?? true,
|
|
37
|
+
root: path.resolve(root),
|
|
38
|
+
workspaceRoot: path.resolve(config.workspaceRoot ?? process.cwd()),
|
|
39
|
+
maxChars,
|
|
40
|
+
maxFindings,
|
|
41
|
+
persist: config.persist ?? true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,CAAC,MA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Aa,EAAE,WAAW,CAAC,CAAA;IAC7C,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;QAC/B,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QACxB,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAClE,QAAQ;QACR,WAAW;QACX,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;KAChC,CAAA;AACH,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dsh-statcheck` — recompute reported statistics, flag self-inconsistency.
|
|
3
|
+
*
|
|
4
|
+
* Three tools, one job: parse APA-style reports, recompute the p value from the
|
|
5
|
+
* reported statistic, and show both numbers. It is arithmetic, not accusation:
|
|
6
|
+
* findings are candidates for human review, never a conclusion about authors.
|
|
7
|
+
*
|
|
8
|
+
* Function plugin — no default export.
|
|
9
|
+
* @module dsh-statcheck
|
|
10
|
+
*/
|
|
11
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
12
|
+
import { Config, resolveConfig, type Config as ConfigShape } from './config.ts';
|
|
13
|
+
/** Cordis plugin name. */
|
|
14
|
+
export declare const name = "statcheck";
|
|
15
|
+
/** The tool registry is required; the REP service is optional. */
|
|
16
|
+
export declare const inject: string[];
|
|
17
|
+
export { Config, resolveConfig };
|
|
18
|
+
export type { ConfigShape };
|
|
19
|
+
export type { ResolvedConfig } from './config.ts';
|
|
20
|
+
export { VERSION } from './version.ts';
|
|
21
|
+
export { chiSquareUpperP, fUpperP, incompleteBeta, logGamma, normalCdf, rTwoTailedP, tTwoTailedP, upperGamma, zTwoTailedP, } from './math.ts';
|
|
22
|
+
export { analyzeText, judgeP, recomputeP, StatInputError } from './check.ts';
|
|
23
|
+
export type { StatFinding, StatIssue, StatisticKind, StatStatus, StatSummary } from './check.ts';
|
|
24
|
+
export { findingsToMarkdown, findingsToSarif } from './report.ts';
|
|
25
|
+
export { StatcheckError, StatcheckRuntime, findingToCheck } from './runtime.ts';
|
|
26
|
+
export type { EvidencePort, StatCheckRequest, StatCheckResult, StatcheckErrorCode, StatcheckRuntimeOptions, } from './runtime.ts';
|
|
27
|
+
export { makeStatCheckTool } from './tools/stat-check.ts';
|
|
28
|
+
export { makeStatRecomputeTool } from './tools/stat-recompute.ts';
|
|
29
|
+
export { makeStatReportTool } from './tools/stat-report.ts';
|
|
30
|
+
/**
|
|
31
|
+
* Mount the three tools.
|
|
32
|
+
* @param ctx - the plugin context (host).
|
|
33
|
+
* @param config - raw plugin config.
|
|
34
|
+
*/
|
|
35
|
+
export declare function apply(ctx: Context, config: ConfigShape): void;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,MAAM,IAAI,WAAW,EAAE,MAAM,aAAa,CAAA;AAM/E,0BAA0B;AAC1B,eAAO,MAAM,IAAI,cAAc,CAAA;AAE/B,kEAAkE;AAClE,eAAO,MAAM,MAAM,UAAY,CAAA;AAE/B,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;AAChC,YAAY,EAAE,WAAW,EAAE,CAAA;AAC3B,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EACL,eAAe,EACf,OAAO,EACP,cAAc,EACd,QAAQ,EACR,SAAS,EACT,WAAW,EACX,WAAW,EACX,UAAU,EACV,WAAW,GACZ,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC5E,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAChG,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC/E,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE3D;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAe7D"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dsh-statcheck` — recompute reported statistics, flag self-inconsistency.
|
|
3
|
+
*
|
|
4
|
+
* Three tools, one job: parse APA-style reports, recompute the p value from the
|
|
5
|
+
* reported statistic, and show both numbers. It is arithmetic, not accusation:
|
|
6
|
+
* findings are candidates for human review, never a conclusion about authors.
|
|
7
|
+
*
|
|
8
|
+
* Function plugin — no default export.
|
|
9
|
+
* @module dsh-statcheck
|
|
10
|
+
*/
|
|
11
|
+
import { Config, resolveConfig } from "./config.js";
|
|
12
|
+
import { StatcheckRuntime } from "./runtime.js";
|
|
13
|
+
import { makeStatCheckTool } from "./tools/stat-check.js";
|
|
14
|
+
import { makeStatRecomputeTool } from "./tools/stat-recompute.js";
|
|
15
|
+
import { makeStatReportTool } from "./tools/stat-report.js";
|
|
16
|
+
/** Cordis plugin name. */
|
|
17
|
+
export const name = 'statcheck';
|
|
18
|
+
/** The tool registry is required; the REP service is optional. */
|
|
19
|
+
export const inject = ['tools'];
|
|
20
|
+
export { Config, resolveConfig };
|
|
21
|
+
export { VERSION } from "./version.js";
|
|
22
|
+
export { chiSquareUpperP, fUpperP, incompleteBeta, logGamma, normalCdf, rTwoTailedP, tTwoTailedP, upperGamma, zTwoTailedP, } from "./math.js";
|
|
23
|
+
export { analyzeText, judgeP, recomputeP, StatInputError } from "./check.js";
|
|
24
|
+
export { findingsToMarkdown, findingsToSarif } from "./report.js";
|
|
25
|
+
export { StatcheckError, StatcheckRuntime, findingToCheck } from "./runtime.js";
|
|
26
|
+
export { makeStatCheckTool } from "./tools/stat-check.js";
|
|
27
|
+
export { makeStatRecomputeTool } from "./tools/stat-recompute.js";
|
|
28
|
+
export { makeStatReportTool } from "./tools/stat-report.js";
|
|
29
|
+
/**
|
|
30
|
+
* Mount the three tools.
|
|
31
|
+
* @param ctx - the plugin context (host).
|
|
32
|
+
* @param config - raw plugin config.
|
|
33
|
+
*/
|
|
34
|
+
export function apply(ctx, config) {
|
|
35
|
+
const resolved = resolveConfig(config);
|
|
36
|
+
const logger = ctx.logger('statcheck');
|
|
37
|
+
if (!resolved.enabled) {
|
|
38
|
+
logger.info('disabled: enabled is false — no tools are mounted');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const service = ctx.get('researchEvidence');
|
|
42
|
+
const runtime = new StatcheckRuntime({ config: resolved, ...(service === undefined ? {} : { service }) });
|
|
43
|
+
if (service === undefined) {
|
|
44
|
+
logger.info(`ctx.researchEvidence is not mounted; using a local core store under ${resolved.root}`);
|
|
45
|
+
}
|
|
46
|
+
ctx.effect(() => ctx.tools.register(makeStatCheckTool(runtime)), 'statcheck: stat_check tool');
|
|
47
|
+
ctx.effect(() => ctx.tools.register(makeStatRecomputeTool(runtime)), 'statcheck: stat_recompute tool');
|
|
48
|
+
ctx.effect(() => ctx.tools.register(makeStatReportTool()), 'statcheck: stat_report tool');
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,MAAM,EAAE,aAAa,EAA8B,MAAM,aAAa,CAAA;AAC/E,OAAO,EAAE,gBAAgB,EAAqB,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE3D,0BAA0B;AAC1B,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAA;AAE/B,kEAAkE;AAClE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,CAAA;AAE/B,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;AAGhC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EACL,eAAe,EACf,OAAO,EACP,cAAc,EACd,QAAQ,EACR,SAAS,EACT,WAAW,EACX,WAAW,EACX,UAAU,EACV,WAAW,GACZ,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE5E,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAQ/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE3D;;;;GAIG;AACH,MAAM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
4
|
+
* Implementations: Lanczos log-gamma, regularized incomplete beta (continued
|
|
5
|
+
* fraction), regularized upper incomplete gamma (series + continued fraction),
|
|
6
|
+
* and the normal CDF via an error-function approximation. Accuracy is ~1e-10
|
|
7
|
+
* for the beta/gamma paths, enough for p-values reported to three decimals.
|
|
8
|
+
*
|
|
9
|
+
* Sources are the standard Numerical Recipes formulas (public-domain algorithms,
|
|
10
|
+
* reimplemented in TypeScript).
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-statcheck/math
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Log-gamma (Lanczos approximation).
|
|
16
|
+
* @param value - a positive number.
|
|
17
|
+
* @returns ln Γ(value).
|
|
18
|
+
*/
|
|
19
|
+
export declare function logGamma(value: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Regularized incomplete beta I_x(a, b).
|
|
22
|
+
* @param a - first shape parameter.
|
|
23
|
+
* @param b - second shape parameter.
|
|
24
|
+
* @param x - evaluation point in [0, 1].
|
|
25
|
+
* @returns I_x(a, b) in [0, 1].
|
|
26
|
+
*/
|
|
27
|
+
export declare function incompleteBeta(a: number, b: number, x: number): number;
|
|
28
|
+
/**
|
|
29
|
+
* Regularized upper incomplete gamma Q(a, x).
|
|
30
|
+
* @param a - shape parameter.
|
|
31
|
+
* @param x - evaluation point.
|
|
32
|
+
* @returns Q(a, x) in [0, 1].
|
|
33
|
+
*/
|
|
34
|
+
export declare function upperGamma(a: number, x: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* Standard normal CDF (Abramowitz–Stegun 7.1.26; |error| < 1.5e-7).
|
|
37
|
+
* @param value - the z score.
|
|
38
|
+
* @returns Φ(value).
|
|
39
|
+
*/
|
|
40
|
+
export declare function normalCdf(value: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Two-tailed p for Student's t.
|
|
43
|
+
* @param t - the t statistic (absolute value is used).
|
|
44
|
+
* @param df - degrees of freedom (> 0).
|
|
45
|
+
* @returns the two-tailed p value.
|
|
46
|
+
*/
|
|
47
|
+
export declare function tTwoTailedP(t: number, df: number): number;
|
|
48
|
+
/**
|
|
49
|
+
* Upper-tail p for the F distribution.
|
|
50
|
+
* @param f - the F statistic.
|
|
51
|
+
* @param df1 - numerator degrees of freedom.
|
|
52
|
+
* @param df2 - denominator degrees of freedom.
|
|
53
|
+
* @returns P(F >= f).
|
|
54
|
+
*/
|
|
55
|
+
export declare function fUpperP(f: number, df1: number, df2: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Upper-tail p for the chi-square distribution.
|
|
58
|
+
* @param chi2 - the chi-square statistic.
|
|
59
|
+
* @param df - degrees of freedom (> 0).
|
|
60
|
+
* @returns P(χ² >= chi2).
|
|
61
|
+
*/
|
|
62
|
+
export declare function chiSquareUpperP(chi2: number, df: number): number;
|
|
63
|
+
/**
|
|
64
|
+
* Two-tailed p for a correlation r with df = n - 2.
|
|
65
|
+
* @param r - the correlation.
|
|
66
|
+
* @param df - degrees of freedom (> 0).
|
|
67
|
+
* @returns the two-tailed p value.
|
|
68
|
+
*/
|
|
69
|
+
export declare function rTwoTailedP(r: number, df: number): number;
|
|
70
|
+
/**
|
|
71
|
+
* Two-tailed p for a z statistic.
|
|
72
|
+
* @param z - the z statistic.
|
|
73
|
+
* @returns the two-tailed p value.
|
|
74
|
+
*/
|
|
75
|
+
export declare function zTwoTailedP(z: number): number;
|
|
76
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO9C;AAyCD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAMtE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAkCvD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAS/C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAIzD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAInE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAIhE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAMzD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|