dsh-molbio-tools 0.28.1 → 0.28.2
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 +41 -0
- package/README.md +8 -6
- package/batch.mjs +53 -21
- package/benchmark/README.md +6 -0
- package/benchmark/tasks/04-cloning.json +2 -2
- package/benchmark/verifications.mjs +1 -1
- package/build/check.mjs +463 -0
- package/build/client-bundle.mjs +1 -1
- package/build/panel-core.mjs +15 -3
- package/build/release-notes.mjs +82 -52
- package/build/release-preflight.mjs +1 -1
- package/docs/audit-2026-12.md +314 -0
- package/docs/change-process.md +305 -0
- package/docs/history.md +2 -0
- package/docs/maintainer.md +7 -2
- package/docs/roadmap.md +1 -1
- package/docs/rules.md +13 -7
- package/docs/store-evidence.md +17 -7
- package/docs/workflow.md +17 -5
- package/genbank.mjs +65 -14
- package/host.mjs +1 -1
- package/index.mjs +87 -66
- package/lib/client.js +89 -17
- package/package.json +10 -7
- package/pcr.mjs +29 -7
- package/phylo.mjs +0 -6
- package/seqio.mjs +5 -0
- package/taqman.mjs +4 -0
- package/test/client.mjs +6 -0
- package/test/contract.mjs +1 -1
- package/test/release.mjs +15 -8
- package/test/smoke.mjs +120 -2
- package/view.mjs +13 -1
package/build/check.mjs
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-molbio-tools/build/check.mjs
|
|
3
|
+
*
|
|
4
|
+
* The fast, offline pre-commit gate. It answers one question:
|
|
5
|
+
*
|
|
6
|
+
* "if I committed and released right now, would anything be silently wrong?"
|
|
7
|
+
*
|
|
8
|
+
* It is deliberately NOT a replacement for `npm test`. The suites answer "do the
|
|
9
|
+
* tools still compute correctly"; this gate answers the cheaper, drift-shaped
|
|
10
|
+
* questions that used to be answered by a human remembering a checklist:
|
|
11
|
+
*
|
|
12
|
+
* 1. the registered tool count and the number written in every doc agree;
|
|
13
|
+
* 2. every benchmark task still names existing tools, and the task count in
|
|
14
|
+
* the docs agrees (a renamed tool used to keep 72/72 green by luck);
|
|
15
|
+
* 3. the committed client bundle and bundle patch match their sources;
|
|
16
|
+
* 4. package.json's version has a CHANGELOG section and the panel version is
|
|
17
|
+
* a plain x.y.z;
|
|
18
|
+
* 5. no tracked file's CONTENT differs from the index while `git status`
|
|
19
|
+
* calls it clean (the stat-cache trap: a same-size edit whose mtime was
|
|
20
|
+
* preserved is invisible to git and would be left out of the commit);
|
|
21
|
+
* 6. the locally installed DSH matches the preset's declared baseline
|
|
22
|
+
* (a warning by default, a failure with --strict);
|
|
23
|
+
* 7. the GitHub Release body is new tools + fixes only (no install block, no
|
|
24
|
+
* version table, no links) and refuses an entry with neither heading;
|
|
25
|
+
* 8. no `test*` script spends tokens on the real-model benchmark (model runs
|
|
26
|
+
* are opt-in, for a new or optimised tool only — rules.md §6);
|
|
27
|
+
* 9. every guard above can still FAIL — each one is fed a mutation first.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* node build/check.mjs # fast checks; baseline mismatch is a warning
|
|
31
|
+
* node build/check.mjs --strict # baseline mismatch is a failure (CI/release)
|
|
32
|
+
* node build/check.mjs --suites # additionally run prompt + smoke + offline bench
|
|
33
|
+
* node build/check.mjs --self-test # only the mutation cases
|
|
34
|
+
*
|
|
35
|
+
* Exit code: 0 when every check passes, 1 otherwise. Everything is read-only;
|
|
36
|
+
* the gate never rewrites an artifact (the repair is always printed instead).
|
|
37
|
+
*
|
|
38
|
+
* Deliberate strictness: a numeric claim is located by an exact PHRASE, so
|
|
39
|
+
* rewording one of those sentences is a failure too — update the pattern in the
|
|
40
|
+
* same commit that rewrites the sentence. The alternative (a loose regex that
|
|
41
|
+
* matches anything) is a guard that quietly stops checking, which is exactly
|
|
42
|
+
* what rules.md §9 forbids.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs';
|
|
46
|
+
import { execFileSync } from 'node:child_process';
|
|
47
|
+
import { createHash } from 'node:crypto';
|
|
48
|
+
import { dirname, join, resolve } from 'node:path';
|
|
49
|
+
import { fileURLToPath } from 'node:url';
|
|
50
|
+
|
|
51
|
+
import { createGenerator } from './client-bundle-core.mjs';
|
|
52
|
+
import { buildPatch, rowBlockOf } from './preset-patch.mjs';
|
|
53
|
+
import { changelogSection, versionShapeProblem } from './release-preflight.mjs';
|
|
54
|
+
import { releaseNotes, renderNotes } from './release-notes.mjs';
|
|
55
|
+
import { findHarnessRoot } from '../benchmark/harness.mjs';
|
|
56
|
+
|
|
57
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
58
|
+
const strict = process.argv.includes('--strict');
|
|
59
|
+
const withSuites = process.argv.includes('--suites');
|
|
60
|
+
const selfTestOnly = process.argv.includes('--self-test');
|
|
61
|
+
|
|
62
|
+
const read = (relative) => readFileSync(join(ROOT, relative), 'utf8');
|
|
63
|
+
const normalize = (text) => text.replace(/^\uFEFF/, '').replace(/\r\n/g, '\n');
|
|
64
|
+
|
|
65
|
+
// ── pure helpers (exported so the mutation cases can drive them) ────────────
|
|
66
|
+
|
|
67
|
+
/** Every `name: 'molbio_*'` in the entry, deduplicated. */
|
|
68
|
+
export function toolNamesOf(indexText) {
|
|
69
|
+
const names = new Set();
|
|
70
|
+
for (const match of indexText.matchAll(/\bname: '(molbio_[a-z0-9_]+)'/g)) names.add(match[1]);
|
|
71
|
+
return [...names].sort();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Compare numeric claims in documents with the computed count.
|
|
76
|
+
* @param {{file: string, pattern: RegExp, label: string}[]} claims
|
|
77
|
+
* @param {(file: string) => string} readText
|
|
78
|
+
* @param {number} expected
|
|
79
|
+
* @returns {{file: string, label: string, found: string[], expected: number}[]}
|
|
80
|
+
*/
|
|
81
|
+
export function countMismatches(claims, readText, expected) {
|
|
82
|
+
const problems = [];
|
|
83
|
+
for (const claim of claims) {
|
|
84
|
+
const text = readText(claim.file);
|
|
85
|
+
const found = [...text.matchAll(claim.pattern)].map((match) => match.slice(1).filter((part) => part !== undefined));
|
|
86
|
+
if (found.length === 0) {
|
|
87
|
+
problems.push({ file: claim.file, label: claim.label, found: ['<claim not found>'], expected });
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
for (const groups of found) {
|
|
91
|
+
if (!groups.every((value) => Number(value) === expected)) {
|
|
92
|
+
problems.push({ file: claim.file, label: claim.label, found: groups, expected });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return problems;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** One committed artifact against the text its sources produce. */
|
|
100
|
+
export function artifactMismatches(entries) {
|
|
101
|
+
return entries.filter((entry) => entry.actual !== undefined && normalize(entry.actual) !== normalize(entry.expected));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Files whose CONTENT differs from the index but which `git status` reports as
|
|
106
|
+
* clean. `dirty` is the porcelain path set, so ordinary unstaged edits are not
|
|
107
|
+
* reported here — only the edits git cannot see.
|
|
108
|
+
* @param {{path: string, indexSha: string, workSha: string}[]} entries
|
|
109
|
+
* @param {Set<string>} dirty
|
|
110
|
+
*/
|
|
111
|
+
export function invisibleEdits(entries, dirty) {
|
|
112
|
+
return entries.filter((entry) => !dirty.has(entry.path) && entry.indexSha !== entry.workSha);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Routine scripts (`test`, `test:*`, `pretest`, `posttest`) must never invoke the
|
|
117
|
+
* real-model benchmark: it costs tokens and only belongs to "a tool was added or
|
|
118
|
+
* an existing tool was optimised". `bench:offline` is allowed — it runs no model.
|
|
119
|
+
* @param {Record<string, string>} scripts - package.json's "scripts"
|
|
120
|
+
* @returns {string[]} offending `name: command` entries
|
|
121
|
+
*/
|
|
122
|
+
export function modelRunsInRoutineScripts(scripts) {
|
|
123
|
+
const offenders = [];
|
|
124
|
+
for (const [name, command] of Object.entries(scripts ?? {})) {
|
|
125
|
+
const routine = name === 'test' || name.startsWith('test:') || name === 'pretest' || name === 'posttest';
|
|
126
|
+
if (!routine) continue;
|
|
127
|
+
if (/--model\b/.test(command)) {
|
|
128
|
+
offenders.push(`${name}: ${command}`);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const benchCalls = [...command.matchAll(/\bbench(?::[a-z-]+)?\b/g)].map((match) => match[0]);
|
|
132
|
+
if (benchCalls.some((call) => call !== 'bench:offline')) offenders.push(`${name}: ${command}`);
|
|
133
|
+
}
|
|
134
|
+
return offenders;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Benchmark tasks that name a tool the plugin does not register. */
|
|
138
|
+
export function unknownToolReferences(tasks, toolNames) {
|
|
139
|
+
const known = new Set(toolNames);
|
|
140
|
+
const problems = [];
|
|
141
|
+
for (const task of tasks) {
|
|
142
|
+
for (const name of [...(task.covers ?? []), ...(task.expect_tools ?? [])]) {
|
|
143
|
+
if (!known.has(name)) problems.push({ id: task.id, name });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return problems;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ── the checks ──────────────────────────────────────────────────────────────
|
|
150
|
+
|
|
151
|
+
const results = [];
|
|
152
|
+
function record(name, status, detail, hint) {
|
|
153
|
+
results.push({ name, status, detail, hint });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const toolClaims = [
|
|
157
|
+
{ file: 'README.md', pattern: /为它提供 \*\*(\d+) 个/g, label: 'README · 工具数' },
|
|
158
|
+
{ file: 'README.md', pattern: /(按任务分组的 (\d+) 个工具)/g, label: 'README · 目录' },
|
|
159
|
+
{ file: 'README.md', pattern: /\*\*(\d+) 个工具只在这个模式里出现\*\*/g, label: 'README · 只在该模式' },
|
|
160
|
+
{ file: 'README.md', pattern: /(\d+) 个工具按任务分为/g, label: 'README · 分组' },
|
|
161
|
+
{ file: 'docs/maintainer.md', pattern: /\*\*(\d+) 个 `molbio_\*` 工具\*\*/g, label: 'maintainer · 工具数' },
|
|
162
|
+
{ file: 'docs/rules.md', pattern: /断言 \*\*(\d+)\/(\d+) 个已注册工具/g, label: 'rules · 覆盖断言' },
|
|
163
|
+
{ file: 'docs/workflow.md', pattern: /`(\d+)\/(\d+) tools covered`/g, label: 'workflow · 覆盖断言' },
|
|
164
|
+
{ file: 'packages/molbio-panel/README.md', pattern: /注册 \*\*(\d+) 个工具\*\*/g, label: 'panel README · 工具数' },
|
|
165
|
+
{ file: 'packages/molbio-panel/README.md', pattern: /\| (\d+) 个 molbio 工具 \|/g, label: 'panel README · 表格' },
|
|
166
|
+
{ file: 'docs/change-process.md', pattern: /\*\*(\d+) 个工具\*\*/g, label: 'change-process · 工具数' },
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
const taskClaims = [
|
|
170
|
+
{ file: 'README.md', pattern: /全部 (\d+) 题/g, label: 'README · 题数' },
|
|
171
|
+
{ file: 'docs/maintainer.md', pattern: /`bench:full` 全部 (\d+) 题/g, label: 'maintainer · 题数' },
|
|
172
|
+
{ file: 'docs/workflow.md', pattern: /相关题 \/ (\d+) 题/g, label: 'workflow · 题数' },
|
|
173
|
+
{ file: 'docs/change-process.md', pattern: /(\d+) 道 benchmark 题/g, label: 'change-process · 题数' },
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
export async function runCoreChecks() {
|
|
177
|
+
results.length = 0;
|
|
178
|
+
const indexText = read('index.mjs');
|
|
179
|
+
const tools = toolNamesOf(indexText);
|
|
180
|
+
|
|
181
|
+
// 1. tool count vs every document that states it
|
|
182
|
+
const toolProblems = countMismatches(toolClaims, read, tools.length);
|
|
183
|
+
record('工具数 / 文档计数', toolProblems.length === 0 ? 'ok' : 'fail',
|
|
184
|
+
toolProblems.length === 0 ? `${tools.length} tools; ${toolClaims.length} claims match`
|
|
185
|
+
: toolProblems.map((p) => `${p.file} ${p.label}: ${p.found.join('/')} (expected ${p.expected})`).join('; '),
|
|
186
|
+
'docs 里的数字必须与 index.mjs 注册的工具数一致;改工具数就同步这 9 处。');
|
|
187
|
+
|
|
188
|
+
// 2. benchmark tasks: count claims + coverage of real tool names
|
|
189
|
+
const taskDir = join(ROOT, 'benchmark', 'tasks');
|
|
190
|
+
const tasks = [];
|
|
191
|
+
const taskFiles = existsSync(taskDir)
|
|
192
|
+
? readdirSync(taskDir).filter((file) => file.endsWith('.json')).sort()
|
|
193
|
+
: [];
|
|
194
|
+
for (const file of taskFiles) {
|
|
195
|
+
const document = JSON.parse(read(`benchmark/tasks/${file}`));
|
|
196
|
+
for (const task of document.tasks ?? []) tasks.push(task);
|
|
197
|
+
}
|
|
198
|
+
const taskProblems = countMismatches(taskClaims, read, tasks.length);
|
|
199
|
+
const unknown = unknownToolReferences(tasks, tools);
|
|
200
|
+
const duplicateIds = tasks.map((task) => task.id).filter((id, index, all) => all.indexOf(id) !== index);
|
|
201
|
+
const taskOk = taskProblems.length === 0 && unknown.length === 0 && duplicateIds.length === 0;
|
|
202
|
+
record('benchmark 任务', taskOk ? 'ok' : 'fail',
|
|
203
|
+
taskOk ? `${tasks.length} tasks; ${taskClaims.length} claims match; every covers/expect_tools name is registered`
|
|
204
|
+
: [...taskProblems.map((p) => `${p.file} ${p.label}: ${p.found.join('/')} (expected ${p.expected})`),
|
|
205
|
+
...unknown.map((u) => `task ${u.id} names unknown tool ${u.name}`),
|
|
206
|
+
...(duplicateIds.length > 0 ? [`duplicate task ids: ${duplicateIds.join(', ')}`] : [])].join('; '),
|
|
207
|
+
'任务引用的工具名必须存在;题数变化要同步 README/maintainer/workflow。');
|
|
208
|
+
|
|
209
|
+
// 3. committed artifacts vs sources
|
|
210
|
+
const artifacts = [];
|
|
211
|
+
const generator = await createGenerator({ entry: join(ROOT, 'build', 'client-entry.mjs'), baseDir: ROOT });
|
|
212
|
+
for (const targetRoot of [ROOT, join(ROOT, 'packages', 'molbio-panel')]) {
|
|
213
|
+
const manifest = JSON.parse(readFileSync(join(targetRoot, 'package.json'), 'utf8'));
|
|
214
|
+
const clientRel = typeof manifest.exports?.['./client'] === 'string'
|
|
215
|
+
? manifest.exports['./client']
|
|
216
|
+
: manifest.exports?.['./client']?.default;
|
|
217
|
+
if (typeof clientRel !== 'string') continue;
|
|
218
|
+
const output = join(targetRoot, clientRel);
|
|
219
|
+
artifacts.push({
|
|
220
|
+
label: `${manifest.name} ${clientRel}`,
|
|
221
|
+
expected: generator.renderBundle(manifest.name).text,
|
|
222
|
+
actual: existsSync(output) ? readFileSync(output, 'utf8') : undefined,
|
|
223
|
+
hint: 'node build/client-bundle.mjs',
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const rows = rowBlockOf(read('preset/molbio-lab/agent.cordis.yml'));
|
|
227
|
+
const meta = read('preset/molbio-lab/preset.yml');
|
|
228
|
+
const displayName = /^name:\s*(.+)$/m.exec(meta)?.[1]?.trim();
|
|
229
|
+
const description = /^description:\s*(.+)$/m.exec(meta)?.[1];
|
|
230
|
+
if (rows !== undefined && description !== undefined) {
|
|
231
|
+
artifacts.push({
|
|
232
|
+
label: 'cordis.patch.yml',
|
|
233
|
+
expected: buildPatch({ rows, description, displayName }),
|
|
234
|
+
actual: read('cordis.patch.yml'),
|
|
235
|
+
hint: 'node build/preset-patch.mjs',
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
const staleArtifacts = artifactMismatches(artifacts);
|
|
239
|
+
const missingArtifacts = artifacts.filter((entry) => entry.actual === undefined);
|
|
240
|
+
record('构建产物', staleArtifacts.length === 0 && missingArtifacts.length === 0 ? 'ok' : 'fail',
|
|
241
|
+
staleArtifacts.length === 0 && missingArtifacts.length === 0
|
|
242
|
+
? `${artifacts.length} artifact(s) match their sources`
|
|
243
|
+
: [...staleArtifacts.map((entry) => `${entry.label} STALE → ${entry.hint}`),
|
|
244
|
+
...missingArtifacts.map((entry) => `${entry.label} MISSING → ${entry.hint}`)].join('; '),
|
|
245
|
+
'产物必须与源一起提交;不要手改,重跑生成器。');
|
|
246
|
+
|
|
247
|
+
// 4. version + CHANGELOG
|
|
248
|
+
const manifest = JSON.parse(read('package.json'));
|
|
249
|
+
const panel = JSON.parse(read('packages/molbio-panel/package.json'));
|
|
250
|
+
const section = changelogSection(read('CHANGELOG.md'), manifest.version);
|
|
251
|
+
const panelProblem = versionShapeProblem(panel.version);
|
|
252
|
+
const versionOk = section.found && panelProblem === undefined;
|
|
253
|
+
record('版本与 CHANGELOG', versionOk ? 'ok' : 'fail',
|
|
254
|
+
versionOk ? `${manifest.version} has a CHANGELOG section; panel ${panel.version}`
|
|
255
|
+
: [!section.found ? `CHANGELOG has no section for ${manifest.version}` : '',
|
|
256
|
+
panelProblem ? `panel version: ${panelProblem}` : ''].filter(Boolean).join('; '),
|
|
257
|
+
'改版本号必须同时写 CHANGELOG 该版本段落;面板版本必须是 x.y.z。');
|
|
258
|
+
|
|
259
|
+
// 5. GitHub Release body: new tools + fixes, and nothing else
|
|
260
|
+
let releaseProblem;
|
|
261
|
+
let releaseBody = '';
|
|
262
|
+
try {
|
|
263
|
+
releaseBody = releaseNotes(`v${manifest.version}`);
|
|
264
|
+
for (const line of releaseBody.split('\n')) {
|
|
265
|
+
if (line === '' || line === '## 新增工具' || line === '## 修复') continue;
|
|
266
|
+
if (!line.startsWith('- ')) {
|
|
267
|
+
releaseProblem = `unexpected line in the release body: ${line}`;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (releaseProblem === undefined && /npm install|npm entries|CHANGELOG|blob\/v/.test(releaseBody)) {
|
|
272
|
+
releaseProblem = 'the release body carries install/admin text';
|
|
273
|
+
}
|
|
274
|
+
} catch (error) {
|
|
275
|
+
releaseProblem = error instanceof Error ? error.message : String(error);
|
|
276
|
+
}
|
|
277
|
+
record('发布说明', releaseProblem === undefined ? 'ok' : 'fail',
|
|
278
|
+
releaseProblem === undefined
|
|
279
|
+
? `v${manifest.version}: ${releaseBody.split('\n').filter((line) => line.startsWith('- ')).length} bullet(s), new tools + fixes only`
|
|
280
|
+
: releaseProblem,
|
|
281
|
+
'GitHub Release 只收 `### 新增工具` / `### 修复` 的顶层 bullet;格式见 docs/change-process.md §5。');
|
|
282
|
+
|
|
283
|
+
// 6. benchmark policy: routine scripts never spend tokens
|
|
284
|
+
const modelLeaks = modelRunsInRoutineScripts(manifest.scripts);
|
|
285
|
+
record('benchmark 策略', modelLeaks.length === 0 ? 'ok' : 'fail',
|
|
286
|
+
modelLeaks.length === 0 ? 'no routine (test*) script runs the real model; model runs stay opt-in'
|
|
287
|
+
: modelLeaks.join('; '),
|
|
288
|
+
'真实模型评测只在新工具/优化工具时按需跑(rules.md §6);npm test 与 CI 只跑 --offline。');
|
|
289
|
+
|
|
290
|
+
// 7. edits git cannot see (content differs from the index, status says clean)
|
|
291
|
+
try {
|
|
292
|
+
const dirty = new Set(execFileSync('git', ['status', '--porcelain', '-z'], { cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })
|
|
293
|
+
.split('\0').filter(Boolean).map((entry) => entry.slice(3)));
|
|
294
|
+
const index = new Map();
|
|
295
|
+
for (const entry of execFileSync('git', ['ls-files', '-s', '-z'], { cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).split('\0').filter(Boolean)) {
|
|
296
|
+
const [metaText, path] = entry.split('\t');
|
|
297
|
+
const [mode, sha] = metaText.split(' ');
|
|
298
|
+
if (path !== undefined && mode !== '120000') index.set(path, sha);
|
|
299
|
+
}
|
|
300
|
+
const textExtensions = new Set(['.mjs', '.js', '.json', '.md', '.yml', '.yaml', '.svg', '.txt', '.csv', '.tsv', '.gitignore', '.gitattributes', '.gff3']);
|
|
301
|
+
const entries = [];
|
|
302
|
+
for (const [path, indexSha] of index) {
|
|
303
|
+
const absolute = join(ROOT, path);
|
|
304
|
+
if (!existsSync(absolute)) continue;
|
|
305
|
+
const stats = statSync(absolute);
|
|
306
|
+
if (!stats.isFile() || stats.size > 4 * 1024 * 1024) continue;
|
|
307
|
+
if (!textExtensions.has(path.slice(path.lastIndexOf('.'))) && path !== 'LICENSE' && !path.endsWith('.d.ts')) continue;
|
|
308
|
+
const bytes = readFileSync(absolute);
|
|
309
|
+
if (bytes.subarray(0, 8192).includes(0)) continue; // binary fixture
|
|
310
|
+
const text = normalize(bytes.toString('utf8'));
|
|
311
|
+
const workSha = createHash('sha1').update(`blob ${Buffer.byteLength(text)}\0`).update(text).digest('hex');
|
|
312
|
+
entries.push({ path, indexSha, workSha });
|
|
313
|
+
}
|
|
314
|
+
const hidden = invisibleEdits(entries, dirty);
|
|
315
|
+
record('工作树隐形改动', hidden.length === 0 ? 'ok' : 'fail',
|
|
316
|
+
hidden.length === 0 ? `${entries.length} tracked text files match the index`
|
|
317
|
+
: `${hidden.map((entry) => entry.path).join(', ')} differ from the index but git status calls them clean — run \`touch <file>\` then \`git add -A\`, or the commit will silently drop them`,
|
|
318
|
+
'OPS/编辑器若保留 mtime,同尺寸改动会落进 git 的 stat 缓存盲区。');
|
|
319
|
+
} catch (error) {
|
|
320
|
+
record('工作树隐形改动', 'skip', `git unavailable: ${error instanceof Error ? error.code ?? error.message : String(error)}`, '在装有 git 的普通终端运行本门禁。');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 8. DSH baseline (declared by the preset header) vs the installed harness
|
|
324
|
+
const baseline = /# Baseline:.*?dsh\s+(\S+)/.exec(read('preset/molbio-lab/agent.cordis.yml'))?.[1];
|
|
325
|
+
let installed;
|
|
326
|
+
try {
|
|
327
|
+
const harnessRoot = findHarnessRoot(process.env.DSH_HARNESS_ROOT);
|
|
328
|
+
installed = harnessRoot === undefined ? undefined : JSON.parse(readFileSync(join(harnessRoot, 'package.json'), 'utf8')).version;
|
|
329
|
+
} catch {
|
|
330
|
+
installed = undefined;
|
|
331
|
+
}
|
|
332
|
+
if (baseline === undefined || installed === undefined) {
|
|
333
|
+
record('DSH 基线', 'skip', `baseline ${baseline ?? 'unreadable'}; installed ${installed ?? 'not found'}`,
|
|
334
|
+
'preset 头部应当有 `# Baseline: ... dsh <version>`;本机需要安装一份 DSH。');
|
|
335
|
+
} else if (installed === baseline) {
|
|
336
|
+
record('DSH 基线', 'ok', `installed ${installed} matches the declared baseline`);
|
|
337
|
+
} else {
|
|
338
|
+
record('DSH 基线', strict ? 'fail' : 'warn',
|
|
339
|
+
`installed ${installed} != declared baseline ${baseline}; preset-health/contract/drift-probe will report drift that is not YOUR change`,
|
|
340
|
+
'升级本机 DSH,或把改动放到基线版本上验证;CI 已 pin 该版本。');
|
|
341
|
+
}
|
|
342
|
+
return { tools, tasks, artifacts };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ── the guards must be able to fail ─────────────────────────────────────────
|
|
346
|
+
|
|
347
|
+
export function runMutationCases() {
|
|
348
|
+
const cases = [];
|
|
349
|
+
const check = (name, caught, detail) => cases.push({ name, caught, detail });
|
|
350
|
+
|
|
351
|
+
const wrongCount = countMismatches(
|
|
352
|
+
[{ file: 'x.md', pattern: /(\d+) tools/g, label: 'x' }],
|
|
353
|
+
() => 'this file says 63 tools', 72);
|
|
354
|
+
check('文档计数守卫', wrongCount.length === 1, 'a doc claiming 63 against 72 is caught');
|
|
355
|
+
|
|
356
|
+
const wrongTask = countMismatches(
|
|
357
|
+
[{ file: 'x.md', pattern: /(\d+) tasks/g, label: 'x' }],
|
|
358
|
+
() => 'this file says 70 tasks', 73);
|
|
359
|
+
check('题数守卫', wrongTask.length === 1, 'a doc claiming 70 against 73 is caught');
|
|
360
|
+
|
|
361
|
+
const stale = artifactMismatches([{ label: 'a', expected: 'new text\n', actual: 'old text\n' }]);
|
|
362
|
+
check('产物守卫', stale.length === 1, 'a stale artifact is caught');
|
|
363
|
+
|
|
364
|
+
const hidden = invisibleEdits([{ path: 'a.mjs', indexSha: 'aaa', workSha: 'bbb' }], new Set());
|
|
365
|
+
const visible = invisibleEdits([{ path: 'a.mjs', indexSha: 'aaa', workSha: 'bbb' }], new Set(['a.mjs']));
|
|
366
|
+
check('隐形改动守卫', hidden.length === 1 && visible.length === 0, 'a clean-but-changed file is caught; a normally modified one is not');
|
|
367
|
+
|
|
368
|
+
const unknown = unknownToolReferences([{ id: 't', covers: ['molbio_gone'] }], ['molbio_here']);
|
|
369
|
+
check('任务工具名守卫', unknown.length === 1, 'a task naming a removed tool is caught');
|
|
370
|
+
|
|
371
|
+
const missing = changelogSection('# Changelog\n\n## [0.1.0]\n', '0.2.0');
|
|
372
|
+
check('CHANGELOG 守卫', missing.found === false, 'a version with no section is caught');
|
|
373
|
+
|
|
374
|
+
const emptyNotes = (() => {
|
|
375
|
+
try {
|
|
376
|
+
renderNotes({ new: [], fix: [] });
|
|
377
|
+
return false;
|
|
378
|
+
} catch {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
})();
|
|
382
|
+
check('发布说明守卫', emptyNotes, 'a release entry with no tool/fix bullets is refused');
|
|
383
|
+
|
|
384
|
+
const modelLeak = modelRunsInRoutineScripts({
|
|
385
|
+
test: 'node benchmark/run.mjs --model --changed',
|
|
386
|
+
'test:unit': 'node --run bench:full',
|
|
387
|
+
'test:ok': 'node --run bench:offline',
|
|
388
|
+
bench: 'node benchmark/run.mjs --model',
|
|
389
|
+
});
|
|
390
|
+
check('benchmark 策略守卫', modelLeak.length === 2, 'a routine script that calls the model is caught; bench:offline and the opt-in bench script are not');
|
|
391
|
+
|
|
392
|
+
return cases;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// ── suite runner (needs a shell that may spawn node) ────────────────────────
|
|
396
|
+
|
|
397
|
+
function runSuites() {
|
|
398
|
+
const suites = [
|
|
399
|
+
{ label: 'prompt', args: ['test/prompt.mjs'] },
|
|
400
|
+
{ label: 'offline benchmark', args: ['benchmark/run.mjs', '--offline'] },
|
|
401
|
+
{ label: 'smoke', args: ['test/smoke.mjs'] },
|
|
402
|
+
];
|
|
403
|
+
const output = [];
|
|
404
|
+
for (const suite of suites) {
|
|
405
|
+
try {
|
|
406
|
+
execFileSync(process.execPath, suite.args, { cwd: ROOT, env: { ...process.env, MOLBIO_AUTO_VIEW: '0' }, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
407
|
+
output.push({ label: suite.label, status: 'ok' });
|
|
408
|
+
} catch (error) {
|
|
409
|
+
const blocked = error?.code === 'EPERM' || error?.code === 'EACCES';
|
|
410
|
+
output.push({ label: suite.label, status: blocked ? 'skip' : 'fail', detail: blocked ? 'sandbox blocks child processes; run it in a normal shell' : (error?.stderr?.toString().trim().split('\n').pop() ?? String(error?.code)) });
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return output;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ── report ──────────────────────────────────────────────────────────────────
|
|
417
|
+
|
|
418
|
+
const SYMBOL = { ok: 'ok ', warn: 'WARN', fail: 'FAIL', skip: 'skip' };
|
|
419
|
+
|
|
420
|
+
function printReport() {
|
|
421
|
+
console.log('dsh-molbio-tools · pre-commit check' + (strict ? ' (strict)' : ''));
|
|
422
|
+
console.log('');
|
|
423
|
+
for (const result of results) {
|
|
424
|
+
console.log(` ${SYMBOL[result.status]} ${result.name} — ${result.detail}`);
|
|
425
|
+
if (result.status !== 'ok' && result.hint !== undefined) console.log(` ↳ ${result.hint}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
let failed = false;
|
|
430
|
+
|
|
431
|
+
if (selfTestOnly) {
|
|
432
|
+
const cases = runMutationCases();
|
|
433
|
+
for (const testCase of cases) {
|
|
434
|
+
console.log(` ${testCase.caught ? 'ok ' : 'FAIL'} ${testCase.name} — ${testCase.detail}`);
|
|
435
|
+
if (!testCase.caught) failed = true;
|
|
436
|
+
}
|
|
437
|
+
} else {
|
|
438
|
+
const mutation = runMutationCases();
|
|
439
|
+
const mutationFailed = mutation.filter((testCase) => !testCase.caught);
|
|
440
|
+
await runCoreChecks();
|
|
441
|
+
results.push({
|
|
442
|
+
name: '守卫自检',
|
|
443
|
+
status: mutationFailed.length === 0 ? 'ok' : 'fail',
|
|
444
|
+
detail: mutationFailed.length === 0 ? `${mutation.length} mutation case(s) caught` : `${mutationFailed.map((c) => c.name).join(', ')} did not catch its mutation`,
|
|
445
|
+
hint: '一个从没红过的守卫不算守卫(rules.md §9)。',
|
|
446
|
+
});
|
|
447
|
+
if (withSuites) {
|
|
448
|
+
for (const suite of runSuites()) {
|
|
449
|
+
results.push({ name: `套件 · ${suite.label}`, status: suite.status, detail: suite.detail ?? 'passed', hint: 'npm test 的一部分' });
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
printReport();
|
|
453
|
+
const failures = results.filter((result) => result.status === 'fail');
|
|
454
|
+
const warnings = results.filter((result) => result.status === 'warn');
|
|
455
|
+
failed = failures.length > 0;
|
|
456
|
+
console.log('');
|
|
457
|
+
console.log(failed
|
|
458
|
+
? `结论: FAIL (${failures.length} failed${warnings.length > 0 ? `, ${warnings.length} warning` : ''}) — 修好上面的问题再提交`
|
|
459
|
+
: `结论: PASS${warnings.length > 0 ? ` (${warnings.length} warning)` : ''} — 下一步见 docs/change-process.md`);
|
|
460
|
+
if (!withSuites) console.log('提示: `node build/check.mjs --suites` 会额外跑 prompt / offline benchmark / smoke。');
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
process.exitCode = failed ? 1 : 0;
|
package/build/client-bundle.mjs
CHANGED
|
@@ -40,7 +40,7 @@ const checkOnly = process.argv.slice(2).includes('--check');
|
|
|
40
40
|
/**
|
|
41
41
|
* The bundles to emit. The SAME browser half ships through two channels:
|
|
42
42
|
*
|
|
43
|
-
* - `dsh-molbio-tools` — the plugin package: one install gives the
|
|
43
|
+
* - `dsh-molbio-tools` — the plugin package: one install gives the 72 tools
|
|
44
44
|
* plus the panel (its host half also registers the tools).
|
|
45
45
|
* - `dsh-molbio-panel` — a panel-only package: installing it adds the tab to a
|
|
46
46
|
* profile WITHOUT dragging the tools into every session of that profile,
|
package/build/panel-core.mjs
CHANGED
|
@@ -638,10 +638,22 @@ export function paperSummary(paper) {
|
|
|
638
638
|
return parts.join(' · ');
|
|
639
639
|
}
|
|
640
640
|
|
|
641
|
-
/**
|
|
641
|
+
/**
|
|
642
|
+
* The URL a paper's title links to, when it has one.
|
|
643
|
+
*
|
|
644
|
+
* Only http(s) survives: the value reaches an `<a href>` in the panel, and
|
|
645
|
+
* `paper.url` comes from tool arguments and from web results — neither is a
|
|
646
|
+
* trusted scheme (a `javascript:` URL would run on click). The PMID branch is
|
|
647
|
+
* digits-only for the same reason.
|
|
648
|
+
*/
|
|
642
649
|
export function paperLink(paper) {
|
|
643
|
-
if (typeof paper.url === 'string'
|
|
644
|
-
|
|
650
|
+
if (typeof paper.url === 'string') {
|
|
651
|
+
const url = paper.url.trim();
|
|
652
|
+
if (/^https?:\/\//i.test(url)) return url;
|
|
653
|
+
}
|
|
654
|
+
if (typeof paper.pmid === 'string' && /^\d+$/.test(paper.pmid.trim())) {
|
|
655
|
+
return `https://pubmed.ncbi.nlm.nih.gov/${paper.pmid.trim()}/`;
|
|
656
|
+
}
|
|
645
657
|
return undefined;
|
|
646
658
|
}
|
|
647
659
|
|