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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `stat_check` — recompute reported statistics in a manuscript.
|
|
3
|
+
* @module dsh-statcheck/tools/stat-check
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
7
|
+
import { StatcheckError, type StatcheckRuntime } from '../runtime.ts'
|
|
8
|
+
import { ERROR_SCHEMA, FINDING_SCHEMA, SUMMARY_SCHEMA, plainFinding } from './shared.ts'
|
|
9
|
+
|
|
10
|
+
const OUTPUT_SCHEMA = {
|
|
11
|
+
type: 'object',
|
|
12
|
+
additionalProperties: false,
|
|
13
|
+
properties: {
|
|
14
|
+
ok: { type: 'boolean', required: true },
|
|
15
|
+
summary: SUMMARY_SCHEMA,
|
|
16
|
+
findings: { type: 'array', items: FINDING_SCHEMA },
|
|
17
|
+
source: { type: 'json' },
|
|
18
|
+
evidenceId: { type: 'string' },
|
|
19
|
+
recordPath: { type: 'string' },
|
|
20
|
+
error: ERROR_SCHEMA,
|
|
21
|
+
},
|
|
22
|
+
} as const
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build the `stat_check` tool.
|
|
26
|
+
* @param runtime - the statcheck runtime.
|
|
27
|
+
* @returns the tool definition.
|
|
28
|
+
*/
|
|
29
|
+
export function makeStatCheckTool(runtime: StatcheckRuntime) {
|
|
30
|
+
return defineTool({
|
|
31
|
+
name: 'stat_check',
|
|
32
|
+
description: [
|
|
33
|
+
'Recompute the p values reported in a manuscript and flag self-inconsistent statistics (dsh-statcheck).',
|
|
34
|
+
'',
|
|
35
|
+
'Parses APA-style reports: t(df), F(df1, df2), χ²(df), r(df), z, each with a nearby p value (`p = .018`, `p < .001`) and an optional 95% CI. The p value is recomputed from the reported statistic only — no data is re-analysed, no model is judged.',
|
|
36
|
+
'',
|
|
37
|
+
'Flags mean "the reported p does not follow from the reported statistic", with both numbers and the character range shown. They do NOT imply misconduct and must be reviewed by a human. Scanned/PDF text is out of scope: extract text first (dsh-doc-anchor) and pass `text` or a `.txt`/`.md`/`.tex` path.',
|
|
38
|
+
].join('\n'),
|
|
39
|
+
parameters: {
|
|
40
|
+
text: { type: 'string', description: 'Manuscript text to analyze (mutually exclusive with path).' },
|
|
41
|
+
path: { type: 'string', description: 'Workspace-relative manuscript path (.txt/.md/.tex/.html; must stay inside the workspace).' },
|
|
42
|
+
persist: { type: 'boolean', description: 'Store the analyzed text as a REP snapshot + record (default true).' },
|
|
43
|
+
maxFindings: { type: 'integer', description: 'Findings cap for this call.' },
|
|
44
|
+
},
|
|
45
|
+
output: {
|
|
46
|
+
schema: OUTPUT_SCHEMA,
|
|
47
|
+
render: (_args, value) => {
|
|
48
|
+
const result = value as
|
|
49
|
+
| { ok: true; summary: { total: number; consistent: number; inconsistent: number; unparsed: number }; findings: Array<{ statistic: string; text: string; detail: string; status: string; charStart: number }>; evidenceId?: string }
|
|
50
|
+
| { ok: false; error: { code: string; message: string } }
|
|
51
|
+
if (!result.ok) return [{ type: 'text', text: `stat_check failed (${result.error.code}): ${result.error.message}` }]
|
|
52
|
+
const lines = [
|
|
53
|
+
`stat_check: ${result.summary.total} statistic(s) — ${result.summary.consistent} consistent, ${result.summary.inconsistent} inconsistent, ${result.summary.unparsed} unparsed`,
|
|
54
|
+
]
|
|
55
|
+
for (const finding of result.findings.filter(item => item.status === 'inconsistent').slice(0, 20)) {
|
|
56
|
+
lines.push(` [inconsistent] ${finding.text} — ${finding.detail} (chars ${finding.charStart}-${finding.charStart + finding.text.length})`)
|
|
57
|
+
}
|
|
58
|
+
if (result.summary.inconsistent > 0) {
|
|
59
|
+
lines.push(' these findings are candidates for human review, not a conclusion about the authors')
|
|
60
|
+
}
|
|
61
|
+
if (result.evidenceId !== undefined) lines.push(`evidence ${result.evidenceId}`)
|
|
62
|
+
return [{ type: 'text', text: lines.join('\n') }]
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
async execute(args: unknown) {
|
|
66
|
+
const request = args as Parameters<StatcheckRuntime['check']>[0]
|
|
67
|
+
try {
|
|
68
|
+
const result = await runtime.check(request)
|
|
69
|
+
return {
|
|
70
|
+
ok: true as const,
|
|
71
|
+
summary: { ...result.summary },
|
|
72
|
+
findings: result.findings.map(plainFinding),
|
|
73
|
+
source: { ...result.source },
|
|
74
|
+
...(result.evidenceId === undefined ? {} : { evidenceId: result.evidenceId }),
|
|
75
|
+
...(result.recordPath === undefined ? {} : { recordPath: result.recordPath }),
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error instanceof StatcheckError) return { ok: false as const, error: { code: error.code, message: error.message } }
|
|
79
|
+
throw error
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `stat_recompute` — one statistic in, the recomputed p value out.
|
|
3
|
+
* @module dsh-statcheck/tools/stat-recompute
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
7
|
+
import { StatcheckError, type StatcheckRuntime } from '../runtime.ts'
|
|
8
|
+
import { ERROR_SCHEMA } from './shared.ts'
|
|
9
|
+
|
|
10
|
+
const OUTPUT_SCHEMA = {
|
|
11
|
+
type: 'object',
|
|
12
|
+
additionalProperties: false,
|
|
13
|
+
properties: {
|
|
14
|
+
ok: { type: 'boolean', required: true },
|
|
15
|
+
statistic: { type: 'string' },
|
|
16
|
+
value: { type: 'number' },
|
|
17
|
+
df: { type: 'array', items: { type: 'number' } },
|
|
18
|
+
p: { type: 'number' },
|
|
19
|
+
judgment: { type: 'json' },
|
|
20
|
+
error: ERROR_SCHEMA,
|
|
21
|
+
},
|
|
22
|
+
} as const
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build the `stat_recompute` tool.
|
|
26
|
+
* @param runtime - the statcheck runtime.
|
|
27
|
+
* @returns the tool definition.
|
|
28
|
+
*/
|
|
29
|
+
export function makeStatRecomputeTool(runtime: StatcheckRuntime) {
|
|
30
|
+
return defineTool({
|
|
31
|
+
name: 'stat_recompute',
|
|
32
|
+
description: [
|
|
33
|
+
'Recompute a p value from a single reported statistic (dsh-statcheck).',
|
|
34
|
+
'',
|
|
35
|
+
't and r are two-tailed; F and χ² are upper-tail; z is two-tailed. Degrees of freedom are required (t: 1, F: 2, χ²: 1, r: 1, z: 0). Pass `p` as written (e.g. ".018" or "<.001") to also get a consistency judgment with the same rounding rule used by stat_check.',
|
|
36
|
+
'',
|
|
37
|
+
'This is arithmetic, not inference: it does not re-analyse data and cannot tell whether the reported statistic itself is appropriate.',
|
|
38
|
+
].join('\n'),
|
|
39
|
+
parameters: {
|
|
40
|
+
statistic: { type: 'string', enum: ['t', 'F', 'chi2', 'r', 'z'], description: 'Statistic family.' },
|
|
41
|
+
value: { type: 'number', required: true, description: 'The reported statistic.' },
|
|
42
|
+
df: { type: 'array', items: { type: 'number' }, description: 'Degrees of freedom as reported (empty for z).' },
|
|
43
|
+
p: { type: 'string', description: 'The p value as reported (".018", "<.001", "= .05").' },
|
|
44
|
+
},
|
|
45
|
+
output: {
|
|
46
|
+
schema: OUTPUT_SCHEMA,
|
|
47
|
+
render: (_args, value) => {
|
|
48
|
+
const result = value as
|
|
49
|
+
| { ok: true; statistic: string; value: number; df: number[]; p: number; judgment?: { status: string; issue?: string; detail: string } }
|
|
50
|
+
| { ok: false; error: { code: string; message: string } }
|
|
51
|
+
if (!result.ok) return [{ type: 'text', text: `stat_recompute failed (${result.error.code}): ${result.error.message}` }]
|
|
52
|
+
const lines = [`stat_recompute: ${result.statistic} = ${result.value}${result.df.length === 0 ? '' : `, df = ${result.df.join(', ')}`} → p = ${result.p.toFixed(6)}`]
|
|
53
|
+
if (result.judgment !== undefined) lines.push(` ${result.judgment.status}${result.judgment.issue === undefined ? '' : ` (${result.judgment.issue})`}: ${result.judgment.detail}`)
|
|
54
|
+
return [{ type: 'text', text: lines.join('\n') }]
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
async execute(args: unknown) {
|
|
58
|
+
const request = args as { statistic: 't' | 'F' | 'chi2' | 'r' | 'z'; value: number; df?: number[]; p?: string }
|
|
59
|
+
try {
|
|
60
|
+
const result = runtime.recompute({
|
|
61
|
+
statistic: request.statistic,
|
|
62
|
+
value: request.value,
|
|
63
|
+
df: request.df ?? [],
|
|
64
|
+
...(request.p === undefined ? {} : { p: request.p }),
|
|
65
|
+
})
|
|
66
|
+
return {
|
|
67
|
+
ok: true as const,
|
|
68
|
+
statistic: request.statistic,
|
|
69
|
+
value: request.value,
|
|
70
|
+
df: [...(request.df ?? [])],
|
|
71
|
+
p: result.p,
|
|
72
|
+
...(result.judgment === undefined
|
|
73
|
+
? {}
|
|
74
|
+
: { judgment: { status: result.judgment.status, ...(result.judgment.issue === undefined ? {} : { issue: result.judgment.issue }), detail: result.judgment.detail } }),
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error instanceof StatcheckError) return { ok: false as const, error: { code: error.code, message: error.message } }
|
|
78
|
+
throw error
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `stat_report` — render findings as Markdown and SARIF 2.1.0.
|
|
3
|
+
* @module dsh-statcheck/tools/stat-report
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
7
|
+
import type { StatFinding } from '../check.ts'
|
|
8
|
+
import { findingsToMarkdown, findingsToSarif } from '../report.ts'
|
|
9
|
+
import { VERSION } from '../version.ts'
|
|
10
|
+
import { ERROR_SCHEMA, SUMMARY_SCHEMA } from './shared.ts'
|
|
11
|
+
|
|
12
|
+
const OUTPUT_SCHEMA = {
|
|
13
|
+
type: 'object',
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
properties: {
|
|
16
|
+
ok: { type: 'boolean', required: true },
|
|
17
|
+
markdown: { type: 'string' },
|
|
18
|
+
sarif: { type: 'json' },
|
|
19
|
+
summary: SUMMARY_SCHEMA,
|
|
20
|
+
error: ERROR_SCHEMA,
|
|
21
|
+
},
|
|
22
|
+
} as const
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build the `stat_report` tool.
|
|
26
|
+
* @returns the tool definition.
|
|
27
|
+
*/
|
|
28
|
+
export function makeStatReportTool() {
|
|
29
|
+
return defineTool({
|
|
30
|
+
name: 'stat_report',
|
|
31
|
+
description: [
|
|
32
|
+
'Render stat_check findings as a Markdown report and a SARIF 2.1.0 log (dsh-statcheck).',
|
|
33
|
+
'',
|
|
34
|
+
'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.',
|
|
35
|
+
'',
|
|
36
|
+
'The report says explicitly that a finding means "the reported p does not follow from the reported statistic" — not misconduct.',
|
|
37
|
+
].join('\n'),
|
|
38
|
+
parameters: {
|
|
39
|
+
findings: { type: 'array', items: { type: 'json' }, required: true, description: 'Findings from stat_check.' },
|
|
40
|
+
text: { type: 'string', description: 'Original manuscript text; when provided, SARIF line/column are mapped from each finding charStart.' },
|
|
41
|
+
},
|
|
42
|
+
output: {
|
|
43
|
+
schema: OUTPUT_SCHEMA,
|
|
44
|
+
render: (_args, value) => {
|
|
45
|
+
const result = value as { ok: true; markdown: string; summary: { inconsistent: number } } | { ok: false; error: { code: string; message: string } }
|
|
46
|
+
if (!result.ok) return [{ type: 'text', text: `stat_report failed (${result.error.code}): ${result.error.message}` }]
|
|
47
|
+
return [{ type: 'text', text: result.markdown }]
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
async execute(args: unknown) {
|
|
51
|
+
const request = args as { findings?: StatFinding[]; text?: string }
|
|
52
|
+
const findings = Array.isArray(request.findings) ? request.findings : []
|
|
53
|
+
const text = typeof request.text === 'string' ? request.text : undefined
|
|
54
|
+
const summary = {
|
|
55
|
+
total: findings.length,
|
|
56
|
+
consistent: findings.filter(finding => finding.status === 'consistent').length,
|
|
57
|
+
inconsistent: findings.filter(finding => finding.status === 'inconsistent').length,
|
|
58
|
+
unparsed: findings.filter(finding => finding.status === 'unparsed').length,
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
ok: true as const,
|
|
62
|
+
markdown: findingsToMarkdown(findings, summary),
|
|
63
|
+
sarif: findingsToSarif(findings, VERSION, text) as never,
|
|
64
|
+
summary,
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
}
|