dsh-science-plugin 0.0.0-stage → 0.14.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.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +90 -2
  3. package/agents/_README.md +5 -0
  4. package/agents/analyst.md +27 -0
  5. package/agents/figure-expert.md +35 -0
  6. package/agents/literature-scout.md +32 -0
  7. package/agents/presentation.md +78 -0
  8. package/agents/reviewer.md +32 -0
  9. package/agents/simulator.md +30 -0
  10. package/agents/topic-designer.md +26 -0
  11. package/agents/trainer.md +36 -0
  12. package/agents/writer.md +44 -0
  13. package/assets/mascots/analyst.svg +33 -0
  14. package/assets/mascots/designer.svg +33 -0
  15. package/assets/mascots/figure.svg +35 -0
  16. package/assets/mascots/idle.svg +9 -0
  17. package/assets/mascots/lead.svg +33 -0
  18. package/assets/mascots/presentation.svg +40 -0
  19. package/assets/mascots/reviewer.svg +31 -0
  20. package/assets/mascots/scout.svg +31 -0
  21. package/assets/mascots/simulator.svg +33 -0
  22. package/assets/mascots/thinking.svg +23 -0
  23. package/assets/mascots/trainer.svg +32 -0
  24. package/assets/mascots/working.svg +9 -0
  25. package/assets/mascots/writer.svg +33 -0
  26. package/client/client.js +3425 -0
  27. package/client/client.js.map +7 -0
  28. package/cordis.patch.yml +10 -0
  29. package/docs/DEVLOG.md +864 -0
  30. package/docs/SPEC.md +452 -0
  31. package/docs/recipes/agent-teams-science.md +46 -0
  32. package/docs/research/2026-11-12-academic-figure-skill-/350/257/204/344/274/260.md +33 -0
  33. package/docs/research/2026-11-12-/347/224/237/347/211/251/347/247/221/347/240/224/350/203/275/345/212/233/344/270/216/345/267/245/344/275/234/345/217/260/351/233/206/346/210/220/350/260/203/347/240/224.md +169 -0
  34. package/docs/research/2026-11-12-/347/247/221/347/240/224/347/273/230/345/233/276/345/274/200/346/272/220/346/226/271/346/241/210/350/260/203/347/240/224.md +52 -0
  35. package/docs/research/2026-11-13-/345/257/271/350/257/235/351/251/261/345/212/250/347/247/221/347/240/224/345/267/245/344/275/234/345/217/260/344/272/247/345/223/201/347/255/226/347/225/245/350/260/203/347/240/224.md +319 -0
  36. package/docs/research/2026-11-13-/350/267/257/347/272/277B/346/212/200/346/234/257/345/217/257/350/241/214/346/200/247/344/270/216/344/275/216/347/274/272/351/231/267/350/256/276/350/256/241/350/260/203/347/240/224.md +65 -0
  37. package/docs/superpowers/specs/2026-11-12-/347/247/221/347/240/224/345/267/245/344/275/234/345/217/260/351/207/215/346/236/204/350/256/276/350/256/241.md +364 -0
  38. package/docs/superpowers/specs/2026-11-13-/345/257/271/350/257/235/344/274/230/345/205/210/347/247/221/347/240/224/345/215/241/347/211/207/345/267/245/344/275/234/345/217/260/351/207/215/346/236/204/350/256/276/350/256/241.md +607 -0
  39. package/icon.svg +6 -0
  40. package/lib/action-cards.js +194 -0
  41. package/lib/artifact-index.js +131 -0
  42. package/lib/blueprint.js +1487 -0
  43. package/lib/dag.js +69 -0
  44. package/lib/db.js +386 -0
  45. package/lib/figureqa.js +290 -0
  46. package/lib/figures.js +732 -0
  47. package/lib/httpdata-auth.js +91 -0
  48. package/lib/httpdata.js +863 -0
  49. package/lib/index.js +330 -0
  50. package/lib/lit.js +100 -0
  51. package/lib/paperspine.js +287 -0
  52. package/lib/project-adapter.js +259 -0
  53. package/lib/project-catalog.js +227 -0
  54. package/lib/project-context.js +282 -0
  55. package/lib/project-domain.js +849 -0
  56. package/lib/project-remote.js +348 -0
  57. package/lib/project-store.js +653 -0
  58. package/lib/rail-team.js +47 -0
  59. package/lib/resources.js +94 -0
  60. package/lib/reviewcov.js +238 -0
  61. package/lib/reviewer.js +638 -0
  62. package/lib/reviewruns.js +95 -0
  63. package/lib/roles.js +41 -0
  64. package/lib/router.js +133 -0
  65. package/lib/skeleton-context.js +181 -0
  66. package/lib/skillmenu.js +994 -0
  67. package/lib/ssh.js +637 -0
  68. package/lib/status.js +138 -0
  69. package/lib/store.js +50 -0
  70. package/lib/team.js +945 -0
  71. package/lib/vendor/ssh2.bundle.cjs +20124 -0
  72. package/lib/workspace-key.js +64 -0
  73. package/locale/en.json +7 -0
  74. package/locale/zh.json +7 -0
  75. package/package.json +72 -4
  76. package/skills/sci-autoresearch/SKILL.md +41 -0
  77. package/skills/sci-figures/SKILL.md +91 -0
  78. package/skills/sci-figures/references/journal-requirements.md +22 -0
  79. package/skills/sci-figures/references/r-figures.md +106 -0
  80. package/skills/sci-figures/scripts/figure_export.py +45 -0
  81. package/skills/sci-figures/scripts/style_presets.py +82 -0
  82. package/skills/sci-hypothesis/SKILL.md +37 -0
  83. package/skills/sci-polish/SKILL.md +28 -0
  84. package/skills/sci-remote-jobs/SKILL.md +48 -0
  85. package/skills/sci-simulation/SKILL.md +70 -0
  86. package/skills/sci-simulation/references/tool-dossiers/_TEMPLATE.md +25 -0
  87. package/skills/sci-simulation/references/tool-dossiers/ase.md +42 -0
  88. package/skills/sci-simulation/references/tool-dossiers/gaussian.md +42 -0
  89. package/skills/sci-simulation/references/tool-dossiers/gromacs.md +37 -0
  90. package/skills/sci-simulation/references/tool-dossiers/lammps.md +34 -0
  91. package/skills/sci-simulation/references/tool-dossiers/quantum-espresso.md +34 -0
  92. package/skills/sci-simulation/references/universal-tool-onboarding.md +117 -0
  93. package/skills/sci-slides/SKILL.md +73 -0
  94. package/skills/sci-slides/scripts/make_deck.py +332 -0
  95. package/skills/sci-writing/SKILL.md +33 -0
@@ -0,0 +1,290 @@
1
+ // dsh-science — 科研图件投稿前检内核
2
+ //
3
+ // 只检查可从文件与登记元数据观察到的属性;科学正确性、图像完整性和最终尺寸可读性
4
+ // 必须由研究者人工确认。这里的 "approved" 表示完成本插件前检,不代表期刊接收保证。
5
+
6
+ import { extname } from 'node:path'
7
+
8
+ export const JOURNAL_PROFILES = Object.freeze({
9
+ generic: Object.freeze({
10
+ id: 'generic',
11
+ label: '通用科研图件',
12
+ checkedAt: '2026-11-12',
13
+ source: 'https://research-figure-guide.nature.com/figures/preparing-figures-our-specifications/',
14
+ widthsMm: Object.freeze({ single: 89, double: 183 }),
15
+ maxHeightMm: 170,
16
+ fontPt: Object.freeze({ min: 5, max: 8 }),
17
+ rasterDpi: 300,
18
+ }),
19
+ nature: Object.freeze({
20
+ id: 'nature',
21
+ label: 'Nature 研究论文图件',
22
+ checkedAt: '2026-11-12',
23
+ source: 'https://research-figure-guide.nature.com/figures/building-and-exporting-figure-panels/',
24
+ widthsMm: Object.freeze({ single: 89, double: 183 }),
25
+ maxHeightMm: 170,
26
+ fontPt: Object.freeze({ min: 5, max: 7 }),
27
+ rasterDpi: 300,
28
+ }),
29
+ })
30
+
31
+ const FORMAT_KIND = Object.freeze({
32
+ png: 'raster', jpg: 'raster', jpeg: 'raster', gif: 'raster', webp: 'raster', tiff: 'raster',
33
+ svg: 'vector', pdf: 'vector',
34
+ })
35
+
36
+ function numberOrNull(v) {
37
+ const n = Number(v)
38
+ return Number.isFinite(n) && n > 0 ? n : null
39
+ }
40
+ function round(v, digits = 2) {
41
+ if (!Number.isFinite(v)) return null
42
+ const m = 10 ** digits
43
+ return Math.round(v * m) / m
44
+ }
45
+ function decodeXmlText(buf) {
46
+ if (buf[0] === 0xff && buf[1] === 0xfe) return buf.subarray(2).toString('utf16le')
47
+ if (buf[0] === 0xfe && buf[1] === 0xff) {
48
+ const body = buf.subarray(2, buf.length - ((buf.length - 2) % 2))
49
+ return Buffer.from(body).swap16().toString('utf16le')
50
+ }
51
+ if (buf[0] === 0x3c && buf[1] === 0x00) return buf.subarray(0, buf.length - (buf.length % 2)).toString('utf16le')
52
+ if (buf[0] === 0x00 && buf[1] === 0x3c) return Buffer.from(buf.subarray(0, buf.length - (buf.length % 2))).swap16().toString('utf16le')
53
+ return buf.toString('utf8')
54
+ }
55
+
56
+ function jpegSize(buf) {
57
+ if (buf.length < 4 || buf[0] !== 0xff || buf[1] !== 0xd8) return null
58
+ let i = 2
59
+ while (i + 8 < buf.length) {
60
+ if (buf[i] !== 0xff) { i++; continue }
61
+ const marker = buf[i + 1]
62
+ i += 2
63
+ if (marker === 0xd8 || marker === 0xd9) continue
64
+ if (i + 2 > buf.length) break
65
+ const len = buf.readUInt16BE(i)
66
+ if (len < 2 || i + len > buf.length) break
67
+ if ((marker >= 0xc0 && marker <= 0xc3) || (marker >= 0xc5 && marker <= 0xc7) || (marker >= 0xc9 && marker <= 0xcb) || (marker >= 0xcd && marker <= 0xcf)) {
68
+ return { width: buf.readUInt16BE(i + 5), height: buf.readUInt16BE(i + 3) }
69
+ }
70
+ i += len
71
+ }
72
+ return null
73
+ }
74
+
75
+ function tiffSize(buf) {
76
+ if (buf.length < 16) return null
77
+ const le = buf.toString('latin1', 0, 2) === 'II'
78
+ const be = buf.toString('latin1', 0, 2) === 'MM'
79
+ if (!le && !be) return null
80
+ const u16 = (off) => le ? buf.readUInt16LE(off) : buf.readUInt16BE(off)
81
+ const u32 = (off) => le ? buf.readUInt32LE(off) : buf.readUInt32BE(off)
82
+ const ifd = u32(4)
83
+ if (ifd + 2 > buf.length) return null
84
+ const count = u16(ifd)
85
+ let width = null
86
+ let height = null
87
+ for (let n = 0; n < count; n++) {
88
+ const off = ifd + 2 + n * 12
89
+ if (off + 12 > buf.length) break
90
+ const tag = u16(off)
91
+ const type = u16(off + 2)
92
+ const value = type === 3 ? u16(off + 8) : u32(off + 8)
93
+ if (tag === 256) width = value
94
+ if (tag === 257) height = value
95
+ }
96
+ return width && height ? { width, height } : null
97
+ }
98
+
99
+ function cssLengthToMm(raw) {
100
+ const m = /^\s*([0-9]*\.?[0-9]+)\s*(mm|cm|in|pt|px)?\s*$/i.exec(String(raw || ''))
101
+ if (!m) return null
102
+ const value = Number(m[1])
103
+ const unit = (m[2] || 'px').toLowerCase()
104
+ if (unit === 'mm') return value
105
+ if (unit === 'cm') return value * 10
106
+ if (unit === 'in') return value * 25.4
107
+ if (unit === 'pt') return value * 25.4 / 72
108
+ return null // px 没有可靠物理尺寸,留给目标宽度计算
109
+ }
110
+
111
+ function svgInfo(buf) {
112
+ const text = decodeXmlText(buf)
113
+ const root = /<svg\b([^>]*)>/i.exec(text)
114
+ const attrs = root ? root[1] : ''
115
+ const attr = (name) => {
116
+ const m = new RegExp(`\\b${name}\\s*=\\s*["']([^"']+)["']`, 'i').exec(attrs)
117
+ return m ? m[1] : null
118
+ }
119
+ const view = String(attr('viewBox') || '').trim().split(/[\s,]+/).map(Number)
120
+ const viewSize = view.length === 4 && view.every(Number.isFinite)
121
+ ? { width: Math.abs(view[2]), height: Math.abs(view[3]) }
122
+ : null
123
+ const fontPt = []
124
+ for (const m of text.matchAll(/font-size\s*(?:=|:)\s*["']?\s*([0-9]*\.?[0-9]+)\s*(px|pt)?/gi)) {
125
+ const v = Number(m[1])
126
+ if (Number.isFinite(v)) fontPt.push((m[2] || 'px').toLowerCase() === 'pt' ? v : v * 0.75)
127
+ }
128
+ const widthMm = cssLengthToMm(attr('width'))
129
+ const heightMm = cssLengthToMm(attr('height'))
130
+ return {
131
+ text,
132
+ viewSize,
133
+ physicalSize: widthMm && heightMm ? { widthMm: round(widthMm), heightMm: round(heightMm) } : null,
134
+ editableTextCount: (text.match(/<text\b/gi) || []).length,
135
+ fontPt: fontPt.length ? { min: round(Math.min(...fontPt)), max: round(Math.max(...fontPt)) } : null,
136
+ }
137
+ }
138
+ function pdfInfo(buf) {
139
+ // 只读首段元数据;压缩对象中的字体与图层无法靠正则可靠判断,因此仍列为人工检查。
140
+ const text = buf.subarray(0, Math.min(buf.length, 2 * 1024 * 1024)).toString('latin1')
141
+ const m = /\/MediaBox\s*\[\s*[-0-9.]+\s+[-0-9.]+\s+([-0-9.]+)\s+([-0-9.]+)\s*\]/.exec(text)
142
+ const widthPt = m ? Number(m[1]) : null
143
+ const heightPt = m ? Number(m[2]) : null
144
+ return {
145
+ physicalSize: Number.isFinite(widthPt) && Number.isFinite(heightPt)
146
+ ? { widthMm: round(widthPt * 25.4 / 72), heightMm: round(heightPt * 25.4 / 72) }
147
+ : null,
148
+ pageCountHint: (text.match(/\/Type\s*\/Page\b/g) || []).length || null,
149
+ }
150
+ }
151
+
152
+ export function inspectFigureBuffer(filePath, buf) {
153
+ const ext = extname(String(filePath || '')).slice(1).toLowerCase()
154
+ const out = {
155
+ ext,
156
+ kind: FORMAT_KIND[ext] || 'unknown',
157
+ bytes: buf.length,
158
+ pixelSize: null,
159
+ physicalSize: null,
160
+ editableTextCount: null,
161
+ fontPt: null,
162
+ }
163
+ try {
164
+ if (ext === 'png' && buf.length >= 24) out.pixelSize = { width: buf.readUInt32BE(16), height: buf.readUInt32BE(20) }
165
+ else if (ext === 'jpg' || ext === 'jpeg') out.pixelSize = jpegSize(buf)
166
+ else if (ext === 'gif' && buf.length >= 10) out.pixelSize = { width: buf.readUInt16LE(6), height: buf.readUInt16LE(8) }
167
+ else if (ext === 'tiff') out.pixelSize = tiffSize(buf)
168
+ else if (ext === 'svg') Object.assign(out, svgInfo(buf))
169
+ else if (ext === 'pdf') Object.assign(out, pdfInfo(buf))
170
+ } catch {
171
+ // 文件已通过外层格式闸门时,解析失败只意味着该测量不可用,不伪造数值。
172
+ }
173
+ return out
174
+ }
175
+
176
+ function check(id, label, status, observed, requirement, action = '') {
177
+ return { id, label, status, observed, requirement, action }
178
+ }
179
+
180
+ export function auditFigureRecord(record, inspected, options = {}) {
181
+ const plan = record && record.plan && typeof record.plan === 'object' ? record.plan : {}
182
+ const profile = JOURNAL_PROFILES[plan.targetJournal] || JOURNAL_PROFILES.generic
183
+ const pathExists = typeof options.pathExists === 'function' ? options.pathExists : () => true
184
+ const targetWidthMm = numberOrNull(plan.targetWidthMm)
185
+ const targetHeightMm = targetWidthMm && inspected.pixelSize
186
+ ? targetWidthMm * inspected.pixelSize.height / inspected.pixelSize.width
187
+ : inspected.physicalSize && inspected.physicalSize.heightMm
188
+ const effectiveDpi = inspected.kind === 'raster' && inspected.pixelSize && targetWidthMm
189
+ ? inspected.pixelSize.width / (targetWidthMm / 25.4)
190
+ : null
191
+ const checks = []
192
+ checks.push(check(
193
+ 'file-format', '投稿文件格式', FORMAT_KIND[inspected.ext] ? 'pass' : 'fail',
194
+ inspected.ext || '未知', 'PNG/JPEG/TIFF 等位图或 SVG/PDF 矢量图', '导出受支持格式后重新登记。',
195
+ ))
196
+ const sizeTooLarge = !!targetWidthMm && (
197
+ targetWidthMm > profile.widthsMm.double || (targetHeightMm != null && targetHeightMm > profile.maxHeightMm)
198
+ )
199
+ checks.push(check(
200
+ 'target-size', '最终物理尺寸', !targetWidthMm ? 'warn' : sizeTooLarge ? 'fail' : 'pass',
201
+ targetWidthMm ? `${round(targetWidthMm)} × ${round(targetHeightMm)} mm` : '未声明目标宽度',
202
+ `${profile.label}:宽度不超过 ${profile.widthsMm.double} mm,高度不超过 ${profile.maxHeightMm} mm`,
203
+ sizeTooLarge ? '缩小画布或重排面板,并按新的最终宽度重新审计。' : '在 sci_figure_plan 中设置 target_width_mm。',
204
+ ))
205
+ if (inspected.kind === 'raster') {
206
+ checks.push(check(
207
+ 'effective-dpi', '最终尺寸有效分辨率', effectiveDpi == null ? 'warn' : effectiveDpi >= profile.rasterDpi ? 'pass' : 'fail',
208
+ effectiveDpi == null ? '无法计算' : `${round(effectiveDpi, 1)} dpi`,
209
+ `至少 ${profile.rasterDpi} dpi`, '从原始数据重新导出更高像素图;不要只修改 dpi 元数据。',
210
+ ))
211
+ } else {
212
+ checks.push(check(
213
+ 'effective-dpi', '矢量保留', inspected.kind === 'vector' ? 'pass' : 'warn',
214
+ inspected.kind === 'vector' ? '矢量容器' : '无法判断', '线条与文字优先保持矢量', '改用 SVG/PDF 导出并人工检查。',
215
+ ))
216
+ }
217
+ const codeOk = !!record.codePath && pathExists(record.codePath)
218
+ checks.push(check(
219
+ 'code-source', '生成代码', codeOk ? 'pass' : 'warn',
220
+ codeOk ? record.codePath : '缺少或路径不存在', '保留可复现绘图代码', '登记 code_path 并确认文件存在。',
221
+ ))
222
+ const sourcePaths = Array.isArray(record.sourceDataPaths) ? record.sourceDataPaths.filter(Boolean) : []
223
+ const missingSources = sourcePaths.filter((p) => !pathExists(p))
224
+ checks.push(check(
225
+ 'source-data', '源数据溯源', sourcePaths.length > 0 && missingSources.length === 0 ? 'pass' : 'warn',
226
+ sourcePaths.length === 0 ? '未登记' : missingSources.length ? `缺失 ${missingSources.length}/${sourcePaths.length}` : `${sourcePaths.length} 个文件`,
227
+ '图中数值可追溯到源数据', '在图件计划中登记 source_data_paths,并修复失效路径。',
228
+ ))
229
+ const statsNeeded = plan.requiresStatistics === true
230
+ const statsOk = !statsNeeded || !!String(plan.statisticsNote || '').trim()
231
+ checks.push(check(
232
+ 'statistics-note', '统计与重复说明', statsOk ? 'pass' : 'warn',
233
+ statsNeeded ? (plan.statisticsNote || '缺少') : '该图声明不需要统计说明',
234
+ statsNeeded ? '定义 n、误差线、检验与多重比较' : '按图件类型决定', '补充 statistics_note。',
235
+ ))
236
+ const templateSource = String(plan.templateSource || '').trim()
237
+ const templateLicense = String(plan.templateLicense || '').trim()
238
+ checks.push(check(
239
+ 'template-license', '模板与素材许可', !templateSource || templateLicense ? 'pass' : 'warn',
240
+ !templateSource ? '未使用外部模板' : templateLicense || '使用了模板但未登记许可',
241
+ '保存来源、精确版本与许可', '补充 template_license;逐项核对素材授权。',
242
+ ))
243
+ if (inspected.ext === 'svg' && inspected.fontPt) {
244
+ const fontOk = inspected.fontPt.min >= profile.fontPt.min && inspected.fontPt.max <= profile.fontPt.max
245
+ checks.push(check(
246
+ 'font-size', '矢量文字字号', fontOk ? 'pass' : 'fail',
247
+ `${inspected.fontPt.min}–${inspected.fontPt.max} pt`,
248
+ `${profile.fontPt.min}–${profile.fontPt.max} pt(最终尺寸)`, '调整字号并按最终宽度重新导出。',
249
+ ))
250
+ } else {
251
+ checks.push(check(
252
+ 'font-size', '最终尺寸文字可读性', 'manual', '自动检查不足',
253
+ `${profile.fontPt.min}–${profile.fontPt.max} pt,且文字保持可编辑`, '按最终物理尺寸打开 PDF/SVG 或打印检查。',
254
+ ))
255
+ }
256
+ checks.push(check('panel-layout', '面板布局与裁切', 'manual', '待人工查看', '标签顺序、对齐、留白、无重叠或裁切', '逐面板审阅最终导出文件。'))
257
+ checks.push(check('scientific-integrity', '科学与图像完整性', 'manual', '待研究者确认', '数据、标尺、颜色映射与统计表达真实准确', '对照源数据、分析代码和图注逐项确认。'))
258
+
259
+ const summary = { pass: 0, warn: 0, fail: 0, manual: 0 }
260
+ for (const c of checks) summary[c.status] = (summary[c.status] || 0) + 1
261
+ const automaticStatus = summary.fail > 0 ? 'failed' : summary.warn > 0 ? 'needs-attention' : 'ready-for-manual-review'
262
+ const manualReview = record.manualReview && typeof record.manualReview === 'object'
263
+ ? { ...record.manualReview }
264
+ : { decision: 'pending', note: '', reviewedAt: null }
265
+ let overallStatus = automaticStatus
266
+ if (manualReview.decision === 'rejected') overallStatus = 'rejected'
267
+ else if (manualReview.decision === 'approved' && automaticStatus === 'ready-for-manual-review') overallStatus = 'approved'
268
+ return {
269
+ checkedAt: Date.now(),
270
+ profile: { id: profile.id, label: profile.label, checkedAt: profile.checkedAt, source: profile.source },
271
+ measurements: {
272
+ format: inspected.ext,
273
+ kind: inspected.kind,
274
+ pixelSize: inspected.pixelSize,
275
+ physicalSize: inspected.physicalSize,
276
+ targetWidthMm: round(targetWidthMm),
277
+ targetHeightMm: round(targetHeightMm),
278
+ effectiveDpi: round(effectiveDpi, 1),
279
+ fontPt: inspected.fontPt,
280
+ editableTextCount: inspected.editableTextCount,
281
+ },
282
+ checks,
283
+ summary,
284
+ automaticStatus,
285
+ manualReview,
286
+ overallStatus,
287
+ disclaimer: '自动前检只覆盖可观察属性;科学正确性、图像完整性和期刊接收仍需研究者与目标期刊确认。',
288
+ }
289
+ }
290
+ // 本模块只生成投稿前检结论;期刊接收仍由研究者与编辑流程判定。