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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stat-recompute.js","sourceRoot":"","sources":["../../src/tools/stat-recompute.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAyB,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;QACvC,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC7B,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;QAChD,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrB,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QAC1B,KAAK,EAAE,YAAY;KACpB;CACO,CAAA;AAEV;;;;GAIG;AACH,MAAM,UAAU,qBAAqB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AC,EAAE;wBACJ,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;iBACxK,CAAA;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,cAAc;oBAAE,OAAO,EAAE,EAAE,EAAE,KAAc,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,CAAA;gBACvH,MAAM,KAAK,CAAA;YACb,CAAC;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `stat_report` — render findings as Markdown and SARIF 2.1.0.
3
+ * @module dsh-statcheck/tools/stat-report
4
+ */
5
+ /**
6
+ * Build the `stat_report` tool.
7
+ * @returns the tool definition.
8
+ */
9
+ export declare function makeStatReportTool(): import("@deepseek-ai/dsh-tools").ToolDefinition;
10
+ //# sourceMappingURL=stat-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stat-report.d.ts","sourceRoot":"","sources":["../../src/tools/stat-report.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH;;;GAGG;AACH,wBAAgB,kBAAkB,oDAwCjC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * `stat_report` — render findings as Markdown and SARIF 2.1.0.
3
+ * @module dsh-statcheck/tools/stat-report
4
+ */
5
+ import { defineTool } from '@deepseek-ai/dsh-tools';
6
+ import { findingsToMarkdown, findingsToSarif } from "../report.js";
7
+ import { VERSION } from "../version.js";
8
+ import { ERROR_SCHEMA, SUMMARY_SCHEMA } from "./shared.js";
9
+ const OUTPUT_SCHEMA = {
10
+ type: 'object',
11
+ additionalProperties: false,
12
+ properties: {
13
+ ok: { type: 'boolean', required: true },
14
+ markdown: { type: 'string' },
15
+ sarif: { type: 'json' },
16
+ summary: SUMMARY_SCHEMA,
17
+ error: ERROR_SCHEMA,
18
+ },
19
+ };
20
+ /**
21
+ * Build the `stat_report` tool.
22
+ * @returns the tool definition.
23
+ */
24
+ export function makeStatReportTool() {
25
+ return defineTool({
26
+ name: 'stat_report',
27
+ description: [
28
+ 'Render stat_check findings as a Markdown report and a SARIF 2.1.0 log (dsh-statcheck).',
29
+ '',
30
+ 'Pass the `findings` array returned by stat_check. The Markdown table names the reported statistic, the recomputed p, the verdict and the character range; the SARIF log carries one error result per inconsistent finding for CI/code-scanning consumers.',
31
+ '',
32
+ 'The report says explicitly that a finding means "the reported p does not follow from the reported statistic" — not misconduct.',
33
+ ].join('\n'),
34
+ parameters: {
35
+ findings: { type: 'array', items: { type: 'json' }, required: true, description: 'Findings from stat_check.' },
36
+ text: { type: 'string', description: 'Original manuscript text; when provided, SARIF line/column are mapped from each finding charStart.' },
37
+ },
38
+ output: {
39
+ schema: OUTPUT_SCHEMA,
40
+ render: (_args, value) => {
41
+ const result = value;
42
+ if (!result.ok)
43
+ return [{ type: 'text', text: `stat_report failed (${result.error.code}): ${result.error.message}` }];
44
+ return [{ type: 'text', text: result.markdown }];
45
+ },
46
+ },
47
+ async execute(args) {
48
+ const request = args;
49
+ const findings = Array.isArray(request.findings) ? request.findings : [];
50
+ const text = typeof request.text === 'string' ? request.text : undefined;
51
+ const summary = {
52
+ total: findings.length,
53
+ consistent: findings.filter(finding => finding.status === 'consistent').length,
54
+ inconsistent: findings.filter(finding => finding.status === 'inconsistent').length,
55
+ unparsed: findings.filter(finding => finding.status === 'unparsed').length,
56
+ };
57
+ return {
58
+ ok: true,
59
+ markdown: findingsToMarkdown(findings, summary),
60
+ sarif: findingsToSarif(findings, VERSION, text),
61
+ summary,
62
+ };
63
+ },
64
+ });
65
+ }
66
+ //# sourceMappingURL=stat-report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stat-report.js","sourceRoot":"","sources":["../../src/tools/stat-report.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE1D,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;QACvC,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC5B,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QACvB,OAAO,EAAE,cAAc;QACvB,KAAK,EAAE,YAAY;KACpB;CACO,CAAA;AAEV;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE;YACX,wFAAwF;YACxF,EAAE;YACF,2PAA2P;YAC3P,EAAE;YACF,gIAAgI;SACjI,CAAC,IAAI,CAAC,IAAI,CAAC;QACZ,UAAU,EAAE;YACV,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,2BAA2B,EAAE;YAC9G,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,oGAAoG,EAAE;SAC5I;QACD,MAAM,EAAE;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;gBACjB,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC;gBAC/C,KAAK,EAAE,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAU;gBACxD,OAAO;aACR,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Package version, single-sourced (pinned to package.json by the test suite).
3
+ * @module dsh-statcheck/version
4
+ */
5
+ /** The package version. */
6
+ export declare const VERSION = "0.1.0";
7
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,2BAA2B;AAC3B,eAAO,MAAM,OAAO,UAAU,CAAA"}
package/lib/version.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Package version, single-sourced (pinned to package.json by the test suite).
3
+ * @module dsh-statcheck/version
4
+ */
5
+ /** The package version. */
6
+ export const VERSION = '0.1.0';
7
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,84 @@
1
1
  {
2
2
  "name": "dsh-statcheck",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Recompute the statistics reported in a manuscript and flag self-inconsistent p values for DeepSeek Harness: APA-style t/F/chi-square/r/z parsing, two-tailed and upper-tail p values from zero-dependency distributions, CI-versus-p checks, exact character locators, Markdown and SARIF 2.1.0 output, and a REP v1 evidence record. Arithmetic, not accusation.",
5
+ "author": "dsh-statcheck contributors",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/PerryLink/dsh-statcheck.git"
9
+ },
10
+ "homepage": "https://github.com/PerryLink/dsh-statcheck#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/PerryLink/dsh-statcheck/issues"
13
+ },
14
+ "private": false,
15
+ "type": "module",
16
+ "main": "./lib/index.js",
17
+ "types": "./lib/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./lib/index.d.ts",
21
+ "default": "./lib/index.js"
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "files": [
26
+ "lib",
27
+ "src",
28
+ "cordis.patch.yml",
29
+ "CHANGELOG.md",
30
+ "README.md",
31
+ "README-zh.md",
32
+ "LICENSE"
33
+ ],
34
+ "sideEffects": false,
35
+ "dsh": {
36
+ "manifestVersion": 1,
37
+ "bundle": {
38
+ "patch": "./cordis.patch.yml"
39
+ }
40
+ },
41
+ "keywords": [
42
+ "dsh",
43
+ "dsh-plugin",
44
+ "deepseek-harness",
45
+ "research",
46
+ "statistics",
47
+ "statcheck",
48
+ "p-value",
49
+ "apa",
50
+ "sarif",
51
+ "rep-v1"
52
+ ],
53
+ "engines": {
54
+ "node": "^22.19.0 || >=24.9.0",
55
+ "dsh": ">=0.2.1-0 <0.3.0 || >=0.2.2-0 <0.3.0"
56
+ },
57
+ "packageManager": "pnpm@12.16.1",
58
+ "peerDependencies": {
59
+ "@deepseek-ai/cordis": "^4.0.5-alpha.1",
60
+ "@deepseek-ai/dsh-tools": ">=0.2.1-0 <0.3.0 || >=0.2.2-0 <0.3.0",
61
+ "@deepseek-ai/schemastery": "^3.18.5-alpha.1",
62
+ "@perrylink/dsh-research-core": "^0.1.0"
63
+ },
64
+ "dependencies": {},
65
+ "devDependencies": {
66
+ "@deepseek-ai/cordis": "^4.1.0",
67
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
68
+ "@deepseek-ai/schemastery": "~3.19.0",
69
+ "@perrylink/dsh-research-core": "file:../dsh-research-core",
70
+ "@types/node": "^22.20.5",
71
+ "typescript": "^5.9.0",
72
+ "vitest": "^3.2.0"
73
+ },
74
+ "scripts": {
75
+ "build": "tsc -p tsconfig.json",
76
+ "clean": "node -e \"require('node:fs').rmSync('lib',{recursive:true,force:true})\"",
77
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json",
78
+ "test": "vitest run",
79
+ "test:watch": "vitest",
80
+ "bench:stats": "pnpm run build && node bench/run-stats.mjs",
81
+ "verify:package": "node scripts/verify-package.mjs"
82
+ },
83
+ "license": "Apache-2.0"
84
+ }
package/src/check.ts ADDED
@@ -0,0 +1,308 @@
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
+
14
+ import { stableId } from '@perrylink/dsh-research-core'
15
+ import { chiSquareUpperP, fUpperP, rTwoTailedP, tTwoTailedP, zTwoTailedP } from './math.ts'
16
+
17
+ /** Supported statistic families. */
18
+ export type StatisticKind = 't' | 'F' | 'chi2' | 'r' | 'z'
19
+
20
+ /** Consistency verdict of one reported statistic. */
21
+ export type StatStatus = 'consistent' | 'inconsistent' | 'unparsed'
22
+
23
+ /** What kind of problem was found. */
24
+ export type StatIssue = 'p-value' | 'p-threshold' | 'ci' | 'format' | 'df'
25
+
26
+ /** One parsed and judged statistical report. */
27
+ export interface StatFinding {
28
+ readonly findingId: string
29
+ readonly statistic: StatisticKind
30
+ /** The matched source text. */
31
+ readonly text: string
32
+ readonly charStart: number
33
+ readonly charEnd: number
34
+ /** Degrees of freedom as reported. */
35
+ readonly df: readonly number[]
36
+ readonly reported: {
37
+ readonly statistic: number
38
+ /** The p value as written (`".018"`, `"<.001"` …). */
39
+ readonly p?: string
40
+ readonly pKind?: 'equal' | 'less' | 'greater'
41
+ readonly pValue?: number
42
+ readonly ci?: readonly [number, number]
43
+ }
44
+ /** The p value recomputed from the reported statistic. */
45
+ readonly recomputed: { readonly p: number }
46
+ readonly status: StatStatus
47
+ readonly issue?: StatIssue
48
+ readonly severity: 'info' | 'warning' | 'error'
49
+ readonly detail: string
50
+ }
51
+
52
+ /** Aggregate counts. */
53
+ export interface StatSummary {
54
+ readonly total: number
55
+ readonly consistent: number
56
+ readonly inconsistent: number
57
+ readonly unparsed: number
58
+ }
59
+
60
+ /** A parsed statistic before judging. */
61
+ interface Candidate {
62
+ readonly kind: StatisticKind
63
+ readonly statistic: number
64
+ readonly df: number[]
65
+ readonly start: number
66
+ readonly end: number
67
+ readonly text: string
68
+ }
69
+
70
+ const P_PATTERN = /\bp\s*(<|>|=|≤|≥)\s*(\.\d+|\d+\.?\d*)/u
71
+ const CI_PATTERN = /(?:9[05]%\s*)?(?:CI|confidence interval)\s*[:=]?\s*\[?\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)/iu
72
+ const WINDOW = 120
73
+
74
+ /** Thrown for an impossible recomputation request (bad df/statistic). */
75
+ export class StatInputError extends Error {
76
+ /** Stable code. */
77
+ readonly code: 'INVALID_INPUT' | 'OUT_OF_DOMAIN'
78
+
79
+ constructor(code: 'INVALID_INPUT' | 'OUT_OF_DOMAIN', message: string) {
80
+ super(message)
81
+ this.name = 'StatInputError'
82
+ this.code = code
83
+ }
84
+ }
85
+
86
+ /** Parse the statistic candidates in one text. */
87
+ function candidatesOf(text: string): Candidate[] {
88
+ const candidates: Candidate[] = []
89
+ const add = (match: RegExpExecArray, kind: StatisticKind, statistic: number, df: number[]): void => {
90
+ candidates.push({ kind, statistic, df, start: match.index, end: match.index + match[0].length, text: match[0] })
91
+ }
92
+ for (const match of text.matchAll(/\bt\s*\(\s*(\d+(?:\.\d+)?)\s*\)\s*=\s*(-?\d+(?:\.\d+)?)/gu)) {
93
+ add(match, 't', Number(match[2]), [Number(match[1])])
94
+ }
95
+ for (const match of text.matchAll(/\bF\s*\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*\)\s*=\s*(-?\d+(?:\.\d+)?)/gu)) {
96
+ add(match, 'F', Number(match[3]), [Number(match[1]), Number(match[2])])
97
+ }
98
+ for (const match of text.matchAll(/(?:χ²|χ2|X²|X2)\s*\(\s*(\d+(?:\.\d+)?)\s*\)\s*=\s*(-?\d+(?:\.\d+)?)/gu)) {
99
+ add(match, 'chi2', Number(match[2]), [Number(match[1])])
100
+ }
101
+ for (const match of text.matchAll(/\br\s*\(\s*(\d+(?:\.\d+)?)\s*\)\s*=\s*(-?\.?\d+(?:\.\d+)?)/gu)) {
102
+ add(match, 'r', Number(match[2]), [Number(match[1])])
103
+ }
104
+ for (const match of text.matchAll(/\bz\s*=\s*(-?\d+(?:\.\d+)?)/gu)) {
105
+ add(match, 'z', Number(match[1]), [])
106
+ }
107
+ return candidates.sort((left, right) => left.start - right.start)
108
+ }
109
+
110
+ /**
111
+ * Recompute the two-tailed (t/r/z) or upper-tail (F/χ²) p value.
112
+ * @param input - statistic kind, value and df.
113
+ * @returns the recomputed p value.
114
+ * @throws StatInputError when the request is outside the distribution's domain.
115
+ */
116
+ export function recomputeP(input: { statistic: StatisticKind; value: number; df: readonly number[] }): number {
117
+ const { statistic, value } = input
118
+ const df = [...input.df]
119
+ if (!Number.isFinite(value)) throw new StatInputError('INVALID_INPUT', 'statistic must be a finite number')
120
+ if (statistic === 't') {
121
+ const df1 = df[0]
122
+ if (df1 === undefined || df1 <= 0) throw new StatInputError('OUT_OF_DOMAIN', 't requires df > 0')
123
+ return tTwoTailedP(value, df1)
124
+ }
125
+ if (statistic === 'F') {
126
+ const [df1, df2] = df
127
+ if (df1 === undefined || df2 === undefined || df1 <= 0 || df2 <= 0) {
128
+ throw new StatInputError('OUT_OF_DOMAIN', 'F requires df1 > 0 and df2 > 0')
129
+ }
130
+ if (value < 0) throw new StatInputError('OUT_OF_DOMAIN', 'F must be >= 0 (a negative F is not a statistic)')
131
+ return fUpperP(value, df1, df2)
132
+ }
133
+ if (statistic === 'chi2') {
134
+ const df1 = df[0]
135
+ if (df1 === undefined || df1 <= 0) throw new StatInputError('OUT_OF_DOMAIN', 'chi-square requires df > 0')
136
+ if (value < 0) throw new StatInputError('OUT_OF_DOMAIN', 'chi-square must be >= 0 (a negative χ² is not a statistic)')
137
+ return chiSquareUpperP(value, df1)
138
+ }
139
+ if (statistic === 'r') {
140
+ const df1 = df[0]
141
+ if (df1 === undefined || df1 <= 0) throw new StatInputError('OUT_OF_DOMAIN', 'r requires df > 0')
142
+ if (Math.abs(value) > 1) throw new StatInputError('OUT_OF_DOMAIN', 'r must be in [-1, 1]')
143
+ return rTwoTailedP(value, df1)
144
+ }
145
+ return zTwoTailedP(value)
146
+ }
147
+
148
+ /** Decimal places in a reported p string. */
149
+ function decimalsOf(raw: string): number {
150
+ const dot = raw.indexOf('.')
151
+ return dot === -1 ? 0 : raw.length - dot - 1
152
+ }
153
+
154
+ /** Judge one reported p against the recomputed one. */
155
+ export function judgeP(input: {
156
+ pRaw: string
157
+ pKind: 'equal' | 'less' | 'greater'
158
+ recomputed: number
159
+ }): { status: 'consistent' | 'inconsistent'; issue?: StatIssue; detail: string } {
160
+ const { pRaw, pKind, recomputed } = input
161
+ const reported = Number(pRaw.startsWith('.') ? `0${pRaw}` : pRaw)
162
+ if (!Number.isFinite(reported) || reported < 0 || reported > 1) {
163
+ return {
164
+ status: 'inconsistent',
165
+ issue: 'format',
166
+ detail: `the reported p ${pKind === 'equal' ? '=' : pKind === 'less' ? '<' : '>'} ${pRaw} is not a probability in [0, 1]`,
167
+ }
168
+ }
169
+ const shown = recomputed.toFixed(4)
170
+ if (pKind === 'equal' && reported === 0) {
171
+ return {
172
+ status: 'inconsistent',
173
+ issue: 'format',
174
+ detail: `the report says p = ${pRaw}; an exact zero p cannot follow from a finite statistic — APA style requires p < .001 (recomputed ${shown})`,
175
+ }
176
+ }
177
+ if (pKind === 'equal') {
178
+ const tolerance = 0.5 * 10 ** -decimalsOf(pRaw) + 0.001
179
+ if (Math.abs(recomputed - reported) <= tolerance) {
180
+ return { status: 'consistent', detail: `reported p = ${pRaw}; recomputed ${shown} (within rounding)` }
181
+ }
182
+ return {
183
+ status: 'inconsistent',
184
+ issue: 'p-value',
185
+ detail: `reported p = ${pRaw}, but the reported statistic gives recomputed p = ${shown}`,
186
+ }
187
+ }
188
+ if (pKind === 'less') {
189
+ if (recomputed < reported - 1e-12) {
190
+ return { status: 'consistent', detail: `reported p < ${pRaw}; recomputed ${shown}` }
191
+ }
192
+ return {
193
+ status: 'inconsistent',
194
+ issue: 'p-threshold',
195
+ detail: `reported p < ${pRaw}, but the reported statistic gives p = ${shown}`,
196
+ }
197
+ }
198
+ if (recomputed > reported + 1e-12) {
199
+ return { status: 'consistent', detail: `reported p > ${pRaw}; recomputed ${shown}` }
200
+ }
201
+ return {
202
+ status: 'inconsistent',
203
+ issue: 'p-threshold',
204
+ detail: `reported p > ${pRaw}, but the reported statistic gives p = ${shown}`,
205
+ }
206
+ }
207
+
208
+ /** True when a p value is significant at .05. */
209
+ function isSignificant(pValue: number): boolean {
210
+ return pValue < 0.05
211
+ }
212
+
213
+ /**
214
+ * Analyze a block of text.
215
+ * @param text - the manuscript text (untrusted data).
216
+ * @param options - `maxFindings` caps the output (default 500).
217
+ * @returns the findings and their aggregate counts.
218
+ */
219
+ export function analyzeText(text: string, options: { maxFindings?: number } = {}): { findings: StatFinding[]; summary: StatSummary } {
220
+ const maxFindings = options.maxFindings ?? 500
221
+ const candidates = candidatesOf(text)
222
+ const findings: StatFinding[] = []
223
+ for (const [index, candidate] of candidates.entries()) {
224
+ if (findings.length >= maxFindings) break
225
+ const next = candidates[index + 1]?.start ?? text.length
226
+ const windowEnd = Math.min(next, candidate.end + WINDOW)
227
+ const window = text.slice(candidate.end, windowEnd)
228
+ const pMatch = P_PATTERN.exec(window)
229
+ const ciMatch = CI_PATTERN.exec(window)
230
+ const findingId = stableId('st', [candidate.kind, candidate.text, candidate.start])
231
+ const base = {
232
+ findingId,
233
+ statistic: candidate.kind,
234
+ text: candidate.text,
235
+ charStart: candidate.start,
236
+ charEnd: candidate.end,
237
+ df: candidate.df,
238
+ }
239
+ let recomputed: number
240
+ try {
241
+ recomputed = recomputeP({ statistic: candidate.kind, value: candidate.statistic, df: candidate.df })
242
+ } catch (error) {
243
+ findings.push({
244
+ ...base,
245
+ reported: { statistic: candidate.statistic },
246
+ recomputed: { p: Number.NaN },
247
+ status: 'inconsistent',
248
+ issue: 'df',
249
+ severity: 'error',
250
+ detail: `cannot recompute: ${(error as Error).message}`,
251
+ })
252
+ continue
253
+ }
254
+
255
+ if (pMatch === null) {
256
+ findings.push({
257
+ ...base,
258
+ reported: { statistic: candidate.statistic },
259
+ recomputed: { p: recomputed },
260
+ status: 'unparsed',
261
+ severity: 'info',
262
+ detail: `statistic parsed (recomputed p = ${recomputed.toFixed(4)}), but no p value was found next to it`,
263
+ })
264
+ continue
265
+ }
266
+ const pKind = pMatch[1] === '<' || pMatch[1] === '≤' ? 'less' : pMatch[1] === '>' || pMatch[1] === '≥' ? 'greater' : 'equal'
267
+ const pRaw = pMatch[2]!
268
+ const judgment = judgeP({ pRaw, pKind, recomputed })
269
+ const ci = ciMatch === null ? undefined : ([Number(ciMatch[1]), Number(ciMatch[2])] as const)
270
+ let status = judgment.status
271
+ let issue = judgment.issue
272
+ let detail = judgment.detail
273
+ let severity: StatFinding['severity'] = status === 'consistent' ? 'info' : 'error'
274
+ if (ci !== undefined && status === 'consistent') {
275
+ const reportedP = Number(pRaw.startsWith('.') ? `0${pRaw}` : pRaw)
276
+ const significant = pKind === 'equal' ? isSignificant(reportedP) : isSignificant(recomputed)
277
+ const excludesZero = ci[0] > 0 || ci[1] < 0
278
+ if (significant && !excludesZero) {
279
+ status = 'inconsistent'
280
+ issue = 'ci'
281
+ severity = 'error'
282
+ detail = `p = ${pRaw} is significant, but the reported 95% CI [${ci[0]}, ${ci[1]}] includes 0`
283
+ }
284
+ }
285
+ findings.push({
286
+ ...base,
287
+ reported: {
288
+ statistic: candidate.statistic,
289
+ p: pRaw,
290
+ pKind,
291
+ pValue: Number(pRaw.startsWith('.') ? `0${pRaw}` : pRaw),
292
+ ...(ci === undefined ? {} : { ci }),
293
+ },
294
+ recomputed: { p: recomputed },
295
+ status,
296
+ ...(issue === undefined ? {} : { issue }),
297
+ severity,
298
+ detail,
299
+ })
300
+ }
301
+ const summary: StatSummary = {
302
+ total: findings.length,
303
+ consistent: findings.filter(finding => finding.status === 'consistent').length,
304
+ inconsistent: findings.filter(finding => finding.status === 'inconsistent').length,
305
+ unparsed: findings.filter(finding => finding.status === 'unparsed').length,
306
+ }
307
+ return { findings, summary }
308
+ }
package/src/config.ts ADDED
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Config schema and resolution for `dsh-statcheck`.
3
+ * @module dsh-statcheck/config
4
+ */
5
+
6
+ import path from 'node:path'
7
+ import z from '@deepseek-ai/schemastery'
8
+
9
+ /** Raw plugin config. */
10
+ export interface Config {
11
+ enabled?: boolean
12
+ /** Store/record root, resolved against the harness working directory. */
13
+ root?: string
14
+ /** Workspace root that manuscript paths must stay inside. */
15
+ workspaceRoot?: string
16
+ /** Hard cap on analyzed characters. */
17
+ maxChars?: number
18
+ /** Hard cap on findings per call. */
19
+ maxFindings?: number
20
+ /** Persist a snapshot + REP record (default true). */
21
+ persist?: boolean
22
+ }
23
+
24
+ /** Fully resolved config. */
25
+ export interface ResolvedConfig {
26
+ readonly enabled: boolean
27
+ readonly root: string
28
+ readonly workspaceRoot: string
29
+ readonly maxChars: number
30
+ readonly maxFindings: number
31
+ readonly persist: boolean
32
+ }
33
+
34
+ /** Schemastery schema. */
35
+ export const Config: z<Config> = z.object({
36
+ enabled: z.boolean().default(true),
37
+ root: z.string().default('.statcheck'),
38
+ workspaceRoot: z.string(),
39
+ maxChars: z.number().default(2_000_000),
40
+ maxFindings: z.number().default(500),
41
+ persist: z.boolean().default(true),
42
+ })
43
+
44
+ /** Throw unless the value is a positive safe integer. */
45
+ function assertPositiveInt(name: string, value: number): void {
46
+ if (!Number.isSafeInteger(value) || value <= 0) {
47
+ throw new TypeError(`${name} must be a positive safe integer, got ${String(value)}`)
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Validate raw values and fill explicit defaults.
53
+ * @param config - raw plugin config.
54
+ * @returns the fully resolved config.
55
+ */
56
+ export function resolveConfig(config: Config = {}): ResolvedConfig {
57
+ const root = config.root ?? '.statcheck'
58
+ if (typeof root !== 'string' || root.trim() === '') throw new TypeError('root must be a non-empty path')
59
+ const maxChars = config.maxChars ?? 2_000_000
60
+ const maxFindings = config.maxFindings ?? 500
61
+ assertPositiveInt('maxChars', maxChars)
62
+ assertPositiveInt('maxFindings', maxFindings)
63
+ return {
64
+ enabled: config.enabled ?? true,
65
+ root: path.resolve(root),
66
+ workspaceRoot: path.resolve(config.workspaceRoot ?? process.cwd()),
67
+ maxChars,
68
+ maxFindings,
69
+ persist: config.persist ?? true,
70
+ }
71
+ }
package/src/index.ts ADDED
@@ -0,0 +1,75 @@
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
+
12
+ import type { Context } from '@deepseek-ai/cordis'
13
+ import { Config, resolveConfig, type Config as ConfigShape } from './config.ts'
14
+ import { StatcheckRuntime, type EvidencePort } from './runtime.ts'
15
+ import { makeStatCheckTool } from './tools/stat-check.ts'
16
+ import { makeStatRecomputeTool } from './tools/stat-recompute.ts'
17
+ import { makeStatReportTool } from './tools/stat-report.ts'
18
+
19
+ /** Cordis plugin name. */
20
+ export const name = 'statcheck'
21
+
22
+ /** The tool registry is required; the REP service is optional. */
23
+ export const inject = ['tools']
24
+
25
+ export { Config, resolveConfig }
26
+ export type { ConfigShape }
27
+ export type { ResolvedConfig } from './config.ts'
28
+ export { VERSION } from './version.ts'
29
+ export {
30
+ chiSquareUpperP,
31
+ fUpperP,
32
+ incompleteBeta,
33
+ logGamma,
34
+ normalCdf,
35
+ rTwoTailedP,
36
+ tTwoTailedP,
37
+ upperGamma,
38
+ zTwoTailedP,
39
+ } from './math.ts'
40
+ export { analyzeText, judgeP, recomputeP, StatInputError } from './check.ts'
41
+ export type { StatFinding, StatIssue, StatisticKind, StatStatus, StatSummary } from './check.ts'
42
+ export { findingsToMarkdown, findingsToSarif } from './report.ts'
43
+ export { StatcheckError, StatcheckRuntime, findingToCheck } from './runtime.ts'
44
+ export type {
45
+ EvidencePort,
46
+ StatCheckRequest,
47
+ StatCheckResult,
48
+ StatcheckErrorCode,
49
+ StatcheckRuntimeOptions,
50
+ } from './runtime.ts'
51
+ export { makeStatCheckTool } from './tools/stat-check.ts'
52
+ export { makeStatRecomputeTool } from './tools/stat-recompute.ts'
53
+ export { makeStatReportTool } from './tools/stat-report.ts'
54
+
55
+ /**
56
+ * Mount the three tools.
57
+ * @param ctx - the plugin context (host).
58
+ * @param config - raw plugin config.
59
+ */
60
+ export function apply(ctx: Context, config: ConfigShape): void {
61
+ const resolved = resolveConfig(config)
62
+ const logger = ctx.logger('statcheck')
63
+ if (!resolved.enabled) {
64
+ logger.info('disabled: enabled is false — no tools are mounted')
65
+ return
66
+ }
67
+ const service = ctx.get('researchEvidence') as EvidencePort | undefined
68
+ const runtime = new StatcheckRuntime({ config: resolved, ...(service === undefined ? {} : { service }) })
69
+ if (service === undefined) {
70
+ logger.info(`ctx.researchEvidence is not mounted; using a local core store under ${resolved.root}`)
71
+ }
72
+ ctx.effect(() => ctx.tools.register(makeStatCheckTool(runtime)), 'statcheck: stat_check tool')
73
+ ctx.effect(() => ctx.tools.register(makeStatRecomputeTool(runtime)), 'statcheck: stat_recompute tool')
74
+ ctx.effect(() => ctx.tools.register(makeStatReportTool()), 'statcheck: stat_report tool')
75
+ }