dsh-molbio-tools 0.28.0 → 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 +98 -0
- package/README.md +8 -6
- package/batch.mjs +53 -21
- package/benchmark/README.md +6 -0
- package/benchmark/harness.mjs +11 -3
- package/benchmark/profile.mjs +2 -2
- package/benchmark/run.mjs +3 -1
- package/benchmark/sequences.mjs +16 -0
- package/benchmark/tasks/01-core.json +1 -1
- package/benchmark/tasks/02-primers.json +1 -5
- package/benchmark/tasks/04-cloning.json +2 -2
- package/benchmark/tasks/09-formats.json +1 -1
- package/benchmark/tasks/10-v28.json +1 -1
- package/benchmark/verifications.mjs +3 -9
- 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 +36 -6
- 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 +239 -140
- package/lib/client.js +89 -17
- package/package.json +11 -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/prompt.mjs +149 -0
- package/test/release.mjs +15 -8
- package/test/smoke.mjs +129 -4
- package/view.mjs +13 -1
package/lib/client.js
CHANGED
|
@@ -1668,15 +1668,35 @@ window.__ModuleLoader__.load({
|
|
|
1668
1668
|
const parts = [...cleaned.matchAll(/\d+(?:\.\.\d+)?/g)];
|
|
1669
1669
|
const numbers = [...cleaned.matchAll(/\d+/g)].map((match) => Number(match[0]));
|
|
1670
1670
|
if (numbers.length === 0) return undefined;
|
|
1671
|
+
// Reduce with a loop, never `Math.min(...numbers)`: a 20 Mb join() with a few
|
|
1672
|
+
// hundred thousand parts is a real NCBI record shape, and spreading it into
|
|
1673
|
+
// the argument list throws `RangeError: Maximum call stack size exceeded`
|
|
1674
|
+
// instead of returning a span.
|
|
1675
|
+
let start = numbers[0];
|
|
1676
|
+
let end = numbers[0];
|
|
1677
|
+
for (const number of numbers) {
|
|
1678
|
+
if (number < start) start = number;
|
|
1679
|
+
if (number > end) end = number;
|
|
1680
|
+
}
|
|
1671
1681
|
return {
|
|
1672
|
-
start
|
|
1673
|
-
end
|
|
1682
|
+
start,
|
|
1683
|
+
end,
|
|
1674
1684
|
strand: /complement/i.test(raw) ? -1 : 1,
|
|
1675
1685
|
raw: raw.trim(),
|
|
1676
1686
|
multiPart: parts.length > 1,
|
|
1677
1687
|
};
|
|
1678
1688
|
}
|
|
1679
1689
|
|
|
1690
|
+
/** Does this location still have an unclosed `(` (i.e. it wraps onto the next line)? */
|
|
1691
|
+
function isLocationOpen(text) {
|
|
1692
|
+
let depth = 0;
|
|
1693
|
+
for (const character of text) {
|
|
1694
|
+
if (character === '(') depth += 1;
|
|
1695
|
+
else if (character === ')') depth = Math.max(0, depth - 1);
|
|
1696
|
+
}
|
|
1697
|
+
return depth > 0;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1680
1700
|
/** Parse one qualifier line: /key="value" (or unquoted value). */
|
|
1681
1701
|
function parseQualifier(line) {
|
|
1682
1702
|
const match = /^\s*\/?([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(?:"([^"]*)"|(\S+))/.exec(line);
|
|
@@ -1709,6 +1729,31 @@ window.__ModuleLoader__.load({
|
|
|
1709
1729
|
let inOrigin = false;
|
|
1710
1730
|
let currentFeature = undefined;
|
|
1711
1731
|
let currentQualifier = undefined;
|
|
1732
|
+
let currentLocation = '';
|
|
1733
|
+
let locationOpen = false;
|
|
1734
|
+
let placed = false;
|
|
1735
|
+
|
|
1736
|
+
/** Publish the current feature once its location can be placed. */
|
|
1737
|
+
const placeCurrentFeature = () => {
|
|
1738
|
+
if (currentFeature === undefined) return;
|
|
1739
|
+
const parsedLocation = parseLocation(currentLocation);
|
|
1740
|
+
if (parsedLocation === undefined) return;
|
|
1741
|
+
currentFeature.location = parsedLocation;
|
|
1742
|
+
if (!placed) {
|
|
1743
|
+
features.push(currentFeature);
|
|
1744
|
+
placed = true;
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
|
|
1748
|
+
/** Count a feature that never got a placeable location, then reset per-feature state. */
|
|
1749
|
+
const finishFeature = () => {
|
|
1750
|
+
if (currentFeature !== undefined && !placed) skippedFeatures += 1;
|
|
1751
|
+
currentFeature = undefined;
|
|
1752
|
+
currentQualifier = undefined;
|
|
1753
|
+
currentLocation = '';
|
|
1754
|
+
locationOpen = false;
|
|
1755
|
+
placed = false;
|
|
1756
|
+
};
|
|
1712
1757
|
|
|
1713
1758
|
for (let i = locusIndex; i < lines.length; i++) {
|
|
1714
1759
|
const line = lines[i];
|
|
@@ -1719,29 +1764,35 @@ window.__ModuleLoader__.load({
|
|
|
1719
1764
|
}
|
|
1720
1765
|
if (inFeatures) {
|
|
1721
1766
|
if (/^ORIGIN/.test(line)) {
|
|
1767
|
+
finishFeature();
|
|
1722
1768
|
inFeatures = false;
|
|
1723
1769
|
inOrigin = true;
|
|
1724
1770
|
continue;
|
|
1725
1771
|
}
|
|
1726
1772
|
if (/^\s{5}\S/.test(line)) {
|
|
1727
1773
|
// New feature: 5 spaces, then type and location.
|
|
1774
|
+
finishFeature();
|
|
1728
1775
|
const match = /^\s{5}(\S+)\s*(.*)$/.exec(line);
|
|
1729
1776
|
if (match === null) {
|
|
1730
1777
|
skippedFeatures += 1;
|
|
1731
1778
|
continue;
|
|
1732
1779
|
}
|
|
1733
|
-
currentFeature = {
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1780
|
+
currentFeature = { type: match[1], location: undefined, qualifiers: {} };
|
|
1781
|
+
currentLocation = match[2] ?? '';
|
|
1782
|
+
locationOpen = isLocationOpen(currentLocation);
|
|
1783
|
+
placeCurrentFeature();
|
|
1784
|
+
continue;
|
|
1785
|
+
}
|
|
1786
|
+
// A location wider than the column wraps onto 21-space continuation lines
|
|
1787
|
+
// (`join(1..10,30..40,` + `50..60,70..80)`), which is how NCBI writes any
|
|
1788
|
+
// long join(). Such a line belongs to the LOCATION. It used to be read as
|
|
1789
|
+
// a qualifier continuation only, so the span silently stopped at the first
|
|
1790
|
+
// line and every downstream coordinate (map, batch table, feature counts)
|
|
1791
|
+
// sat on the wrong bases.
|
|
1792
|
+
if (locationOpen && /^\s{21}[0-9()][0-9,().^<>?\s]*$/.test(line)) {
|
|
1793
|
+
currentLocation += line.trim();
|
|
1794
|
+
locationOpen = isLocationOpen(currentLocation);
|
|
1795
|
+
placeCurrentFeature();
|
|
1745
1796
|
continue;
|
|
1746
1797
|
}
|
|
1747
1798
|
if (/^\s{21}\//.test(line) && currentFeature !== undefined) {
|
|
@@ -4938,6 +4989,11 @@ window.__ModuleLoader__.load({
|
|
|
4938
4989
|
for (const rawLine of text.split(/\r?\n/)) {
|
|
4939
4990
|
const line = rawLine.trim();
|
|
4940
4991
|
if (line === '') continue;
|
|
4992
|
+
// FASTA's comment convention: a line starting with ';' is a comment, not
|
|
4993
|
+
// sequence. It used to be appended verbatim (cleanSequence keeps letters),
|
|
4994
|
+
// so a commented file reported a longer sequence and a wrong GC% with no
|
|
4995
|
+
// warning — the most expensive kind of wrong answer.
|
|
4996
|
+
if (line.startsWith(';')) continue;
|
|
4941
4997
|
if (line.startsWith('>')) {
|
|
4942
4998
|
if (current !== undefined && current.sequence !== '') entries.push(current);
|
|
4943
4999
|
const header = line.slice(1).trim();
|
|
@@ -6320,6 +6376,10 @@ window.__ModuleLoader__.load({
|
|
|
6320
6376
|
for (let length = opts.probeLenMin; length <= opts.probeLenMax; length++) {
|
|
6321
6377
|
for (let start = windowStart; start + length - 1 <= windowEnd; start++) {
|
|
6322
6378
|
const sequence = work.slice(start, start + length);
|
|
6379
|
+
// An ambiguous base has no nearest-neighbour parameters, so `primerTm`
|
|
6380
|
+
// silently treats that step as 0 and the candidate gets a plausible-looking
|
|
6381
|
+
// Tm. A probe with an N cannot be ordered, so it must not be proposed.
|
|
6382
|
+
if (!/^[ACGT]+$/.test(sequence)) continue;
|
|
6323
6383
|
const evaluated = evaluateProbe(sequence, {
|
|
6324
6384
|
tmOpts: opts.tmOpts,
|
|
6325
6385
|
ctMolar: opts.ctMolar,
|
|
@@ -9726,10 +9786,22 @@ window.__ModuleLoader__.load({
|
|
|
9726
9786
|
return parts.join(' · ');
|
|
9727
9787
|
}
|
|
9728
9788
|
|
|
9729
|
-
/**
|
|
9789
|
+
/**
|
|
9790
|
+
* The URL a paper's title links to, when it has one.
|
|
9791
|
+
*
|
|
9792
|
+
* Only http(s) survives: the value reaches an `<a href>` in the panel, and
|
|
9793
|
+
* `paper.url` comes from tool arguments and from web results — neither is a
|
|
9794
|
+
* trusted scheme (a `javascript:` URL would run on click). The PMID branch is
|
|
9795
|
+
* digits-only for the same reason.
|
|
9796
|
+
*/
|
|
9730
9797
|
function paperLink(paper) {
|
|
9731
|
-
if (typeof paper.url === 'string'
|
|
9732
|
-
|
|
9798
|
+
if (typeof paper.url === 'string') {
|
|
9799
|
+
const url = paper.url.trim();
|
|
9800
|
+
if (/^https?:\/\//i.test(url)) return url;
|
|
9801
|
+
}
|
|
9802
|
+
if (typeof paper.pmid === 'string' && /^\d+$/.test(paper.pmid.trim())) {
|
|
9803
|
+
return `https://pubmed.ncbi.nlm.nih.gov/${paper.pmid.trim()}/`;
|
|
9804
|
+
}
|
|
9733
9805
|
return undefined;
|
|
9734
9806
|
}
|
|
9735
9807
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-molbio-tools",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.2",
|
|
4
4
|
"description": "Zero-dependency molecular-biology plugin bundle for the DeepSeek Harness: sequence analysis, primer design (incl. cross-intron qPCR primers, TaqMan hydrolysis/MGB probes with ordering CSV and multiplex compatibility, duplex thermodynamics (ΔH/ΔS/ΔG37/Tm with hairpin and dimer checks)), in-silico PCR, cloning simulation, SnapGene .dna parsing and plasmid maps, Sanger verification, protein tools (incl. helical wheel, hydropathy and charge-pH plots), methylation-aware restriction analysis with double-digest buffer checks, qPCR analysis and plotting, multiple sequence alignment that conserves every input residue, conservation analysis, sequence logos, codon-usage analysis, phylogenetic trees with bootstrap support, Newick I/O and long-name label wrapping, CpG-island/GC-skew composition analysis, k-mer dotplots, read-level FASTQ QC, vector/adapter contamination screening, FASTQ trimming/filtering, batch file analysis with CSV export, silent restriction-site mutagenesis, family-aware CRISPR gRNA design (SpCas9/SaCas9/Cas12a/Cas13) with off-target search, an opt-in hand-off that shows a generated plot to the model as an attached image, plus a browser-side right-sidebar panel (plasmid maps, sequence logos, and a rotatable realistic 3D ball-and-stick/space-filling preview of PDB/mmCIF/SDF structures drawn in the Web GUI) and a literature/protocol/experiment record system.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=24",
|
|
9
|
-
"dsh": ">=0.2.
|
|
9
|
+
"dsh": ">=0.2.2-rc.2 <0.3.0-0"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": "./index.mjs",
|
|
@@ -17,9 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build:client": "node build/client-bundle.mjs",
|
|
20
|
-
"
|
|
20
|
+
"check": "node build/check.mjs",
|
|
21
|
+
"check:strict": "node build/check.mjs --strict",
|
|
22
|
+
"check:suites": "node build/check.mjs --suites",
|
|
23
|
+
"test": "node build/check.mjs && node --run test:unit && node test/prompt.mjs && node test/contract.mjs && node test/drift-probe.mjs && node test/preset-health.mjs && node test/release.mjs && node test/benchmark-profile.mjs && node test/benchmark-score.mjs && node test/benchmark-coverage.mjs && node test/benchmark-changed.mjs && node --run bench:offline",
|
|
21
24
|
"test:unit": "node test/smoke.mjs && node test/svgpng.mjs && node test/svgio.mjs && node test/charts.mjs && node test/structure.mjs && node test/client.mjs && node test/panel-render.mjs && node test/map-card.mjs && node test/client-mount.mjs",
|
|
22
25
|
"test:smoke": "node test/smoke.mjs",
|
|
26
|
+
"test:prompt": "node test/prompt.mjs",
|
|
23
27
|
"test:svgpng": "node test/svgpng.mjs",
|
|
24
28
|
"test:charts": "node test/charts.mjs",
|
|
25
29
|
"test:svgio": "node test/svgio.mjs",
|
|
@@ -105,11 +109,11 @@
|
|
|
105
109
|
"compatibility": {
|
|
106
110
|
"dshReleases": {
|
|
107
111
|
"0.2.1-rc.1": "unknown",
|
|
108
|
-
"0.2.1-rc.2": "
|
|
109
|
-
"0.2.1-rc.3": "
|
|
112
|
+
"0.2.1-rc.2": "unknown",
|
|
113
|
+
"0.2.1-rc.3": "unknown",
|
|
110
114
|
"0.2.1-rc.4": "unknown",
|
|
111
|
-
"0.2.1-rc.5": "
|
|
112
|
-
"0.2.2-rc.1": "
|
|
115
|
+
"0.2.1-rc.5": "unknown",
|
|
116
|
+
"0.2.2-rc.1": "unknown",
|
|
113
117
|
"0.2.2-rc.2": "compatible",
|
|
114
118
|
"0.2.2-rc.3": "compatible",
|
|
115
119
|
"0.2.2-rc.4": "unknown",
|
package/pcr.mjs
CHANGED
|
@@ -39,6 +39,14 @@ export const PCR_DEFAULTS = {
|
|
|
39
39
|
min_size: 0,
|
|
40
40
|
max_size: 100000,
|
|
41
41
|
max_products: 200,
|
|
42
|
+
/**
|
|
43
|
+
* Hard ceiling on (forward site × reverse site) evaluations. A poly-A template
|
|
44
|
+
* with an 8-mer primer on each side yields ~n²/2 pairs: without a ceiling a
|
|
45
|
+
* 5 kb template allocates 12 million amplicon objects and a 1 Mb one exhausts
|
|
46
|
+
* memory. Reaching it sets `truncated`, so the caller is told the answer is
|
|
47
|
+
* partial instead of receiving a silent sample.
|
|
48
|
+
*/
|
|
49
|
+
max_pair_evaluations: 200_000,
|
|
42
50
|
/** Product sequences longer than this are not returned inline (size is). */
|
|
43
51
|
max_returned_sequence: 5000,
|
|
44
52
|
};
|
|
@@ -53,10 +61,13 @@ function baseMatches(primerBase, templateBase) {
|
|
|
53
61
|
/** The product sequence of a template, taking the top strand with a modular slice. */
|
|
54
62
|
function sliceSequence(sequence, start, length) {
|
|
55
63
|
if (length >= sequence.length) {
|
|
56
|
-
// More than one full turn of a circular template: tile it.
|
|
64
|
+
// More than one full turn of a circular template: tile it. Tiling to
|
|
65
|
+
// `length` was not enough — the slice starts at `start`, so the buffer needs
|
|
66
|
+
// `start + length` bases or a full-length product came back short (a 43 bp
|
|
67
|
+
// product starting at offset 10 returned 33 bases).
|
|
57
68
|
let out = '';
|
|
58
|
-
while (out.length < length) out += sequence;
|
|
59
|
-
return out.slice(start, start + length)
|
|
69
|
+
while (out.length < start + length) out += sequence;
|
|
70
|
+
return out.slice(start, start + length);
|
|
60
71
|
}
|
|
61
72
|
if (start + length <= sequence.length) return sequence.slice(start, start + length);
|
|
62
73
|
return sequence.slice(start) + sequence.slice(0, start + length - sequence.length);
|
|
@@ -83,9 +94,13 @@ export function findBindingSites(template, primer, strand, options = {}) {
|
|
|
83
94
|
const probe = strand === 'reverse' ? reverseComplement(primer) : primer;
|
|
84
95
|
const length = template.length;
|
|
85
96
|
if (!circular && length < probe.length) return [];
|
|
86
|
-
|
|
97
|
+
// A circular template has exactly `length` start positions. Scanning
|
|
98
|
+
// `start <= length` examined position `length`, which is position 0 again, so
|
|
99
|
+
// one real site was reported twice (as start=61 on a 60 bp template) and the
|
|
100
|
+
// duplicated site produced a duplicate amplicon.
|
|
101
|
+
const windows = circular ? length : length - probe.length + 1;
|
|
87
102
|
const sites = [];
|
|
88
|
-
for (let start = 0; start
|
|
103
|
+
for (let start = 0; start < windows; start++) {
|
|
89
104
|
let mismatches = 0;
|
|
90
105
|
let mismatchPositions = [];
|
|
91
106
|
let matched = true;
|
|
@@ -154,8 +169,15 @@ export function simulatePair(template, pair, options = {}) {
|
|
|
154
169
|
const reverseSites = findBindingSites(template, reverse, 'reverse', { ...settings, circular });
|
|
155
170
|
const amplicons = [];
|
|
156
171
|
let outOfRange = 0;
|
|
157
|
-
|
|
172
|
+
let pairsCapped = false;
|
|
173
|
+
let evaluated = 0;
|
|
174
|
+
outer: for (const forwardSite of forwardSites) {
|
|
158
175
|
for (const reverseSite of reverseSites) {
|
|
176
|
+
if (evaluated >= settings.max_pair_evaluations) {
|
|
177
|
+
pairsCapped = true;
|
|
178
|
+
break outer;
|
|
179
|
+
}
|
|
180
|
+
evaluated += 1;
|
|
159
181
|
// A product must run from the forward site's 3' end to the reverse
|
|
160
182
|
// site's 5' end, i.e. the reverse site has to lie "after" it.
|
|
161
183
|
const productStartIndex = forwardSite.start_index;
|
|
@@ -206,7 +228,7 @@ export function simulatePair(template, pair, options = {}) {
|
|
|
206
228
|
reverse_sites: reverseSites,
|
|
207
229
|
amplicons: capped,
|
|
208
230
|
amplicon_count: capped.length,
|
|
209
|
-
truncated: amplicons.length > capped.length,
|
|
231
|
+
truncated: pairsCapped || amplicons.length > capped.length,
|
|
210
232
|
out_of_range: outOfRange,
|
|
211
233
|
on_target_count: onTarget.length,
|
|
212
234
|
off_target_count: capped.length - onTarget.length,
|
package/phylo.mjs
CHANGED
|
@@ -1019,12 +1019,6 @@ export function renderTreeSvg(tree, {
|
|
|
1019
1019
|
};
|
|
1020
1020
|
});
|
|
1021
1021
|
blocks = new Map(fitted.map((entry) => [entry.leafNode, entry.block]));
|
|
1022
|
-
if (process.env.MOLBIO_PROBE_RADIAL === '1' && !fitted.every((entry) => entry.fits)) {
|
|
1023
|
-
for (const entry of fitted.filter((e) => !e.fits)) {
|
|
1024
|
-
const slot = (2 * Math.PI * (entry.reach + LABEL_GAP + entry.block.depth / 2)) / leaves.length;
|
|
1025
|
-
console.log(` FAIL size=${size} ${entry.leafNode.name.slice(0, 14)} angle=${(entry.angle * 180 / Math.PI).toFixed(0)} anchor=${entry.anchor} reach=${entry.reach.toFixed(1)} w=${entry.block.width.toFixed(1)} h=${entry.block.height.toFixed(1)} depth=${entry.block.depth.toFixed(1)} lines=${entry.block.lines.length} slot=${slot.toFixed(1)} plot=${fitsInPlot(entry.angle, entry.anchor, entry.reach, entry.block, size)} slotOk=${fitsAngularSlot(entry.reach, entry.block, leaves.length)}`);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
1022
|
if (fitted.every((entry) => entry.fits) || size <= minimumLeafFont) break;
|
|
1029
1023
|
size = Math.max(minimumLeafFont, size - 0.5);
|
|
1030
1024
|
}
|
package/seqio.mjs
CHANGED
|
@@ -21,6 +21,11 @@ export function parseFasta(text) {
|
|
|
21
21
|
for (const rawLine of text.split(/\r?\n/)) {
|
|
22
22
|
const line = rawLine.trim();
|
|
23
23
|
if (line === '') continue;
|
|
24
|
+
// FASTA's comment convention: a line starting with ';' is a comment, not
|
|
25
|
+
// sequence. It used to be appended verbatim (cleanSequence keeps letters),
|
|
26
|
+
// so a commented file reported a longer sequence and a wrong GC% with no
|
|
27
|
+
// warning — the most expensive kind of wrong answer.
|
|
28
|
+
if (line.startsWith(';')) continue;
|
|
24
29
|
if (line.startsWith('>')) {
|
|
25
30
|
if (current !== undefined && current.sequence !== '') entries.push(current);
|
|
26
31
|
const header = line.slice(1).trim();
|
package/taqman.mjs
CHANGED
|
@@ -251,6 +251,10 @@ export function probeCandidates(template, forwardInterval, reverseInterval, opts
|
|
|
251
251
|
for (let length = opts.probeLenMin; length <= opts.probeLenMax; length++) {
|
|
252
252
|
for (let start = windowStart; start + length - 1 <= windowEnd; start++) {
|
|
253
253
|
const sequence = work.slice(start, start + length);
|
|
254
|
+
// An ambiguous base has no nearest-neighbour parameters, so `primerTm`
|
|
255
|
+
// silently treats that step as 0 and the candidate gets a plausible-looking
|
|
256
|
+
// Tm. A probe with an N cannot be ordered, so it must not be proposed.
|
|
257
|
+
if (!/^[ACGT]+$/.test(sequence)) continue;
|
|
254
258
|
const evaluated = evaluateProbe(sequence, {
|
|
255
259
|
tmOpts: opts.tmOpts,
|
|
256
260
|
ctMolar: opts.ctMolar,
|
package/test/client.mjs
CHANGED
|
@@ -558,6 +558,12 @@ assert.equal(panelCore.paperSummary(parsedLibrary.papers[2]), '');
|
|
|
558
558
|
assert.equal(panelCore.paperLink(parsedLibrary.papers[0]), 'https://pubmed.ncbi.nlm.nih.gov/12345/');
|
|
559
559
|
assert.equal(panelCore.paperLink(parsedLibrary.papers[1]), 'https://example.org/review');
|
|
560
560
|
assert.equal(panelCore.paperLink(parsedLibrary.papers[2]), undefined);
|
|
561
|
+
// The link reaches an <a href>, and paper.url comes from tool arguments and web
|
|
562
|
+
// results — neither is a trusted scheme, so only http(s) may survive.
|
|
563
|
+
assert.equal(panelCore.paperLink({ url: 'javascript:alert(1)' }), undefined, 'a javascript: URL never becomes a link');
|
|
564
|
+
assert.equal(panelCore.paperLink({ url: 'file:///etc/passwd' }), undefined);
|
|
565
|
+
assert.equal(panelCore.paperLink({ url: 'https://example.org/x', pmid: '12ab' }), 'https://example.org/x');
|
|
566
|
+
assert.equal(panelCore.paperLink({ pmid: '12ab' }), undefined, 'a non-numeric PMID derives no link');
|
|
561
567
|
assert.equal(panelCore.LIBRARY_FILE, 'papers.json');
|
|
562
568
|
// The panel's file path matches the tool's default (papers.mjs DEFAULT_LIBRARY_FILE).
|
|
563
569
|
const { DEFAULT_LIBRARY_FILE } = await import('../papers.mjs');
|
package/test/contract.mjs
CHANGED
|
@@ -472,7 +472,7 @@ check('the published tarball carries the client half and exactly one plugin mani
|
|
|
472
472
|
// SUBMISSION_PACKAGE_AMBIGUOUS, plus a duplicate 427 KB client bundle in every
|
|
473
473
|
// download. The panel does not disappear for npm users: the root package's own
|
|
474
474
|
// `lib/client.js` already carries it (the panel-only package exists for people
|
|
475
|
-
// who want the tab without the
|
|
475
|
+
// who want the tab without the 72 tools).
|
|
476
476
|
assert.ok(
|
|
477
477
|
!files.includes('packages'),
|
|
478
478
|
'the root tarball must not embed packages/molbio-panel: a second `dsh` manifest inside one package is an ambiguous submission, and the panel is published separately',
|
package/test/prompt.mjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-molbio-tools/test/prompt.mjs
|
|
3
|
+
*
|
|
4
|
+
* The prompt surface is a shipped artifact: the tool:molbio section plus every
|
|
5
|
+
* tool description travels on every request, and it is what the model reads
|
|
6
|
+
* when it picks a tool. Nothing else in this suite measures it, so this file
|
|
7
|
+
* pins five properties and then PROVES each one can fail (docs/rules.md rule 9).
|
|
8
|
+
*
|
|
9
|
+
* The split of responsibility it enforces:
|
|
10
|
+
* - a tool description says what the tool does, what its arguments mean and
|
|
11
|
+
* which model or table it uses;
|
|
12
|
+
* - the section says when to reach for a tool, the cross-tool rules, and the
|
|
13
|
+
* conventions all tools share;
|
|
14
|
+
* - no rule appears in both, which is why a duplicated span is a failure.
|
|
15
|
+
*
|
|
16
|
+
* Usage: node test/prompt.mjs
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import assert from 'node:assert/strict';
|
|
20
|
+
|
|
21
|
+
const SECTION_BUDGET = 6000;
|
|
22
|
+
const MAX_LINE_CHARS = 400;
|
|
23
|
+
const DUPLICATE_WINDOW = 60;
|
|
24
|
+
|
|
25
|
+
// Tools allowed to live only in their description. Empty on purpose: every
|
|
26
|
+
// registered tool must be reachable from the section, so a new tool cannot
|
|
27
|
+
// ship invisible. Add a name here only with a reason, and keep the list short.
|
|
28
|
+
const DESCRIPTION_ONLY = new Set([]);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Audit one prompt surface.
|
|
32
|
+
*
|
|
33
|
+
* Pure, so every mutation below exercises the SAME code the real surface goes
|
|
34
|
+
* through; a guard that only ever sees valid input proves nothing.
|
|
35
|
+
*
|
|
36
|
+
* @param {{ section: string, tools: { name: string, description: string }[] }} input
|
|
37
|
+
* @param {{ budget?: number, maxLineChars?: number, window?: number, descriptionOnly?: Set<string> }} [limits]
|
|
38
|
+
* @returns {string[]} problems; empty means the surface passes.
|
|
39
|
+
*/
|
|
40
|
+
function auditPrompt({ section, tools }, limits = {}) {
|
|
41
|
+
const budget = limits.budget ?? SECTION_BUDGET;
|
|
42
|
+
const maxLineChars = limits.maxLineChars ?? MAX_LINE_CHARS;
|
|
43
|
+
const window = limits.window ?? DUPLICATE_WINDOW;
|
|
44
|
+
const descriptionOnly = limits.descriptionOnly ?? DESCRIPTION_ONLY;
|
|
45
|
+
const problems = [];
|
|
46
|
+
if (section.length > budget) {
|
|
47
|
+
problems.push(`budget: section is ${section.length} chars (max ${budget})`);
|
|
48
|
+
}
|
|
49
|
+
section.split('\n').forEach((line, index) => {
|
|
50
|
+
if (line.length > maxLineChars) {
|
|
51
|
+
problems.push(`line: line ${index + 1} is ${line.length} chars (max ${maxLineChars})`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
for (const marker of new Set(section.match(/\(v[\d.]+\)/g) ?? [])) {
|
|
55
|
+
problems.push(`version marker: ${marker} — release history belongs in CHANGELOG.md`);
|
|
56
|
+
}
|
|
57
|
+
const registered = new Set(tools.map((tool) => tool.name));
|
|
58
|
+
const mentioned = new Set(section.match(/molbio_[a-z0-9_]+/g) ?? []);
|
|
59
|
+
for (const name of registered) {
|
|
60
|
+
if (!mentioned.has(name) && !descriptionOnly.has(name)) {
|
|
61
|
+
problems.push(`coverage: ${name} is registered but never named in the section`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const name of mentioned) {
|
|
65
|
+
if (!registered.has(name)) {
|
|
66
|
+
problems.push(`coverage: ${name} is named in the section but not registered`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const sectionWindows = new Set();
|
|
70
|
+
for (let i = 0; i + window <= section.length; i += 1) sectionWindows.add(section.slice(i, i + window));
|
|
71
|
+
for (const tool of tools) {
|
|
72
|
+
const description = String(tool.description ?? '');
|
|
73
|
+
for (let i = 0; i + window <= description.length; i += 1) {
|
|
74
|
+
const span = description.slice(i, i + window);
|
|
75
|
+
if (!sectionWindows.has(span)) continue;
|
|
76
|
+
problems.push(`duplicate: ${window} chars of ${tool.name} description also sit in the section — "${span.replace(/\s+/g, ' ')}"`);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return problems;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ── the real surface ────────────────────────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
const plugin = await import('../index.mjs');
|
|
86
|
+
const registered = [];
|
|
87
|
+
const sections = [];
|
|
88
|
+
const ctx = {
|
|
89
|
+
systemPrompt: { section(options) { sections.push(options); } },
|
|
90
|
+
get() { return undefined; },
|
|
91
|
+
tools: { register(definition) { registered.push(definition); } },
|
|
92
|
+
};
|
|
93
|
+
plugin.apply(ctx);
|
|
94
|
+
|
|
95
|
+
assert.equal(sections.length, 1, 'the plugin must register exactly one prompt section');
|
|
96
|
+
const [section] = sections;
|
|
97
|
+
assert.equal(section.name, 'tool:molbio');
|
|
98
|
+
assert.equal(section.order, 110, 'tool guidance belongs in the 100-199 band, beside tool-bash');
|
|
99
|
+
assert.ok(typeof section.text === 'string' && section.text.length > 0, 'the section must carry text');
|
|
100
|
+
|
|
101
|
+
const tools = registered.map((tool) => ({ name: tool.name, description: tool.description }));
|
|
102
|
+
for (const tool of tools) {
|
|
103
|
+
assert.ok(typeof tool.description === 'string' && tool.description.length > 0, `${tool.name} must carry a description`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const problems = auditPrompt({ section: section.text, tools });
|
|
107
|
+
assert.deepEqual(problems, [], `prompt audit failed:\n ${problems.join('\n ')}`);
|
|
108
|
+
|
|
109
|
+
// ── the same guard, seen failing (docs/rules.md rule 9) ─────────────────────
|
|
110
|
+
|
|
111
|
+
const firstTool = tools[0];
|
|
112
|
+
const filler = Array.from({ length: 200 }, () => '- padding line to push the section over budget').join('\n');
|
|
113
|
+
const mutations = [
|
|
114
|
+
[
|
|
115
|
+
'an unlisted tool',
|
|
116
|
+
() => ({ section: section.text.replace(firstTool.name, 'molbio_unlisted'), tools }),
|
|
117
|
+
/coverage:/,
|
|
118
|
+
],
|
|
119
|
+
[
|
|
120
|
+
'a release marker',
|
|
121
|
+
() => ({ section: `${section.text}\n- (v19) legacy wording that should not be here.`, tools }),
|
|
122
|
+
/version marker:/,
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
'a span copied from a description',
|
|
126
|
+
() => ({ section: `${section.text}\n- ${firstTool.description.slice(0, 80)}`, tools }),
|
|
127
|
+
/duplicate:/,
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
'an over-long line',
|
|
131
|
+
() => ({ section: `${section.text}\n${'x'.repeat(MAX_LINE_CHARS + 1)}`, tools }),
|
|
132
|
+
/line:/,
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
'an oversized section',
|
|
136
|
+
() => ({ section: `${section.text}\n${filler}`, tools }),
|
|
137
|
+
/budget:/,
|
|
138
|
+
],
|
|
139
|
+
];
|
|
140
|
+
for (const [label, mutate, expected] of mutations) {
|
|
141
|
+
const mutated = mutate();
|
|
142
|
+
const found = auditPrompt(mutated);
|
|
143
|
+
assert.ok(found.length > 0, `the audit did not notice ${label}`);
|
|
144
|
+
assert.ok(found.some((problem) => expected.test(problem)), `the audit reported ${JSON.stringify(found)} for ${label}, expected ${expected}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const descriptionChars = tools.reduce((sum, tool) => sum + tool.description.length, 0);
|
|
148
|
+
console.log(`prompt section: ${section.text.length} chars (budget ${SECTION_BUDGET}) · ${tools.length} tools · ${descriptionChars} chars of tool descriptions`);
|
|
149
|
+
console.log(`prompt audit: 5 properties hold; ${mutations.length} mutations caught`);
|
package/test/release.mjs
CHANGED
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
versionShapeProblem,
|
|
46
46
|
workspacePublishProblem,
|
|
47
47
|
} from '../build/release-preflight.mjs';
|
|
48
|
-
import { releaseNotes } from '../build/release-notes.mjs';
|
|
48
|
+
import { extractReleaseBullets, releaseNotes, renderNotes } from '../build/release-notes.mjs';
|
|
49
49
|
|
|
50
50
|
const ROOT = resolve(import.meta.dirname, '..');
|
|
51
51
|
const manifestOf = (directory) => JSON.parse(readFileSync(join(ROOT, directory, 'package.json'), 'utf8'));
|
|
@@ -174,19 +174,26 @@ const notes = [];
|
|
|
174
174
|
notes.push(`CHANGELOG has a ${real.body.length}-character section for ${version}`);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
// ── (5)
|
|
177
|
+
// ── (5) a Release carries new tools and fixes, and nothing else ─────────────
|
|
178
178
|
|
|
179
179
|
{
|
|
180
|
+
const section = changelogSection(readFileSync(join(ROOT, 'CHANGELOG.md'), 'utf8'), version);
|
|
181
|
+
const bullets = extractReleaseBullets(section.body);
|
|
182
|
+
assert.ok(bullets.new.length + bullets.fix.length > 0, `the CHANGELOG entry for ${version} must carry "### 新增工具" or "### 修复" bullets`);
|
|
180
183
|
const body = releaseNotes(`v${version}`, { root: ROOT });
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
assert.ok(
|
|
184
|
+
for (const line of body.split('\n')) {
|
|
185
|
+
if (line === '' || line === '## 新增工具' || line === '## 修复') continue;
|
|
186
|
+
assert.match(line, /^- /, `release notes may carry only tool/fix bullets, got: ${line}`);
|
|
187
|
+
}
|
|
188
|
+
assert.ok(!/npm install|npm entries|CHANGELOG|blob\/v/.test(body), 'no install block, no admin text, no full-entry link');
|
|
189
|
+
// The parser ignores everything outside the two headings, and refuses an empty result.
|
|
190
|
+
assert.deepEqual(extractReleaseBullets('intro\n\n### 细节\n\n- internal only\n'), { new: [], fix: [] });
|
|
191
|
+
assert.deepEqual(extractReleaseBullets('### 新增工具\n\n- tool a\n\n### 修复\n\n- fixed b\n - detail stays in the CHANGELOG\n'), { new: ['tool a'], fix: ['fixed b'] });
|
|
192
|
+
assert.throws(() => renderNotes({ new: [], fix: [] }), /no release-note bullets/);
|
|
186
193
|
// A tag with no section must refuse rather than publish empty notes.
|
|
187
194
|
assert.throws(() => releaseNotes('v9.9.9', { root: ROOT }), /no "## 9\.9\.9" section/);
|
|
188
195
|
assert.throws(() => releaseNotes('0.19.0', { root: ROOT }), /not the release form/);
|
|
189
|
-
notes.push('release notes
|
|
196
|
+
notes.push('release notes carry only new tools and fixes, and refuse an empty section');
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
// ── (6) the manifest fields a profile needs ─────────────────────────────────
|