@barivia/barmesh-mcp 0.6.1 → 0.6.3

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.
@@ -3,7 +3,7 @@
3
3
  * Surfaces phase, elapsed, ETA, and epoch N/M during the SOM training of a
4
4
  * cfd_mesh_convergence job, plus CFD finalize (figure render) sub-status.
5
5
  */
6
- import { apiCall } from "./shared.js";
6
+ import { formatRunConfigTable, finalizeSubStatusLine } from "./run_config.js";
7
7
  function formatElapsedPart(data, status) {
8
8
  const wall = data.wall_elapsed_sec != null && !Number.isNaN(Number(data.wall_elapsed_sec))
9
9
  ? Number(data.wall_elapsed_sec)
@@ -33,32 +33,16 @@ function formatElapsedPart(data, status) {
33
33
  }
34
34
  return null;
35
35
  }
36
- async function finalizeStatusLine(finalizeId) {
37
- try {
38
- const fin = (await apiCall("GET", `/v1/jobs/${finalizeId}`));
39
- const st = String(fin.status ?? "unknown");
40
- const prog = fin.progress != null ? `${(Number(fin.progress) * 100).toFixed(0)}%` : null;
41
- const phase = fin.progress_phase != null ? String(fin.progress_phase) : null;
42
- const elapsed = formatElapsedPart(fin, st);
43
- const bits = [`cfd_finalize ${finalizeId}: ${st}`];
44
- if (prog)
45
- bits.push(prog);
46
- if (phase)
47
- bits.push(`phase ${phase}`);
48
- if (elapsed)
49
- bits.push(elapsed);
50
- return bits.join(", ");
51
- }
52
- catch {
53
- return `cfd_finalize ${finalizeId} still running (poll barmesh_jobs(action=status, job_id="${finalizeId}"))`;
54
- }
55
- }
56
36
  export async function formatJobStatusText(job_id, data) {
57
37
  const status = String(data.status ?? "unknown");
58
38
  const progress = (data.progress ?? 0) * 100;
59
39
  const label = data.label != null && data.label !== "" ? String(data.label) : null;
60
40
  const jobDesc = label ? `Job ${label} (id: ${job_id})` : `Job ${job_id}`;
61
- const parts = [`${jobDesc}: ${status} (${progress.toFixed(1)}%)`];
41
+ const parts = [];
42
+ const runConfig = formatRunConfigTable(data);
43
+ if (runConfig)
44
+ parts.push(runConfig);
45
+ parts.push(`${jobDesc}: ${status} (${progress.toFixed(1)}%)`);
62
46
  const attempt = data.attempt != null ? Number(data.attempt) : null;
63
47
  if (attempt != null && attempt > 1) {
64
48
  parts.push(`attempt ${attempt} (job was requeued after worker timeout — not stuck from scratch)`);
@@ -86,14 +70,19 @@ export async function formatJobStatusText(job_id, data) {
86
70
  const qe = data.quantization_error != null ? Number(data.quantization_error) : null;
87
71
  if (qe != null && !Number.isNaN(qe))
88
72
  parts.push(`QE ${qe.toFixed(4)}`);
73
+ const mapTe = data.map_topographic_error != null ? Number(data.map_topographic_error) : null;
74
+ const liveTe = data.topographic_error != null ? Number(data.topographic_error) : null;
75
+ const te = mapTe != null && !Number.isNaN(mapTe) ? mapTe : liveTe;
76
+ if (te != null && !Number.isNaN(te))
77
+ parts.push(`TE ${te.toFixed(4)}`);
89
78
  }
90
79
  if (status === "running" && progress < 5 && !phase) {
91
80
  parts.push("Advisory: still in early preprocessing — epoch counter starts after ingest completes.");
92
81
  }
93
82
  if (status === "completed") {
94
- const finalizeId = data.finalize_job_id != null && String(data.finalize_job_id) !== "" ? String(data.finalize_job_id) : null;
95
- if (finalizeId) {
96
- parts.push(await finalizeStatusLine(finalizeId));
83
+ const finalizeLine = finalizeSubStatusLine(data);
84
+ if (finalizeLine) {
85
+ parts.push(finalizeLine);
97
86
  parts.push(`Compute done; figures may still be uploading. Poll barmesh_jobs(status) until finalize completes before barmesh_results(get).`);
98
87
  }
99
88
  else {
@@ -0,0 +1,136 @@
1
+ /** Run configuration summary for training monitor (mesh_convergence + training jobs). */
2
+ function formatGrid(grid) {
3
+ if (!Array.isArray(grid) || grid.length < 2)
4
+ return null;
5
+ return `${grid[0]}×${grid[1]}`;
6
+ }
7
+ function formatEpochs(epochs) {
8
+ if (!Array.isArray(epochs) || epochs.length === 0)
9
+ return null;
10
+ if (epochs.length >= 2)
11
+ return `${epochs[0]}+${epochs[1]}`;
12
+ return String(epochs[0]);
13
+ }
14
+ function formatMeshOrder(mo) {
15
+ if (!Array.isArray(mo) || mo.length === 0)
16
+ return null;
17
+ return mo.map(String).join("→");
18
+ }
19
+ function formatFeatures(feats) {
20
+ if (!Array.isArray(feats) || feats.length === 0)
21
+ return null;
22
+ const names = feats.map(String);
23
+ if (names.length <= 6)
24
+ return names.join(", ");
25
+ return `${names.length} cols: ${names.slice(0, 5).join(", ")}, …`;
26
+ }
27
+ /** Merge nested run_config from GET /v1/jobs/:id with top-level monitor fields. */
28
+ export function runConfigSource(data) {
29
+ const rc = data.run_config;
30
+ if (rc && typeof rc === "object") {
31
+ return { ...data, ...rc };
32
+ }
33
+ return data;
34
+ }
35
+ export function buildRunConfigRows(data) {
36
+ const src = runConfigSource(data);
37
+ const rows = [];
38
+ if (src.label)
39
+ rows.push(["Label", String(src.label)]);
40
+ const dsName = src.dataset_name ?? data.dataset_name;
41
+ const dsId = src.dataset_id ?? data.dataset_id;
42
+ if (dsName) {
43
+ const idHint = dsId ? ` (${String(dsId).slice(0, 8)}…)` : "";
44
+ rows.push(["Dataset", `${String(dsName)}${idHint}`]);
45
+ }
46
+ else if (dsId) {
47
+ rows.push(["Dataset id", String(dsId)]);
48
+ }
49
+ const featStr = formatFeatures(src.feature_columns ?? src.columns);
50
+ if (featStr)
51
+ rows.push(["Features", featStr]);
52
+ if (src.batch_size != null)
53
+ rows.push(["Batch", String(src.batch_size)]);
54
+ if (src.preset)
55
+ rows.push(["Preset", String(src.preset)]);
56
+ const gridStr = formatGrid(src.grid);
57
+ if (gridStr)
58
+ rows.push(["Grid", gridStr]);
59
+ const epStr = formatEpochs(src.epochs);
60
+ if (epStr)
61
+ rows.push(["Epochs", epStr]);
62
+ if (src.reference_mesh)
63
+ rows.push(["Reference", String(src.reference_mesh)]);
64
+ const moStr = formatMeshOrder(src.mesh_order);
65
+ if (moStr)
66
+ rows.push(["Mesh order", moStr]);
67
+ if (src.stratify_scale != null)
68
+ rows.push(["Stratify", String(src.stratify_scale)]);
69
+ if (src.emd_method)
70
+ rows.push(["EMD", String(src.emd_method)]);
71
+ if (src.backend)
72
+ rows.push(["Backend", String(src.backend)]);
73
+ if (data.dataset_rows != null) {
74
+ rows.push(["Rows", Number(data.dataset_rows).toLocaleString()]);
75
+ }
76
+ if (data.attempt != null && Number(data.attempt) > 1) {
77
+ rows.push(["Attempt", String(data.attempt)]);
78
+ }
79
+ return rows;
80
+ }
81
+ export function formatRunConfigTable(data) {
82
+ const rows = buildRunConfigRows(data);
83
+ if (rows.length === 0)
84
+ return "";
85
+ return `Run config — ${rows.map(([l, v]) => `${l}: ${v}`).join(" | ")}`;
86
+ }
87
+ export function finalizeSubStatusLine(data) {
88
+ const finalizeId = data.finalize_job_id != null && String(data.finalize_job_id) !== ""
89
+ ? String(data.finalize_job_id)
90
+ : null;
91
+ if (!finalizeId)
92
+ return null;
93
+ const st = String(data.finalize_status ?? "unknown");
94
+ const prog = data.finalize_progress != null ? `${(Number(data.finalize_progress) * 100).toFixed(0)}%` : null;
95
+ const phase = data.finalize_phase != null && String(data.finalize_phase) !== ""
96
+ ? String(data.finalize_phase)
97
+ : null;
98
+ const bits = [`cfd_finalize ${finalizeId}: ${st}`];
99
+ if (prog)
100
+ bits.push(prog);
101
+ if (phase)
102
+ bits.push(`phase ${phase}`);
103
+ return bits.join(", ");
104
+ }
105
+ export function isTerminalJobStatus(status) {
106
+ return status === "completed" || status === "failed" || status === "cancelled";
107
+ }
108
+ /** Keep polling while finalize is still running after parent compute completed. */
109
+ export function shouldKeepPollingJob(data) {
110
+ const status = String(data.status ?? "");
111
+ if (!isTerminalJobStatus(status))
112
+ return true;
113
+ if (status !== "completed")
114
+ return false;
115
+ if (data.finalize_failed === true)
116
+ return false;
117
+ const finalizeId = data.finalize_job_id != null && String(data.finalize_job_id) !== ""
118
+ ? String(data.finalize_job_id)
119
+ : null;
120
+ const finalizeStatus = data.finalize_status != null && String(data.finalize_status) !== ""
121
+ ? String(data.finalize_status)
122
+ : null;
123
+ return finalizeId != null && finalizeStatus !== "completed";
124
+ }
125
+ /** True when compute + finalize (if any) are done — safe to show results_explorer hint. */
126
+ export function isFullyComplete(data) {
127
+ const status = String(data.status ?? "");
128
+ if (status !== "completed")
129
+ return isTerminalJobStatus(status);
130
+ const finalizeId = data.finalize_job_id != null && String(data.finalize_job_id) !== ""
131
+ ? String(data.finalize_job_id)
132
+ : null;
133
+ if (!finalizeId)
134
+ return true;
135
+ return String(data.finalize_status ?? "") === "completed";
136
+ }
package/dist/shared.js CHANGED
@@ -22,7 +22,7 @@ export const FETCH_TIMEOUT_MS = parseInt(process.env.BARIVIA_FETCH_TIMEOUT_MS ??
22
22
  export const MAX_RETRIES = 2;
23
23
  export const RETRYABLE_STATUS = new Set([502, 503, 504]);
24
24
  /** Single source of truth for the proxy version. Keep in sync with package.json on bump. */
25
- export const CLIENT_VERSION = "0.6.1";
25
+ export const CLIENT_VERSION = "0.6.2";
26
26
  export const PUBLIC_SITE_ORIGIN = "https://barivia.se";
27
27
  /** Large per-cell CSV uploads may exceed the default fetch timeout. */
28
28
  export const UPLOAD_DATASET_TIMEOUT_MS = 180_000;
package/dist/tools/cfd.js CHANGED
@@ -25,7 +25,8 @@ COMMON MISTAKES: omitting feature_columns (required); choosing a reference_mesh
25
25
  backend: z.enum(["auto", "cpu", "gpu", "gpu_graphs"]).optional().describe("Compute backend (default auto / preset)"),
26
26
  stratify_scale: z.number().optional().describe("[0,1] per-mesh training-row cap; 1 uses all cells (default 1)"),
27
27
  emd_method: z.enum(["exact", "sinkhorn"]).optional().describe("EMD solver: exact LP (default) or sinkhorn (fast approximation for large grids)"),
28
- te_inner_samples: z.number().int().optional().describe("Inner statistical sample count for per-batch topographic error estimates during SOM training (default clamp(grid_nodes*6, 500, 10000); display cap remains ≤1000 batch points/phase)"),
28
+ te_panel_size: z.number().int().optional().describe("Fixed evaluation-panel size for live topographic error during training (default clamp(grid_nodes*6, 500, 10000); curve stays on this panel end-to-end)"),
29
+ te_inner_samples: z.number().int().optional().describe("Deprecated alias for te_panel_size"),
29
30
  component_planes_physical: z.boolean().optional().describe("Physical-scale component-plane colorbars (default true)"),
30
31
  figures: z.boolean().optional().describe("Generate publication figures (default true)"),
31
32
  transforms: z.record(z.enum(["log", "log1p", "log10", "sqrt", "square", "abs", "invert", "none"])).optional().describe("Per-feature transform applied before normalization (e.g. log1p to compress k/epsilon/omega). Same preprocessing engine as barsom training."),
@@ -40,6 +41,9 @@ COMMON MISTAKES: omitting feature_columns (required); choosing a reference_mesh
40
41
  if (v !== undefined && v !== null)
41
42
  params[k] = v;
42
43
  }
44
+ if (params.te_panel_size == null && params.te_inner_samples != null) {
45
+ params.te_panel_size = params.te_inner_samples;
46
+ }
43
47
  const body = { dataset_id, params };
44
48
  if (typeof label === "string" && label.length > 0)
45
49
  body.label = label;
@@ -3,6 +3,7 @@ import { registerAppTool } from "@modelcontextprotocol/ext-apps/server";
3
3
  import { runMcpToolAudit } from "../audit.js";
4
4
  import { apiCall, getClientSupportsMcpApps, getVizPort, structuredTextResult, } from "../shared.js";
5
5
  import { enrichWithTrainingLog, needsTrainingLogEnrichment } from "../training_review.js";
6
+ import { formatRunConfigTable } from "../run_config.js";
6
7
  export const TRAINING_MONITOR_URI = "ui://barmesh/training-monitor";
7
8
  export const TRAINING_MONITOR_REFRESH_MS = 5000;
8
9
  function buildStructuredContent(job_id, data) {
@@ -51,7 +52,9 @@ export function registerTrainingMonitorTool(server) {
51
52
  timingParts.push(`epoch ${epoch}/${totalEpochs}`);
52
53
  const timingNote = timingParts.length > 0 ? ` ${timingParts.join(", ")}.` : "";
53
54
  const modeNote = terminal ? " (post-hoc review — training-log curves)" : "";
54
- const text = `Training monitor (visual MCP App, refreshes every ${TRAINING_MONITOR_REFRESH_MS / 1000}s): job ${job_id} — ${jobStatus} (${progress.toFixed(1)}%).${modeNote}${timingNote}`;
55
+ const runConfigNote = formatRunConfigTable(data);
56
+ const text = (runConfigNote ? `${runConfigNote}\n` : "") +
57
+ `Training monitor (visual MCP App, refreshes every ${TRAINING_MONITOR_REFRESH_MS / 1000}s): job ${job_id} — ${jobStatus} (${progress.toFixed(1)}%).${modeNote}${timingNote}`;
55
58
  const content = [{ type: "text", text }];
56
59
  const port = getVizPort();
57
60
  const standaloneUrl = port
@@ -9,13 +9,21 @@ export function combinedBatchAxis(nOrd, nConv) {
9
9
  return [];
10
10
  return [...batchSampleAxis(nOrd, 0), ...batchSampleAxis(nConv, nOrd)];
11
11
  }
12
+ export function isKernelTrainingComplete(data, status) {
13
+ if (status === "failed" || status === "cancelled")
14
+ return true;
15
+ if (data.kernel_complete === true)
16
+ return true;
17
+ return status === "completed";
18
+ }
19
+ export function teCurveLabel(base, _kernelComplete = false) {
20
+ return `${base} (panel)`;
21
+ }
12
22
  export function formatCurveSourceNote(data) {
13
23
  const src = data.training_curve_source_batches;
14
- if (!src)
15
- return null;
16
24
  const parts = [];
17
- const ordTotal = typeof src.ordering === "number" ? src.ordering : null;
18
- const convTotal = typeof src.convergence === "number" ? src.convergence : null;
25
+ const ordTotal = src && typeof src.ordering === "number" ? src.ordering : null;
26
+ const convTotal = src && typeof src.convergence === "number" ? src.convergence : null;
19
27
  const ordShown = Array.isArray(data.ordering_errors) ? data.ordering_errors.length : 0;
20
28
  const convShown = Array.isArray(data.convergence_errors) ? data.convergence_errors.length : 0;
21
29
  if (ordTotal != null && ordTotal > ordShown) {
@@ -24,9 +32,27 @@ export function formatCurveSourceNote(data) {
24
32
  if (convTotal != null && convTotal > convShown) {
25
33
  parts.push(`${convShown} of ${convTotal.toLocaleString()} convergence batch samples`);
26
34
  }
35
+ const teEval = data.te_evaluation;
36
+ const panelM = teEval?.te_panel_size;
37
+ const panelN = teEval?.te_panel_n_train;
38
+ if (typeof panelM === "number" && typeof panelN === "number" && panelN > 0) {
39
+ const strat = teEval?.te_panel_stratified === true ? ", stratified by mesh" : "";
40
+ parts.push(`TE curve uses a fixed panel of ${panelM.toLocaleString()} of ${panelN.toLocaleString()} training rows${strat}`);
41
+ }
42
+ const panelTe = data.panel_topographic_error;
43
+ const mapTe = data.map_topographic_error;
44
+ if (panelTe != null &&
45
+ mapTe != null &&
46
+ Number.isFinite(Number(panelTe)) &&
47
+ Number.isFinite(Number(mapTe))) {
48
+ parts.push(`Panel TE ${Number(panelTe).toFixed(4)} · Map TE ${Number(mapTe).toFixed(4)} (full training set)`);
49
+ }
27
50
  if (parts.length === 0)
28
51
  return null;
29
- return `Displaying uniformly subsampled QE+TE curves (≤1000 points/phase, joint indices): ${parts.join("; ")}.`;
52
+ const subsample = ordTotal != null || convTotal != null
53
+ ? "Displaying uniformly subsampled QE+TE curves (≤1000 points/phase, joint indices): "
54
+ : "";
55
+ return `${subsample}${parts.join("; ")}.`.replace(/: ;/, ":");
30
56
  }
31
57
  /** Map TE onto QE batch axis; when batch-aligned (same length), use values directly. */
32
58
  export function alignTeToQeAxis(te, qeLen) {
@@ -42,8 +68,7 @@ export function alignTeToQeAxis(te, qeLen) {
42
68
  return [...Array(pad).fill(null), ...te];
43
69
  }
44
70
  /**
45
- * Last sampled TE point from the (batch-aligned) live TE curve. This is the most
46
- * recent per-epoch TE estimate, distinct from the final trained-map TE in the summary.
71
+ * Last panel TE point from the (batch-aligned) live TE curve.
47
72
  */
48
73
  export function lastEpochTeFromCurves(data) {
49
74
  const conv = data.convergence_topographic_errors;