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 CHANGED
@@ -10,12 +10,53 @@
10
10
  改为按**包名**引用后模块缓存问题随之消失——没有拷贝,也就没有需要保持同步的版本目录。
11
11
  下文历史条目里出现的 `vN` 目录保持原样,作为当时的记录。
12
12
 
13
+ ## [0.28.2] — 2026-12-04(审计修复 + 参数校验收紧 + 发布流程门禁)
14
+
15
+ **工具数 72 不变,benchmark 73 题不变;面板包 0.1.17 → 0.1.18**(浏览器半包含同一批修复,
16
+ 两个 npm 条目在同一个 tag 下发布)。这一版来自一次全面审计:修掉 10 类会给出错误结果或崩溃的缺陷,
17
+ 把"拼错参数照常成功"从结构上根除,并给仓库装上了提交前门禁。
18
+
19
+ ### 修复
20
+
21
+ - `molbio_parse_genbank`:折行的 `join()` location 不再被截断,超大 `join()` 不再 `RangeError`。
22
+ - `molbio_batch_analyze`:1 Mb 基因组的 ORF 汇总不再崩溃;glob 匹配改为线性,异常 `*` 模式不再挂起。
23
+ - `molbio_pcr_simulate`:环状模板不再重复报同一位点/同一条带;全长产物序列不再被截断;候选过多时明确标记 `truncated`。
24
+ - `molbio_fasta_fastq`:FASTA 中 `;` 开头的注释行不再被拼进序列,长度与 GC% 不再错。
25
+ - `molbio_design_taqman`:不再推荐含 `N` 的探针(此类探针无法订购)。
26
+ - 参数校验:未声明的参数直接报错并列出合法参数名;数值 enum 与嵌套对象同样校验。
27
+ - 安全:自动打开图片只接受 `.svg`/HTML 白名单扩展名;论文链接只放行 `http(s)://`。
28
+ - 网络与服务不可用不再报成参数错误,模型不会为此反复改参数重试。
29
+ - `attach_image` 只给开关、没给路径时返回 `image_note`;`molbio_signal_peptide` 的失败原因出现在文本里。
30
+
31
+ ### 内部(不计入 GitHub Release 说明)
32
+
33
+ - 新增 `docs/audit-2026-12.md`(审计记录)与 `docs/change-process.md`(变更 SOP)。
34
+ - 新增 `build/check.mjs` 预检门禁:文档计数、benchmark 任务名、构建产物、版本/CHANGELOG、
35
+ Release 正文格式、git 隐形改动、DSH 基线;并入 `npm test` 与 CI。
36
+ - 真实模型 benchmark 明确为**按需**(仅新增/优化工具时),常规门禁只跑零成本的 `bench:offline`。
37
+ - GitHub Release 正文改为只取 `### 新增工具` / `### 修复` 的顶层条目,不再附安装说明与链接。
38
+ - 文档计数(64→72、65→73)、版本号、兼容性声明与 `.gitignore` 全部对齐;审计基线 DSH 0.2.3-alpha.2。
39
+
40
+ ---
41
+
13
42
  ## [0.28.1] — 2026-12-01(提示面受测化 + 文件输入收敛 + 判分口径修正)
14
43
 
15
44
  **工具数 72 不变,benchmark 73 题不变。** 这一版全部是 0.28.0 之后的提示词与工具接口修复:`prompt` 面
16
45
  第一次成为受测产物,四个工具补齐了文件输入/输出边界,三处 benchmark 判分口径被修正。没有新增工具,
17
46
  `engines`、preset 行清单与面板包均未改。
18
47
 
48
+ ### 修复
49
+
50
+ - `molbio_parse_genbank` 支持 `path` 文件输入,不再要求把序列重打一遍。
51
+ - `molbio_align` 支持 `path1`/`path2`,并识别 FASTA / GenBank / SnapGene。
52
+ - `molbio_editing_outcome` 的 `paths` 支持多记录 FASTA。
53
+ - `molbio_pcr_simulate` 对 5' 克隆尾给出明确诊断,不再报假的 `no product`。
54
+ - `molbio_verify_sanger` 对长 trace 与局部比对窗给出 PARTIAL 与改用建议。
55
+ - `molbio_enzyme_lookup` 新增 `only_cutting`;`molbio_restriction_sites` 的 `common` 默认只列真正切开的酶。
56
+ - `molbio_conservation` 的超长错误信息指向 `molbio_align`。
57
+ - `molbio_clone_primers` 明确反向引物结合段的订购方向。
58
+ - 提示段重写并纳入测试:预算、行宽、无版本标记、覆盖与去重五条不变量。
59
+
19
60
  ### 1. 提示面(prompt)受测化
20
61
 
21
62
  - **`PROMPT_SECTION` 重写**:按问题路由(72 个工具全覆盖)+ 8 条硬规则 + 5 条约定;删掉 `(v19)`/`(v28)`
package/README.md CHANGED
@@ -751,20 +751,22 @@ agent 的 shell 子进程继承**,内联参数会出现在对话记录与工
751
751
  **发布(CD)**:CI 是 `.github/workflows/test.yml`(push / PR 跑全套,双平台),CD 是
752
752
  `.github/workflows/release.yml`——**推一个 `v*` tag 就会**在被打 tag 的提交上重跑全套、过
753
753
  `build/release-preflight.mjs` 的发布前置检查,然后用 npm 的 **Trusted Publishing(OIDC)**
754
- 把两个 npm 条目分开发布(仓库里没有任何长期 token),最后用 CHANGELOG 该版本段落建 GitHub Release。
754
+ 把两个 npm 条目分开发布(仓库里没有任何长期 token),最后用该版本段落里的
755
+ `### 新增工具` / `### 修复` 生成 GitHub Release 正文(只含新增工具与修复,不含内部改动)。
755
756
  两个包的**首次发布必须由人手动做一次**(可信发布要求包已存在于 npm),步骤见
756
757
  [docs/workflow.md](docs/workflow.md) 第 4 节。
757
758
 
758
759
  想评估"模型到底会不会用这些工具",看 **[benchmark/README.md](benchmark/README.md)**:
759
760
  `npm run bench:offline` 零成本校验期望值(在 `npm test` 里),`npm run bench` 用真实模型
760
761
  跑 **core 档 14 题**,`npm run bench:full` 跑**全部 73 题(覆盖 72/72 个工具)**。
762
+ 真实模型评测**按需**:只在新工具或优化/改动已有工具时跑,平时与 CI 都不跑。
761
763
 
762
764
  > **改动与 benchmark 的关系(硬规则)**:新增或改动任何工具行为,**必须**新增/更新对应的
763
- > benchmark 任务并重跑;没有改动就不必重跑。日常只需要一条命令——
764
- > `node benchmark/run.mjs --model --changed`——它会从你的改动反推出该跑哪几题
765
- > (`lib.mjs` 这类共享库会自动放大到全量),改动只在文档/测试时则直接回答"无事可跑"。
766
- > `test/benchmark-coverage.mjs` 会拦住"新工具没有任务"(断言 72/72 覆盖),
767
- > `bench --offline` 会拦住"期望值过期"。完整对照表见
765
+ > benchmark 任务并按需跑一次真实模型评测;没有改动就不必动。需要跑时用
766
+ > `node benchmark/run.mjs --model --changed`——它从你的改动反推出该跑哪几题
767
+ > (先加 `--list` 可零成本看判断结果;`lib.mjs` 这类共享库会自动放大到全量)。
768
+ > 常规门禁只跑两道零成本检查:`test/benchmark-coverage.mjs` 拦住"新工具没有任务"
769
+ > (断言 72/72 覆盖),`bench --offline` 拦住"期望值过期"。完整对照表见
768
770
  > [docs/workflow.md](docs/workflow.md) 第 2 节。
769
771
 
770
772
  > **benchmark 已经查出的一个真实缺陷**:`molbio_design_primers` 返回的引物对把
package/batch.mjs CHANGED
@@ -23,7 +23,6 @@ export const BATCH_LIMITS = {
23
23
  maxFiles: 500,
24
24
  maxFileBytes: 50 * 1024 * 1024,
25
25
  maxTotalBytes: 500 * 1024 * 1024,
26
- maxOrfBases: 2_000_000,
27
26
  maxEnzymes: 20,
28
27
  };
29
28
 
@@ -43,17 +42,46 @@ export function detectBatchFormat(path, text) {
43
42
  return 'text';
44
43
  }
45
44
 
46
- /** Convert a simple basename glob (*, ?) to a RegExp. */
47
- export function globToRegExp(pattern) {
48
- const source = String(pattern)
49
- // A literal backslash must be escaped before anything else; otherwise the
50
- // following replaceAll calls turn it into a regex escape instead of a
51
- // filename character.
52
- .replaceAll('\\', '\\\\')
53
- .replace(/[.+^$()|[\]{}]/g, '\\$&')
54
- .replaceAll('*', '.*')
55
- .replaceAll('?', '.');
56
- return new RegExp('^' + source + '$', 'i');
45
+ /**
46
+ * Match one basename against a simple glob (`*` = any run, `?` = one character,
47
+ * ASCII case-insensitive).
48
+ *
49
+ * Deliberately NOT a RegExp. Translating `*` to `.*` makes a caller-supplied
50
+ * pattern such as `*a*a*a*a*a*a*a*b` backtrack exponentially (measured: ~1.4 s
51
+ * on a 28-character name, and every extra `*` multiplies it), so a pattern the
52
+ * model can mistype could stall the tool. This matcher is a two-pointer scan
53
+ * with ONE backtrack point: O(pattern × name), never exponential.
54
+ */
55
+ export function globMatches(pattern, name) {
56
+ const glob = String(pattern);
57
+ const text = String(name);
58
+ let globIndex = 0;
59
+ let textIndex = 0;
60
+ let star = -1;
61
+ let resume = 0;
62
+ while (textIndex < text.length) {
63
+ const globChar = glob[globIndex];
64
+ if (globIndex < glob.length && (globChar === '?' || globChar.toLowerCase() === text[textIndex].toLowerCase())) {
65
+ globIndex += 1;
66
+ textIndex += 1;
67
+ continue;
68
+ }
69
+ if (globIndex < glob.length && globChar === '*') {
70
+ star = globIndex;
71
+ resume = textIndex;
72
+ globIndex += 1;
73
+ continue;
74
+ }
75
+ if (star !== -1) {
76
+ resume += 1;
77
+ textIndex = resume;
78
+ globIndex = star + 1;
79
+ continue;
80
+ }
81
+ return false;
82
+ }
83
+ while (globIndex < glob.length && glob[globIndex] === '*') globIndex += 1;
84
+ return globIndex === glob.length;
57
85
  }
58
86
 
59
87
  /** Parse one sequence file into its name/topology/sequence/features. */
@@ -142,16 +170,20 @@ export function analyzeSequenceFile(input) {
142
170
  }
143
171
  const orfMinAa = input.orfMinAa ?? 0;
144
172
  if (orfMinAa > 0) {
145
- if (totalBases > BATCH_LIMITS.maxOrfBases) {
146
- row.orf_count = 0;
147
- row.longest_orf_aa = 0;
148
- row.orf_skipped = true;
149
- } else {
150
- const { orfs } = translateFrames(sequence, 'all', input.codonTable ?? 'standard', orfMinAa);
151
- row.orf_count = orfs.length;
152
- row.longest_orf_aa = orfs.length === 0 ? 0 : Math.max(...orfs.map((orf) => orf.length_aa));
153
- row.orf_skipped = false;
173
+ // No size guard here: `normalizeSequence` already rejects anything above
174
+ // 1 Mb, so the previous 2 Mb threshold could never fire — a dead limit that
175
+ // read like protection. The reduction is a loop, not `Math.max(...orfs)`:
176
+ // a 1 Mb genome with min length 1 aa yields ~166k ORFs, and spreading that
177
+ // into an argument list throws RangeError, which the tool turned into an
178
+ // "error" row for a perfectly valid file.
179
+ const { orfs } = translateFrames(sequence, 'all', input.codonTable ?? 'standard', orfMinAa);
180
+ row.orf_count = orfs.length;
181
+ let longestOrfAa = 0;
182
+ for (const orf of orfs) {
183
+ if (orf.length_aa > longestOrfAa) longestOrfAa = orf.length_aa;
154
184
  }
185
+ row.longest_orf_aa = longestOrfAa;
186
+ row.orf_skipped = false;
155
187
  }
156
188
  if (format === 'fasta' || format === 'fastq') {
157
189
  const stats = entryStats(parsed.fastaEntries ?? parsed.fastqEntries ?? [], format === 'fastq');
@@ -48,6 +48,12 @@ It needs no model, takes a few hundred milliseconds, and is part of `npm test`.
48
48
  `--model` spawns `dsh --profile molbio-bench` once per task and grades the event
49
49
  stream. It costs tokens, so it is opt-in.
50
50
 
51
+ **When it runs:** only when a tool is added, or an existing tool is optimised or
52
+ changed in a way that can alter what a task observes. It never runs in `npm test`
53
+ and never in CI — those keep `--offline` and the frozen-response replay. `--changed`
54
+ (or `--list --changed` first, which is free) is how you scope it to the tools a
55
+ diff actually touches.
56
+
51
57
  **`--model` refuses to run while `--offline` fails.** A stale expected value
52
58
  would otherwise be reported as a model failure — the most misleading outcome a
53
59
  benchmark can produce.
@@ -24,8 +24,8 @@
24
24
  "assertions": [
25
25
  {
26
26
  "where": "tool",
27
- "pattern": "extracted (vector|sequence) 101-200 \\(100 bp\\)",
28
- "note": "the tool ran with the sequence it was given. Measured behaviour worth knowing: in the full-tier run the model called `molbio_extract_region` THREE times and every call came back `Error: provide either `vector` (a sequence) or `vector_path`` — it never found the parameter, then reconstructed the region by hand and verified it with `molbio_align` (which it did correctly). This assertion is therefore a genuine TOOL-SELECTION/argument finding: the parameter is named `vector`, the description says 'a sequence', and the model reached for something else. Recorded in benchmark/README.md."
27
+ "pattern": "extracted sequence 101-200 \\(100 bp\\)",
28
+ "note": "the tool ran with the sequence it was given. Measured behaviour worth recording: in the original full-tier run the model called `molbio_extract_region` THREE times, every call failed on the argument name, and it rebuilt the region by hand (correctly). Root cause was upstream of the model: `resolveVector` read only `args.vector` while the schema advertises `sequence`/`source_path`. Undeclared keys are now REJECTED with the valid names in the message, and this verification calls the declared `sequence`, so the invocation measures the tool rather than a silent no-op."
29
29
  },
30
30
  {
31
31
  "where": "tool",
@@ -232,7 +232,7 @@ export function invocationsFor(task) {
232
232
 
233
233
  // cloning
234
234
  'region-extract': () => [
235
- { tool: 'molbio_extract_region', args: { vector: FIXTURES.CONSTRUCT, start: 101, end: 200 } },
235
+ { tool: 'molbio_extract_region', args: { sequence: FIXTURES.CONSTRUCT, start: 101, end: 200 } },
236
236
  ],
237
237
  mutagenesis: () => [
238
238
  { tool: 'molbio_mutagenesis_primers', args: { template: FIXTURES.MUTAGENESIS_TEMPLATE, mutations: [FIXTURES.MUTAGENESIS_MUTATION], tm_min: 60, tm_max: 90, max_results: 1 } },