formlab-mcp 0.6.63 → 0.6.65
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/README.md +3 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/tools/analytics.js +165 -23
package/README.md
CHANGED
|
@@ -52,7 +52,8 @@ Ask Claude (or another MCP client) things like:
|
|
|
52
52
|
| `compare_batches` | Reproducibility of 2+ runs (ideally of one formula): each run's **yield %**, actual produced mass, cost/kg; per-ingredient **drift** across the runs vs the formula's proposed wt-%; and the biggest **outlier** run. `basis`: `wt_percent` (default) or `amount` |
|
|
53
53
|
| `get_batch_pivot` | Production analytics — aggregate batches by `group_by` (formula / status / month / prepared_by / project) × `metric` (count, avg_yield_pct, total_produced_kg, avg_cost_per_batch, total_samples, total_tests), with share + total for additive metrics. Optional `batch_uids` scope + `status` filter |
|
|
54
54
|
| `get_project_pivot` | Portfolio analytics — aggregate projects by `group_by` (status / phase / priority / business_unit / site / customer / lead, or `cf:<custom field>`) × `metric` (count, total_formulas / batches / samples, total_cost, avg_formulas / batches / cost_per_batch), rolling child activity + cost up by any project attribute. Optional `project_uids` scope |
|
|
55
|
-
| `get_stability` | Grounded stability / shelf-life analysis for a formulation, sample or batch × parameter (auto-detected): time-series, drift (per-month slope + R²), an I-chart (mean ±3σ + out-of-control points), spec status, and an ICH-Q1E-flavored projected shelf life (point + 95%-CI crossing), all on **one point per test date per run condition** (replicates averaged, never separate time points), split by storage condition. A ranked-scale (ordinal) or text parameter returns its step / pass-fail series instead: per-condition points, firstFail, latest, scaleShift. Also the app's **Time points** (per condition: tested time points, skipped pulls, the next pull with its due date and whether it's overdue, on the formula's own pull schedule, in months or weeks, or the standard one; `as_of`) and **Arrhenius** (rates at the storage temperatures → the rate, Ea, Q10 and shelf life at `predict_at_c`, zero or first `order`, with 95% CIs and a verdict against the target) |
|
|
55
|
+
| `get_stability` | Grounded stability / shelf-life analysis for a formulation, sample or batch × parameter (auto-detected): time-series, drift (per-month slope + R²), an I-chart (mean ±3σ + out-of-control points), spec status, and an ICH-Q1E-flavored projected shelf life (point + 95%-CI crossing), all on **one point per test date per run condition** (replicates averaged, never separate time points), split by storage condition. A ranked-scale (ordinal) or text parameter returns its step / pass-fail series instead: per-condition points, firstFail, latest, scaleShift. Also the app's **Time points** (per condition: tested time points, skipped pulls, the next pull with its due date and whether it's overdue, on the formula's own pull schedule, in months or weeks, or the standard one; `as_of`) and **Arrhenius** (rates at the storage temperatures → the rate, Ea, Q10 and shelf life at `predict_at_c`, zero or first `order`, with 95% CIs and a verdict against the target), and per series the **moving range** (MR̄, its limit, the jumps above it) |
|
|
56
|
+
| `list_stability_pulls` | Stability pulls due across the whole workspace (the app's Needs Attention row): every formula on a study, its next pull per storage condition overdue or due within `within_days` (default 7), on its own pull schedule or the standard one, with the samples to pull; a test of any parameter counts as the pull; studies more than 60 days late listed apart as stopped |
|
|
56
57
|
| `get_design_space` | COMPOSITION design space for one project, several (`projects`) or any formula list (`formulas`, across projects — like the app's Scope → DOE Matrix): which ingredients vary and over what observed wt-% ranges (ranked), an occupied-region summary ("where you've been"), the biggest untested **interior gap** as ready-to-seed DOE ranges (a combination you could have made but skipped), and an optional standardised **2-component PCA** of all varying ingredients — loadings, variance-explained, scree, and a full-dimensional gap. Optional `axes` (choose the 2–3 axes), `by_role` (map ingredients summed by primary Function, e.g. Pigment / Solvent / Film Former — no gap, roles aren't DOE factors) and `property` (highest / lowest formula plus the ingredients whose level tracks it, Spearman ρ). Reports formulas that aren't on the map and the spread on it. Matches the in-app Design Space Viewer exactly. Answers *"where haven't I explored?"* / *"what should I formulate next?"* |
|
|
57
58
|
| `list_doe_designs` | Saved DOE designs — the *recipe* behind each batch of runs: design type, factors + ranges, constraints, run count, D-efficiency. Filters: `project`, `design_type`, `constrained_only`, `name_contains` |
|
|
58
59
|
| `get_doe_design` | One design in full: constraints in plain language, the model it was optimised for, generation settings (run budget, replicates, centre points, seed) and the complete run matrix with the formulation each run became |
|
|
@@ -165,7 +166,7 @@ Or from the unpacked package:
|
|
|
165
166
|
}
|
|
166
167
|
```
|
|
167
168
|
|
|
168
|
-
Restart Claude Desktop. You should see a hammer icon indicating tools are available, and FormLab's
|
|
169
|
+
Restart Claude Desktop. You should see a hammer icon indicating tools are available, and FormLab's 44 tools become callable in any conversation.
|
|
169
170
|
|
|
170
171
|
## Wire it up to Claude Code
|
|
171
172
|
|
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// FORMLAB_EXPORT=/path/to/export.json node index.js
|
|
8
8
|
// formlab-mcp /path/to/export.json (when installed via npm)
|
|
9
9
|
//
|
|
10
|
-
// Exposes
|
|
10
|
+
// Exposes 44 tools (see ./tools/) over stdio. The MCP host (Claude
|
|
11
11
|
// Desktop, Claude Code, etc.) handles tool discovery, invocation
|
|
12
12
|
// and response formatting. We just register handlers and stay out
|
|
13
13
|
// of the way.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.65",
|
|
4
4
|
"mcpName": "io.github.juliu1980/formlab-mcp",
|
|
5
5
|
"description": "Read-only Model Context Protocol server for FormLab. Lets Claude and other MCP clients read and analyze your FormLab data, from a local export file or your live cloud workspace.",
|
|
6
6
|
"homepage": "https://formvix.com/mcp",
|
package/server.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.juliu1980/formlab-mcp",
|
|
4
4
|
"description": "Read-only MCP server for FormLab formulation data: a local export file or your live cloud workspace.",
|
|
5
|
-
"version": "0.6.
|
|
5
|
+
"version": "0.6.65",
|
|
6
6
|
"websiteUrl": "https://formvix.com/mcp",
|
|
7
7
|
"packages": [
|
|
8
8
|
{
|
|
9
9
|
"registryType": "npm",
|
|
10
10
|
"identifier": "formlab-mcp",
|
|
11
|
-
"version": "0.6.
|
|
11
|
+
"version": "0.6.65",
|
|
12
12
|
"runtimeHint": "npx",
|
|
13
13
|
"transport": {
|
|
14
14
|
"type": "stdio"
|
package/tools/analytics.js
CHANGED
|
@@ -1288,6 +1288,17 @@ function _iChart(ys) {
|
|
|
1288
1288
|
return { mean, sigma, ucl, lcl, ooc };
|
|
1289
1289
|
}
|
|
1290
1290
|
|
|
1291
|
+
// Moving range (the app's I-MR, _stabMR): each point's jump from the one before, MR̄, and UCL = 3.267 × MR̄ (D4 for
|
|
1292
|
+
// ranges of 2); the I-chart's σ is MR̄ ÷ 1.128.
|
|
1293
|
+
const _MR_D4 = 3.267;
|
|
1294
|
+
function _mr(ys) {
|
|
1295
|
+
const mr = ys.map((v, i) => i ? Math.abs(v - ys[i - 1]) : null);
|
|
1296
|
+
const vals = mr.slice(1);
|
|
1297
|
+
const bar = vals.length ? vals.reduce((a, b) => a + b, 0) / vals.length : null;
|
|
1298
|
+
const ucl = bar != null ? _MR_D4 * bar : null;
|
|
1299
|
+
return { mr, bar, ucl, over: mr.map(v => v != null && ucl != null && v > ucl + 1e-12) };
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1291
1302
|
// Shelf life: fit vs elapsed months, extrapolate to the spec limit the trend
|
|
1292
1303
|
// heads toward. Point-estimate crossing + the conservative 95% CI-bound crossing.
|
|
1293
1304
|
// One-sided 95% Student t for df = n − 2 (ICH Q1E) — a copy of the app's _stabT95
|
|
@@ -1405,37 +1416,49 @@ function _condTempC(label) {
|
|
|
1405
1416
|
const range = s.match(/(\d+(?:\.\d+)?)\s*(?:–|-|to)\s*(\d+(?:\.\d+)?)\s*(?:°|º|deg(?:rees)?\.?)?\s*([CF])\b/i);
|
|
1406
1417
|
if (range) return toC((parseFloat(range[1]) + parseFloat(range[2])) / 2, range[3]);
|
|
1407
1418
|
const one = s.match(/(^|[^\d.\-–])(-?\d+(?:\.\d+)?)\s*(?:°|º|deg(?:rees)?\.?)?\s*([CF])\b/i);
|
|
1408
|
-
|
|
1419
|
+
if (one) return toC(parseFloat(one[2]), one[3]);
|
|
1420
|
+
// ICH shorthand, temperature / humidity: "40/75", "25/60 % RH" (QA sweep, Jun 1 Nov).
|
|
1421
|
+
const ich = s.match(/(^|[^\d.\/])(-?\d{1,2})\s*\/\s*(\d{2,3})\s*(?:%\s*(?:RH)?)?(?![\d.\/])/i);
|
|
1422
|
+
return ich && +ich[3] >= 10 && +ich[3] <= 100 && +ich[2] >= -40 && +ich[2] <= 70 ? +ich[2] : null;
|
|
1409
1423
|
}
|
|
1410
1424
|
// The study at a glance, one row per storage condition (the app's Time points plot): what was tested at each time
|
|
1411
1425
|
// point from the entity's T₀ (its first test under any condition), the time points skipped, and the next pull with
|
|
1412
1426
|
// its due date. points: [{ date, cond, pf }].
|
|
1427
|
+
// One storage condition's time points from T₀ and its next pull, on the formula's schedule or the standard one.
|
|
1428
|
+
// ps: points with .date (and .pf on a plot).
|
|
1429
|
+
function _tpCond(ps, t0, tC, targetMonths, plan, now) {
|
|
1430
|
+
const ladder = _tpLadder(tC, targetMonths, plan);
|
|
1431
|
+
// A schedule in weeks keeps its time points in weeks up to its last week pull.
|
|
1432
|
+
const weekDays = Math.max(21, ...ladder.filter(e => _pullWeeks(e) != null).map(e => _pullDays(e) + 4));
|
|
1433
|
+
const keyOf = e => _tpBucket(_pullDays(e), weekDays).key;
|
|
1434
|
+
const cells = new Map();
|
|
1435
|
+
ps.forEach(p => {
|
|
1436
|
+
const b = _tpBucket((p.date.getTime() - t0) / _MS_PER_DAY, weekDays);
|
|
1437
|
+
if (!cells.has(b.key)) cells.set(b.key, { ...b, points: [] });
|
|
1438
|
+
cells.get(b.key).points.push(p);
|
|
1439
|
+
});
|
|
1440
|
+
cells.forEach(c => { c.pf = c.points.some(p => p.pf === 'fail') ? 'fail' : c.points.some(p => p.pf === 'pass') ? 'pass' : null; });
|
|
1441
|
+
// A test dated after today (a typo, or entered ahead) shows, but doesn't count as pulled yet (QA sweep, Jun 1 Nov).
|
|
1442
|
+
const done = [...cells.values()].filter(c => c.points.some(p => p.date.getTime() <= now + _MS_PER_DAY)).map(c => c.key);
|
|
1443
|
+
const lastKey = done.length ? Math.max(...done) : -1;
|
|
1444
|
+
const nextE = ladder.find(e => keyOf(e) > lastKey);
|
|
1445
|
+
const next = nextE == null ? null : (() => {
|
|
1446
|
+
const due = t0 + _pullDays(nextE) * _MS_PER_DAY;
|
|
1447
|
+
return { label: _pullLabel(nextE), due: new Date(due), days: Math.floor((due - now) / _MS_PER_DAY) };
|
|
1448
|
+
})();
|
|
1449
|
+
return { cells, lastKey, weekDays, ladderKeys: ladder.map(keyOf), own: !!_tpOwnPulls(plan, tC), next };
|
|
1450
|
+
}
|
|
1451
|
+
const _dayOf = d => new Date(d).toISOString().slice(0, 10);
|
|
1452
|
+
const _nextOut = n => n ? { timePoint: n.label, due: _dayOf(n.due), daysUntil: n.days, overdue: n.days < 0 } : null;
|
|
1413
1453
|
function _mcpTimePoints(points, formula, targetMonths, now) {
|
|
1414
1454
|
if (!points.length) return null;
|
|
1415
|
-
const day = d => new Date(d).toISOString().slice(0, 10);
|
|
1416
1455
|
const t0 = Math.min(...points.map(p => p.date.getTime()));
|
|
1417
1456
|
const plan = _tpPlanOf(formula);
|
|
1418
1457
|
const byCond = new Map();
|
|
1419
1458
|
points.forEach(p => { const c = (p.cond || '').trim(); if (!byCond.has(c)) byCond.set(c, []); byCond.get(c).push(p); });
|
|
1420
1459
|
const rows = [...byCond.entries()].map(([cond, ps]) => ({ cond, ps, tC: cond ? _condTempC(cond) : null }))
|
|
1421
1460
|
.sort((a, b) => (a.tC == null ? -Infinity : a.tC) - (b.tC == null ? -Infinity : b.tC) || a.cond.localeCompare(b.cond))
|
|
1422
|
-
.map(({ cond, ps, tC }) => {
|
|
1423
|
-
const ladder = _tpLadder(tC, targetMonths, plan);
|
|
1424
|
-
// A schedule in weeks keeps its time points in weeks up to its last week pull.
|
|
1425
|
-
const weekDays = Math.max(21, ...ladder.filter(e => _pullWeeks(e) != null).map(e => _pullDays(e) + 4));
|
|
1426
|
-
const keyOf = e => _tpBucket(_pullDays(e), weekDays).key;
|
|
1427
|
-
const cells = new Map();
|
|
1428
|
-
ps.forEach(p => {
|
|
1429
|
-
const b = _tpBucket((p.date.getTime() - t0) / _MS_PER_DAY, weekDays);
|
|
1430
|
-
if (!cells.has(b.key)) cells.set(b.key, { ...b, dates: new Set(), pfs: [] });
|
|
1431
|
-
const c = cells.get(b.key); c.dates.add(day(p.date)); c.pfs.push(p.pf);
|
|
1432
|
-
});
|
|
1433
|
-
const lastKey = Math.max(...cells.keys());
|
|
1434
|
-
const nextE = ladder.find(e => keyOf(e) > lastKey);
|
|
1435
|
-
const due = nextE == null ? null : t0 + _pullDays(nextE) * _MS_PER_DAY;
|
|
1436
|
-
return { cond, tC, cells, lastKey, weekDays, ladder, ladderKeys: ladder.map(keyOf), own: !!_tpOwnPulls(plan, tC),
|
|
1437
|
-
next: nextE == null ? null : { timePoint: _pullLabel(nextE), due: day(due), daysUntil: Math.floor((due - now) / _MS_PER_DAY) } };
|
|
1438
|
-
});
|
|
1461
|
+
.map(({ cond, ps, tC }) => ({ cond, tC, ladder: _tpLadder(tC, targetMonths, plan), ..._tpCond(ps, t0, tC, targetMonths, plan, now) }));
|
|
1439
1462
|
// Skipped: a time point before this row's last test that its schedule, or (on the standard one) another row at its
|
|
1440
1463
|
// temperature on the standard one, has.
|
|
1441
1464
|
rows.forEach(r => {
|
|
@@ -1444,19 +1467,99 @@ function _mcpTimePoints(points, formula, targetMonths, now) {
|
|
|
1444
1467
|
r.skipped = [...keys].filter(k => k > 0 && k < r.lastKey && !r.cells.has(k)).sort((a, b) => a - b);
|
|
1445
1468
|
});
|
|
1446
1469
|
return {
|
|
1447
|
-
t0:
|
|
1470
|
+
t0: _dayOf(t0),
|
|
1448
1471
|
rows: rows.map(r => ({
|
|
1449
1472
|
condition: r.cond || null,
|
|
1450
1473
|
temperatureC: r.tC != null ? _round(r.tC, 1) : null,
|
|
1451
1474
|
schedule: r.own ? 'formula' : 'standard',
|
|
1452
1475
|
pulls: r.ladder.map(_pullLabel),
|
|
1453
|
-
tested: [...r.cells.values()].sort((a, b) => a.key - b.key).map(c => ({ timePoint: c.label, testDates: c.
|
|
1454
|
-
pf: c.pfs.includes('fail') ? 'fail' : c.pfs.includes('pass') ? 'pass' : null })),
|
|
1476
|
+
tested: [...r.cells.values()].sort((a, b) => a.key - b.key).map(c => ({ timePoint: c.label, testDates: new Set(c.points.map(p => _dayOf(p.date))).size, pf: c.pf })),
|
|
1455
1477
|
skipped: r.skipped.map(k => _tpBucket(k, r.weekDays).label),
|
|
1456
|
-
next: r.next
|
|
1478
|
+
next: _nextOut(r.next),
|
|
1457
1479
|
})),
|
|
1458
1480
|
};
|
|
1459
1481
|
}
|
|
1482
|
+
// Exploration runs (DOE / screening), as the app's flExplorationFormulaIds: the formula or its project marked
|
|
1483
|
+
// exploratory, or a DOE design's run that isn't Approved. Their alerts are expected, so sweeps leave them out.
|
|
1484
|
+
function _mcpExplorationIds(db) {
|
|
1485
|
+
const out = new Set();
|
|
1486
|
+
const proj = new Set((db.projects || []).filter(p => p && p.exploratory).map(p => p.id));
|
|
1487
|
+
const fromDoe = new Set();
|
|
1488
|
+
(db.doeDesigns || []).forEach(d => (d && d.formulationIds || []).forEach(id => fromDoe.add(id)));
|
|
1489
|
+
(db.formulations || []).forEach(f => {
|
|
1490
|
+
if (!f) return;
|
|
1491
|
+
if (f.exploratory || proj.has(f.projectId) || (fromDoe.has(f.id) && f.status !== 'Approved')) out.add(f.id);
|
|
1492
|
+
});
|
|
1493
|
+
return out;
|
|
1494
|
+
}
|
|
1495
|
+
// Pulls due across the workspace (the app's Needs Attention row, _stabPullsDueScan): every formula on a stability study
|
|
1496
|
+
// (tests under a storage condition with a temperature in its name on 2+ dates), its next pull per condition. A test of
|
|
1497
|
+
// any parameter counts as the pull; T₀ is the formula's first such test. Exploration runs, archived and trashed formulas
|
|
1498
|
+
// are left out; a pull more than _PULL_STALE_D days late is a study that stopped (returned apart, as `stopped`).
|
|
1499
|
+
const _PULL_STALE_D = 60;
|
|
1500
|
+
// A condition key naming how a reading was measured, not where the sample was stored.
|
|
1501
|
+
const _RUN_TEMP_KEY = /^(?:test|measur\w*|run|sample|bath|plate|probe|cell|oven)?\s*temp(?:erature)?$|^measured at$/i;
|
|
1502
|
+
// The storage part of a reading's conditions: the first with a temperature whose key isn't a measurement setting;
|
|
1503
|
+
// "RPM 50" beside it is left out, so it doesn't split the study.
|
|
1504
|
+
function _mcpStorageCond(m) {
|
|
1505
|
+
const c = m && m.conditions;
|
|
1506
|
+
if (!c || typeof c !== 'object') return '';
|
|
1507
|
+
for (const [k, v] of Object.entries(c)) {
|
|
1508
|
+
if (v == null || v === '' || _RUN_TEMP_KEY.test(String(k).trim())) continue;
|
|
1509
|
+
const one = `${k} ${v}`;
|
|
1510
|
+
if (_condTempC(one) != null) return one;
|
|
1511
|
+
}
|
|
1512
|
+
return '';
|
|
1513
|
+
}
|
|
1514
|
+
function _mcpPullsDue(db, now) {
|
|
1515
|
+
const due = [], stopped = [];
|
|
1516
|
+
const explore = _mcpExplorationIds(db);
|
|
1517
|
+
const defT = parseFloat(db.defaultShelfLifeMonths);
|
|
1518
|
+
const samplesOf = new Map();
|
|
1519
|
+
const live = new Set(); // samples still on the shelf: a Discarded one is never named to pull
|
|
1520
|
+
(db.samples || []).forEach(x => { if (x && !x._trashed && x.formulationId) { if (!samplesOf.has(x.formulationId)) samplesOf.set(x.formulationId, new Set()); samplesOf.get(x.formulationId).add(x.id); if (x.status !== 'Discarded') live.add(x.id); } });
|
|
1521
|
+
const testsOf = new Map();
|
|
1522
|
+
(db.testResults || []).forEach(t => { if (t && !t._trashed && t.sampleId) { if (!testsOf.has(t.sampleId)) testsOf.set(t.sampleId, []); testsOf.get(t.sampleId).push(t); } });
|
|
1523
|
+
(db.formulations || []).forEach(f => {
|
|
1524
|
+
if (!f || f._trashed || f.deletedAt || f.status === 'Archived' || explore.has(f.id)) return;
|
|
1525
|
+
const sids = samplesOf.get(f.id);
|
|
1526
|
+
if (!sids) return;
|
|
1527
|
+
const byCond = new Map(), params = new Map(), condSamples = new Map();
|
|
1528
|
+
sids.forEach(sid => (testsOf.get(sid) || []).forEach(t => {
|
|
1529
|
+
const day = String(t.testDate || '').slice(0, 10), ms = Date.parse(day);
|
|
1530
|
+
if (!Number.isFinite(ms)) return;
|
|
1531
|
+
(t.measurements || []).forEach(m => {
|
|
1532
|
+
const cond = _mcpStorageCond(m).trim();
|
|
1533
|
+
if (!cond) return;
|
|
1534
|
+
if (!byCond.has(cond)) { byCond.set(cond, new Map()); condSamples.set(cond, new Set()); }
|
|
1535
|
+
byCond.get(cond).set(day, ms);
|
|
1536
|
+
condSamples.get(cond).add(sid);
|
|
1537
|
+
const p = String(m.parameter || '').trim(); if (p) params.set(p, (params.get(p) || 0) + 1);
|
|
1538
|
+
});
|
|
1539
|
+
}));
|
|
1540
|
+
const conds = [...byCond.entries()].filter(([, d]) => d.size >= 2);
|
|
1541
|
+
if (!conds.length) return;
|
|
1542
|
+
const t0 = Math.min(...conds.flatMap(([, d]) => [...d.values()]));
|
|
1543
|
+
const ownT = parseFloat(f.shelfLifeMonths);
|
|
1544
|
+
const target = ownT > 0 ? ownT : defT > 0 ? defT : null;
|
|
1545
|
+
const plan = _tpPlanOf(f);
|
|
1546
|
+
const param = [...params.entries()].sort((a, b) => b[1] - a[1])[0][0];
|
|
1547
|
+
conds.forEach(([cond, d]) => {
|
|
1548
|
+
const tC = _condTempC(cond);
|
|
1549
|
+
const r = _tpCond([...d.values()].map(ms => ({ date: new Date(ms) })), t0, tC, target, plan, now);
|
|
1550
|
+
if (!r.next) return;
|
|
1551
|
+
const sampleIds = [...condSamples.get(cond)].filter(id => live.has(id));
|
|
1552
|
+
if (!sampleIds.length) return; // every sample under it discarded: the study is over there
|
|
1553
|
+
const last = r.cells.get(r.lastKey);
|
|
1554
|
+
const row = { formula: { id: f.id, uid: f.uid || null, name: f.name || f.uid || 'Formula' }, condition: cond, temperatureC: _round(tC, 1),
|
|
1555
|
+
schedule: r.own ? 'formula' : 'standard', t0: _dayOf(t0), lastTimePoint: last ? last.label : null, ..._nextOut(r.next), parameter: param,
|
|
1556
|
+
samples: sampleIds.map(id => { const x = (db.samples || []).find(y => y && y.id === id); return x ? (x.uid || x.id) : id; }) };
|
|
1557
|
+
(r.next.days < -_PULL_STALE_D ? stopped : due).push(row);
|
|
1558
|
+
});
|
|
1559
|
+
});
|
|
1560
|
+
const byDays = (a, b) => a.daysUntil - b.daysUntil;
|
|
1561
|
+
return { due: due.sort(byDays), stopped: stopped.sort(byDays) };
|
|
1562
|
+
}
|
|
1460
1563
|
// Two-sided 95% Student t (t 0.975), for a confidence interval: the Arrhenius CI. A copy of the app's _stabT975.
|
|
1461
1564
|
const _T975_TABLE = [null, 12.706, 4.303, 3.182, 2.776, 2.571, 2.447, 2.365, 2.306, 2.262, 2.228, 2.201, 2.179, 2.160, 2.145, 2.131, 2.120, 2.110, 2.101, 2.093, 2.086, 2.080, 2.074, 2.069, 2.064, 2.060, 2.056, 2.052, 2.048, 2.045, 2.042];
|
|
1462
1565
|
function _t975(df) {
|
|
@@ -1702,6 +1805,7 @@ const get_stability = {
|
|
|
1702
1805
|
}
|
|
1703
1806
|
const ic = _iChart(ys);
|
|
1704
1807
|
if (ic) out.controlChart = { mean: _round(ic.mean), ucl: _round(ic.ucl), lcl: _round(ic.lcl), sigma: _round(ic.sigma), outOfControlPoints: ic.ooc };
|
|
1808
|
+
if (ic) { const m = _mr(ys); out.movingRange = { mean: _round(m.bar), ucl: _round(m.ucl), jumpsAbove: m.over.map((o, i) => o ? { date: pts[i].date.toISOString().slice(0, 10), from: pts[i - 1].date.toISOString().slice(0, 10), jump: _round(m.mr[i], 6) } : null).filter(Boolean) }; }
|
|
1705
1809
|
if (spec.min != null || spec.max != null) out.spec = { ...spec, latestInSpec: (spec.min == null || ys[n - 1] >= spec.min) && (spec.max == null || ys[n - 1] <= spec.max) };
|
|
1706
1810
|
else if (specVaries) {
|
|
1707
1811
|
const ls = [...pts].reverse().find(p => p.spec);
|
|
@@ -1741,6 +1845,7 @@ const get_stability = {
|
|
|
1741
1845
|
targetShelfLife: target ? { months: target.months, source: target.source } : null,
|
|
1742
1846
|
timePoints: _mcpTimePoints(points, formula, target && target.months, asOf),
|
|
1743
1847
|
arrhenius: specVaries ? null : _mcpArrhenius(points, spec, Number.isFinite(+args.predict_at_c) && args.predict_at_c !== null && args.predict_at_c !== '' ? +args.predict_at_c : 25, args.order === 'first' ? 'first' : 'zero', target && target.months),
|
|
1848
|
+
movingRangeNote: 'movingRange (per series, beside controlChart): mean = MR̄, the average jump between consecutive points; ucl = 3.267 × MR̄; jumpsAbove = jumps bigger than chance (date, the point before, the jump). controlChart.sigma = MR̄ ÷ 1.128, so a jump above here is what widens the control limits.',
|
|
1744
1849
|
timePointsNote: 'timePoints: one row per storage condition, time points counted from t0 (the first test under any condition): tested (pf "fail" when any reading that time point failed), skipped (a time point before the last test that the schedule or another condition at that temperature has, but this one does not), next (the next pull not yet tested, its due date, daysUntil; overdue = past as_of; null = schedule complete). schedule "formula" = the formula\'s own pulls (months, or weeks such as "2 wk"), else "standard": 1, 2, 3, 6 months at 35 °C and up; 1, 2, 3, 6, 9, 12, 18, 24, 36 months up to the target shelf life; pulls lists the row\'s schedule.',
|
|
1745
1850
|
arrheniusNote: 'arrhenius (null when no condition names a temperature): rates per storage temperature (3+ test dates each), ln(rate) against 1/T fitted and read at predictAtC: activation energy, Q10 (how many times faster 10 °C warmer, from predictAtC to predictAtC + 10; it varies with temperature), the rate there with its 95% CI, and the shelf life there from the T0 value to the spec limit (ci95Months: a faster rate gives the low end). "> 120" = beyond 10 years. verdict as shelfLife.verdict, against targetShelfLife. realTimeShelfLifeMonths = the trend projection at predictAtC itself when that temperature was tested. why = no prediction, and the reason.',
|
|
1746
1851
|
note: 'shelfLife.fromT0Months / ci95FromT0Months are the projected shelf life counted from the first test (T0): point estimate and the conservative (ICH Q1E) 95%-bound crossing. remainingMonths / ci95Months are the same, counted from the last test. verdict compares against targetShelfLife: "short" = the trend crosses spec before the target, "marginal" = the trend clears it but the 95% bound does not, "meets" = both clear it; null = no target set (then concern is by time left: medium <3 mo or overdue, else info). A projection never reaches \"high\": high is reserved for a MEASURED out-of-spec value (spec.latestInSpec=false). short/overdue → medium, marginal/meets → info. overdue=true means projectedCrossDate is already past today (time left runs from the last test), so the sample is probably out of spec now — recommend a re-test. reportable=false means the app shows no projection (R² < 0.3, crossing already past, or beyond 5 years). Numbers are computed here — narrate them, do not recompute.',
|
|
@@ -1748,6 +1853,42 @@ const get_stability = {
|
|
|
1748
1853
|
},
|
|
1749
1854
|
};
|
|
1750
1855
|
|
|
1856
|
+
const list_stability_pulls = {
|
|
1857
|
+
definition: {
|
|
1858
|
+
name: 'list_stability_pulls',
|
|
1859
|
+
description: 'Stability pulls due across the whole workspace: the app\'s Needs Attention "stability pulls due" row, without naming a formula. Every formula on a stability study (tests under a storage condition with a temperature in its name, on 2+ dates) gives its next pull per condition, on the formula\'s own pull schedule or the standard one (1, 2, 3, 6 months at 35 °C and up; 1, 2, 3, 6, 9, 12, 18, 24, 36 months up to the target shelf life). A test of ANY parameter in a time point under that condition counts as the pull; T0 is the formula\'s first such test. Returns the pulls overdue or due within within_days (default 7), soonest first, with formula, condition, time point, due date, daysUntil (negative = overdue), schedule, the last time point tested, the parameter the study measures most, and the samples to pull (UIDs; discarded ones left out, and a condition whose samples are all discarded has nothing due). Only the storage part of a reading\'s conditions counts (a measurement temperature such as Temperature 25 °C does not make a study); ICH shorthand such as 40/75 reads as 40 °C; a test dated after as_of does not count as pulled yet. A pull more than 60 days late is a study that stopped: listed apart under stopped. Exploration runs (DOE / screening), archived and trashed formulas are left out, as in the app. For one formula\'s full time-point grid use get_stability (timePoints).',
|
|
1860
|
+
inputSchema: {
|
|
1861
|
+
type: 'object',
|
|
1862
|
+
properties: {
|
|
1863
|
+
within_days: { type: 'number', description: 'Pulls due within this many days from as_of, plus every overdue one (default 7; 0 = overdue and due today only).' },
|
|
1864
|
+
formulation: { type: 'string', description: 'Only this formula (id or UID).' },
|
|
1865
|
+
as_of: { type: 'string', description: 'Date (YYYY-MM-DD) to count from. Default today.' },
|
|
1866
|
+
},
|
|
1867
|
+
},
|
|
1868
|
+
},
|
|
1869
|
+
handler: async (args) => {
|
|
1870
|
+
const db = getStore().db;
|
|
1871
|
+
const asOf = args.as_of && /^\d{4}-\d{2}-\d{2}$/.test(args.as_of) ? Date.parse(args.as_of) : Date.now();
|
|
1872
|
+
const within = Number.isFinite(+args.within_days) && args.within_days !== null && args.within_days !== '' ? Math.max(0, +args.within_days) : 7;
|
|
1873
|
+
let f = null;
|
|
1874
|
+
if (args.formulation) {
|
|
1875
|
+
f = (db.formulations || []).find(x => x && (x.id === args.formulation || x.uid === args.formulation));
|
|
1876
|
+
if (!f) return { error: `No formulation found for "${args.formulation}".` };
|
|
1877
|
+
}
|
|
1878
|
+
const r = _mcpPullsDue(db, asOf);
|
|
1879
|
+
const mine = x => !f || x.formula.id === f.id;
|
|
1880
|
+
const pulls = r.due.filter(x => mine(x) && x.daysUntil <= within);
|
|
1881
|
+
return {
|
|
1882
|
+
asOf: new Date(asOf).toISOString().slice(0, 10), withinDays: within,
|
|
1883
|
+
...(f ? { formulation: { uid: f.uid, name: f.name } } : {}),
|
|
1884
|
+
count: pulls.length, overdue: pulls.filter(x => x.overdue).length, pulls,
|
|
1885
|
+
later: r.due.filter(x => mine(x) && x.daysUntil > within).length,
|
|
1886
|
+
stopped: r.stopped.filter(mine),
|
|
1887
|
+
note: 'daysUntil < 0 = overdue by that many days. schedule "formula" = the formula\'s own pulls, else "standard". later = studies whose next pull is further out than within_days. stopped = next pull more than 60 days late, read as a study that ended; the app leaves these out of Needs Attention. Narrate these figures; do not recompute the schedule.',
|
|
1888
|
+
};
|
|
1889
|
+
},
|
|
1890
|
+
};
|
|
1891
|
+
|
|
1751
1892
|
export { _mcpRepNumber, _mcpMeasType, _evalPassFail, _resolveSpec, _shelfLife, _shelfLifeAssess, _mcpCondTags, _mcpArmNames, _mcpCondDefaultScore, _mcpCondSig, _mcpCondLabel, _mcpParamGroupsOf };
|
|
1752
1893
|
// ============================================================
|
|
1753
1894
|
// compare_test_results — the app's Compare Results table (js/views/testing-
|
|
@@ -2006,4 +2147,5 @@ export const tools = {
|
|
|
2006
2147
|
list_doe_designs,
|
|
2007
2148
|
get_doe_design,
|
|
2008
2149
|
get_stability,
|
|
2150
|
+
list_stability_pulls,
|
|
2009
2151
|
};
|