@chessceo/mcp 0.40.0 → 0.42.0

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/dist/index.js CHANGED
@@ -480,6 +480,7 @@ const TOOLS = [
480
480
  "• When they agree → high confidence. When they disagree → look at both scores and reason WHY (Stockfish sharply higher = tactic Lc0 missed; Lc0 higher = long-term positional edge past Stockfish's horizon). Never dismiss either — the disagreement is the signal.\n\n" +
481
481
  "Contempt (`contempt`) skews Lc0 (only Lc0 — Stockfish always stays objective) toward White (positive) or Black (negative). Signed 0-100 strength — same scale as the web UI's ContemptStrength slider (the server multiplies by 8 to produce Lc0's internal cp bias). Typical values: ±15 for a light nudge, ±30-60 for real fighting play, ±80-100 for maximum steer. Use it to find non-objective 'practical' ideas or when the user needs to lean toward fighting/solid lines with a specific colour. Do NOT quote a contempt-biased eval as objective — cross-check with Stockfish.\n\n" +
482
482
  "Also useful: pass `moves` on top of `fen` to explore a variation without computing FENs yourself (e.g. fen='<tabiya>', moves='b4 a5 c3'). And the flip-side-to-move threat check documented in the guide is a great free trick.\n\n" +
483
+ "**PVs are capped at 6 plies by default (3 full moves), and lines that got truncated are marked with `pv_truncated: true`.** This is deliberate: the tail of a PV is where the engine's confidence collapses, AND pasting a long PV into `add_line` as if it were prepared repertoire is the #1 documented anti-pattern of this MCP — a 15-move PV is one line of engine output through positions where both sides had real choices, not a repertoire. To see further, don't raise `pv_max_plies`; instead, walk the tree one branch at a time with a fresh `cloud_analyse` at each position where the opponent has real alternatives — that's what makes it prep instead of pasted output. Only raise the cap when you're verifying a forcing sequence (a mate, a forced tactical resolution), not to build lines.\n\n" +
483
484
  "For the full guide including worked examples, call the `read_engine_usage_guide` tool.\n\n" +
484
485
  "Not for casual questions — this costs real money per second. Use `get_position_stats` for anything that doesn't require deep prep.\n\n" +
485
486
  "**When called with `file_id`+`node_id` (preferred inside a prep file), the resulting eval is auto-stored on that node's `ceoEval` — you can then quote it with quote_engine_eval on any later call.** This is what makes engine attribution trustworthy: prose that says 'engines say X on node Y' can only be true if a call was actually made against node_id=Y.",
@@ -522,6 +523,12 @@ const TOOLS = [
522
523
  items: { type: "string", enum: ["stockfish", "lc0"] },
523
524
  description: "Which engines to run. Default = both. Use `[\"lc0\"]` to skip Stockfish (e.g. while a deep_analyse job is holding the SF slot on the same combo). Use `[\"stockfish\"]` when only the objective read matters. The skipped engine's field is omitted from the response.",
524
525
  },
526
+ pv_max_plies: {
527
+ type: "integer",
528
+ minimum: 1,
529
+ maximum: 40,
530
+ description: "Cap each returned PV to this many plies (default 6 = 3 full moves). PVs beyond ~6 plies are speculative and are the anti-pattern behind pasted-engine-line 'prep' — don't raise unless you're specifically checking a forcing tactic or verifying a mate. When a line was truncated, the response marks it with `pv_truncated: true`.",
531
+ },
525
532
  },
526
533
  },
527
534
  },
@@ -646,7 +653,8 @@ const TOOLS = [
646
653
  {
647
654
  name: "add_line",
648
655
  description: "Append a linear sequence of moves under `parent_id`. Each SAN in the list becomes the mainline child of the previous — one call instead of N add_move calls for a straight variation. If the parent already has other children, this whole line is appended as a variation (promote_variation the first move if you want it as the mainline).\n\n" +
649
- "Auto-saves. Returns `{node_id, line: [{node_id, san}, ...], version}` — `node_id` is the last (leaf) node's id, `line` is every node created in order so you can address any of them next.",
656
+ "**Anti-pattern: pasting an engine PV as a single long `add_line`.** Real prep is a tree, not a line. Almost every position along a variation has more than one plausible move — pasting a 12+-ply engine PV without branching at those points is the #1 documented failure mode of this MCP: it produces a page that reads as prep but ignores every decision the opponent actually gets to make. Long unbranched lines get a warning field in the response starting at ~9 plies and a strong warning at 14+ plies. Rule of thumb: if you added ≥8 plies in one call, at least half of them should have branched. Genuine exceptions exist (forced mates, obligated exchange sequences) — in those cases add a comment naming what makes the sequence forced (`{Every move here is forced by the mate threat.}`), so the reader knows it's forced by chess, not by LLM laziness.\n\n" +
657
+ "Auto-saves. Returns `{node_id, line: [{node_id, san}, ...], version}` — `node_id` is the last (leaf) node's id, `line` is every node created in order so you can address any of them next. When long-and-linear, also includes `warning: \"...\"`.",
650
658
  inputSchema: {
651
659
  type: "object",
652
660
  properties: {
@@ -1070,6 +1078,88 @@ async function fetchCompactEval(fen) {
1070
1078
  }
1071
1079
  // Rewrite the /api/agent/cloud-engines/analyse response (two engines,
1072
1080
  // each with lines[] and a bestMove) so PVs and bestMove come back in SAN.
1081
+ // Session-lifetime memory of which positions the LLM has actually asked
1082
+ // the DB about via `get_position_stats`. Keyed by the 3-field FEN
1083
+ // (piece placement + side to move + castling — same key used for
1084
+ // transposition detection). Used to warn on `add_move` / `add_line` under
1085
+ // a parent the LLM never DB-checked, which is the exact shape of the
1086
+ // bug where the LLM read course chapters and cargo-culted a "mainline"
1087
+ // that the actual games at the position don't play.
1088
+ //
1089
+ // One MCP server process per user, so this Set is effectively per-user
1090
+ // for the length of a session. Not persisted — a new session starts empty.
1091
+ const positionsStatsChecked = new Set();
1092
+ // Nodes we've ALREADY warned on for the "no stats check" pattern this
1093
+ // session, so repeated adds under the same parent don't spam the LLM.
1094
+ const noStatsWarned = new Set();
1095
+ // Detect the anti-patterns the LLM keeps producing in comment prose.
1096
+ // All of these restate what the app already renders elsewhere:
1097
+ // - spread lists ("5.O-O ≈50, 6.h3 ≈42, ...")
1098
+ // - raw centipawn values in prose ("≈-60", "+0.35", "at depth 24")
1099
+ // - long roster restatement ("146 GM games, Nakamura, Kramnik, MVL")
1100
+ // Return an array of warning strings — one per matched category — so the
1101
+ // LLM sees exactly which pattern to remove.
1102
+ function commentAntiPatterns(comment) {
1103
+ if (!comment || typeof comment !== "string")
1104
+ return [];
1105
+ const warns = [];
1106
+ // Spread list: ≈ followed by a 2-3-digit number, appearing 2+ times
1107
+ // (one appearance is a stray, two+ is a comma-separated spread the LLM
1108
+ // pasted from stats output).
1109
+ const spreadMatches = comment.match(/≈\s*[+\-−]?\d{1,3}/g) ?? [];
1110
+ if (spreadMatches.length >= 2) {
1111
+ warns.push("comment contains a spread list (≈ + counts) — the DB viewer already shows sibling counts and fashion scores next to every move, so this is doubled noise. Name the character of the choice instead (\"solid vs sharp\", \"old vs fashionable\") or drop the numbers.");
1112
+ }
1113
+ // Raw centipawn in prose: "+0.35", "-0.20", "+80" (not preceded by move
1114
+ // number). Also "at depth N" or "N nodes" — engine metadata as prose.
1115
+ if (/(?:^|[^\d.])[+-]\d\.\d\d(?!\d)/.test(comment) || /≈\s*[+\-−]?\d{2,3}\b/.test(comment) ||
1116
+ /\bat depth \d+\b/i.test(comment) || /\b\d{2,3}M nodes\b/.test(comment)) {
1117
+ warns.push("comment contains raw centipawn values or engine metadata — the app renders ceoEval + NAG glyph next to every node, so these numbers are doubled noise AND opaque (readers can't tell if ≈-60 means eval, spread, or something else). Set the NAG (set_nags) and let the glyph carry the judgment; drop the number from the prose.");
1118
+ }
1119
+ // Roster: "N GM games" pattern
1120
+ if (/\b\d{2,4}\s+GM games\b/i.test(comment)) {
1121
+ warns.push("comment restates game count — the app shows the count on hover. Either cite a specific game with signal (\"Caruana-Liang, Superbet 2026\") or drop the number.");
1122
+ }
1123
+ return warns;
1124
+ }
1125
+ // Return a warning string when an add_line is suspiciously long-and-linear
1126
+ // (the anti-pattern: LLM pastes a 15-ply engine PV into a single add_line
1127
+ // call as if it were prepared repertoire). Two thresholds so the message
1128
+ // escalates — a 10-ply Berlin mainline is fine, a 20-ply LLM extrapolation
1129
+ // almost never is. Threshold applies at the CALL level, not against
1130
+ // existing tree depth — the anti-pattern is a single tool call adding
1131
+ // many plies at once with no user thought about where the branching should
1132
+ // live.
1133
+ function longLineWarning(sansLength) {
1134
+ if (sansLength >= 14) {
1135
+ return `you added ${sansLength} plies in one call without branching — this is the shape of a pasted engine PV, not a repertoire. Real prep branches at every ply where the opponent has meaningful alternatives. Either (a) delete the tail and rebuild with add_move at each decision point, calling cloud_analyse + get_position_stats to see what actually gets played, or (b) if this really is one forcing sequence (mate combination, tactical winner), add a comment naming what makes it forced. Long unbranched lines with no comment default to "engine PV pasted as prep" in the reader's eyes.`;
1136
+ }
1137
+ if (sansLength >= 9) {
1138
+ return `${sansLength}-ply linear line — check that every ply is a genuine only-move or a documented mainline. If the opponent has real alternatives at any ply (get_position_stats would show 2+ moves with meaningful frequency), that ply should branch instead. Prep is a tree, not a line.`;
1139
+ }
1140
+ return undefined;
1141
+ }
1142
+ // Trim every PV in a converted cloud-analyse response to `maxPlies`
1143
+ // and mark each trimmed line with `pv_truncated: true` so the LLM
1144
+ // sees what happened. Applied ONLY to cloud_analyse (short synchronous
1145
+ // snapshot); deep_analyse is the explicit "give me the deep line"
1146
+ // tool and keeps its full PV.
1147
+ function capPvsInResponse(converted, maxPlies) {
1148
+ if (!converted || typeof converted !== "object")
1149
+ return;
1150
+ const r = converted;
1151
+ for (const eng of [r.stockfish, r.lc0]) {
1152
+ if (!eng || !Array.isArray(eng.lines))
1153
+ continue;
1154
+ for (const line of eng.lines) {
1155
+ if (Array.isArray(line.pv) && line.pv.length > maxPlies) {
1156
+ line.pv = line.pv.slice(0, maxPlies);
1157
+ line.pv_truncated = true;
1158
+ }
1159
+ }
1160
+ }
1161
+ converted.pv_max_plies = maxPlies;
1162
+ }
1073
1163
  function convertCloudSnapshotResponse(raw, startFen) {
1074
1164
  if (!raw || typeof raw !== "object")
1075
1165
  return raw;
@@ -1115,17 +1205,33 @@ function dispatchMutation(file, idIndex, op) {
1115
1205
  };
1116
1206
  const resolve = (id) => resolveNodeId(idIndex, id);
1117
1207
  switch (kind) {
1118
- case "add_move":
1119
- return addMove(file, resolve(nodeIdField("parent_id")), String(op.san));
1208
+ case "add_move": {
1209
+ const parentPath = resolve(nodeIdField("parent_id"));
1210
+ const parent = getNodeByPath(file.root, parentPath);
1211
+ const noStatsWarn = noStatsCheckWarning(parent);
1212
+ const step = addMove(file, parentPath, String(op.san));
1213
+ return { ...step, ...(noStatsWarn ? { warning: noStatsWarn } : {}) };
1214
+ }
1120
1215
  case "add_line": {
1121
1216
  const sans = Array.isArray(op.sans) ? op.sans.map(String) : [];
1122
1217
  const parentPath = resolve(nodeIdField("parent_id"));
1218
+ const parent = getNodeByPath(file.root, parentPath);
1123
1219
  const step = addLine(file, parentPath, sans);
1124
1220
  const lastId = step.line.length > 0 ? step.line[step.line.length - 1].id : nodeIdField("parent_id");
1125
- return { file: step.file, id: lastId, results: step.line };
1221
+ // Same anti-pattern warnings as the standalone add_line case —
1222
+ // long unbranched line + no-stats-check parent are both bugs
1223
+ // whether they land solo or inside a batch.
1224
+ const longLineWarn = longLineWarning(sans.length);
1225
+ const noStatsWarn = noStatsCheckWarning(parent);
1226
+ const warnings = [longLineWarn, noStatsWarn].filter((s) => !!s);
1227
+ return { file: step.file, id: lastId, results: step.line, ...(warnings.length > 0 ? { warnings } : {}) };
1228
+ }
1229
+ case "set_comment": {
1230
+ const commentStr = typeof op.comment === "string" ? op.comment : "";
1231
+ const commentWarns = commentAntiPatterns(commentStr);
1232
+ const step = setComment(file, resolve(nodeIdField("node_id")), commentStr);
1233
+ return { ...step, ...(commentWarns.length > 0 ? { warnings: commentWarns } : {}) };
1126
1234
  }
1127
- case "set_comment":
1128
- return setComment(file, resolve(nodeIdField("node_id")), typeof op.comment === "string" ? op.comment : "");
1129
1235
  case "set_nags":
1130
1236
  return setNags(file, resolve(nodeIdField("node_id")), Array.isArray(op.nags) ? op.nags.map(String) : []);
1131
1237
  case "set_annotations": {
@@ -1170,7 +1276,12 @@ async function applyBatchMutations(args) {
1170
1276
  const step = dispatchMutation(file, idIndex, op);
1171
1277
  file = step.file;
1172
1278
  idIndex = buildIdIndex(file.root);
1173
- results.push({ node_id: step.id, ...(step.results !== undefined ? { line: step.results } : {}) });
1279
+ results.push({
1280
+ node_id: step.id,
1281
+ ...(step.results !== undefined ? { line: step.results } : {}),
1282
+ ...(step.warning ? { warning: step.warning } : {}),
1283
+ ...(step.warnings && step.warnings.length > 0 ? { warnings: step.warnings } : {}),
1284
+ });
1174
1285
  }
1175
1286
  catch (err) {
1176
1287
  const msg = err instanceof Error ? err.message : String(err);
@@ -1862,9 +1973,29 @@ async function applyMutation(args, mutator) {
1862
1973
  ok: true,
1863
1974
  node_id: result.id,
1864
1975
  ...(result.results !== undefined ? { line: result.results } : {}),
1976
+ ...(result.warning ? { warning: result.warning } : {}),
1977
+ ...(result.warnings && result.warnings.length > 0 ? { warnings: result.warnings } : {}),
1865
1978
  version: savedRow.version,
1866
1979
  };
1867
1980
  }
1981
+ // Compute the "you never DB-checked this parent" warning. Called from
1982
+ // add_move / add_line handlers with the parent node. Returns undefined
1983
+ // when either (a) the parent was checked this session (or is root — the
1984
+ // starting position doesn't need a DB check), (b) we already warned on
1985
+ // this parent (dedup so building a big branching subtree isn't spammy),
1986
+ // or (c) the mutator is running against a parent whose position has a
1987
+ // stored ceoEval (implies the LLM has done SOME analytical work here).
1988
+ function noStatsCheckWarning(parent) {
1989
+ if (parent.id === ROOT_ID)
1990
+ return undefined;
1991
+ const key = positionKey(parent.fen);
1992
+ if (positionsStatsChecked.has(key))
1993
+ return undefined;
1994
+ if (noStatsWarned.has(parent.id))
1995
+ return undefined;
1996
+ noStatsWarned.add(parent.id);
1997
+ return `no get_position_stats call for the parent (id=${parent.id}, ${parent.san}) this session. Course chapter titles describe what an author chose to cover, not what practical opponents play — treating "the So chapter says 6.O-O-O" as "the mainline is 6.O-O-O" is the exact pattern this warning exists to catch. Call get_position_stats at this position (via file_id+node_id=${parent.id}) BEFORE deciding which branches belong here; suppress this warning by making that call. Warned once per parent per session.`;
1998
+ }
1868
1999
  async function loadPrepFile(id) {
1869
2000
  const raw = await authedRequest("GET", `/api/agent/prep-files/${encodeURIComponent(id)}`);
1870
2001
  const g = raw;
@@ -2529,6 +2660,10 @@ async function callToolInner(name, args) {
2529
2660
  if (ev)
2530
2661
  converted.eval = ev;
2531
2662
  }
2663
+ // Record that this position was DB-checked this session. Downstream
2664
+ // add_move / add_line under this parent won't fire the "no stats
2665
+ // check" warning. Keyed by 3-field FEN so transpositions count.
2666
+ positionsStatsChecked.add(positionKey(fen));
2532
2667
  return converted;
2533
2668
  }
2534
2669
  case "describe_position": {
@@ -2627,6 +2762,21 @@ async function callToolInner(name, args) {
2627
2762
  body.engines = args.engines;
2628
2763
  const raw = await authedRequest("POST", "/api/agent/cloud-engines/analyse", body);
2629
2764
  const converted = convertCloudSnapshotResponse(raw, fen);
2765
+ // PV cap: engine PVs beyond ~6 plies are speculative (the tail is
2766
+ // where the search's confidence collapses — SF at depth 24 has
2767
+ // seen the first few plies solidly and hedged everything after).
2768
+ // More importantly, LLMs paste long PVs into `add_line` as if
2769
+ // they were prepared repertoire. A 15-move PV pasted as a
2770
+ // variation is one line of engine output through positions
2771
+ // where both sides had real choices — not a repertoire. Cap the
2772
+ // affordance: return only what's load-bearing (3 full moves for
2773
+ // understanding the point), let the caller re-analyse the
2774
+ // resulting position if they want to see further. Override via
2775
+ // `pv_max_plies` for the rare case (deep tactics verification).
2776
+ const pvMaxPlies = typeof args.pv_max_plies === "number" && args.pv_max_plies > 0
2777
+ ? Math.min(args.pv_max_plies, 40)
2778
+ : 6;
2779
+ capPvsInResponse(converted, pvMaxPlies);
2630
2780
  // Node-addressed calls: persist the result on the node's ceoEval
2631
2781
  // so a later quote_engine_eval can cite this measurement. This is
2632
2782
  // the anti-hallucination hinge — prose that says "engines say X
@@ -2674,17 +2824,42 @@ async function callToolInner(name, args) {
2674
2824
  case "delete_prep_file":
2675
2825
  return authedRequest("DELETE", `/api/agent/prep-files/${encodeURIComponent(String(args.id))}`);
2676
2826
  case "add_move":
2677
- return applyMutation(args, (file, idIndex) => addMove(file, resolveNodeId(idIndex, argNodeId(args, "parent_id")), String(args.san)));
2678
- case "add_line":
2679
2827
  return applyMutation(args, (file, idIndex) => {
2680
- const sans = Array.isArray(args.sans) ? args.sans.map(String) : [];
2681
2828
  const parentPath = resolveNodeId(idIndex, argNodeId(args, "parent_id"));
2682
- const step = addLine(file, parentPath, sans);
2829
+ const parent = getNodeByPath(file.root, parentPath);
2830
+ const noStatsWarn = noStatsCheckWarning(parent);
2831
+ const step = addMove(file, parentPath, String(args.san));
2832
+ return { ...step, ...(noStatsWarn ? { warning: noStatsWarn } : {}) };
2833
+ });
2834
+ case "add_line": {
2835
+ const sansArg = Array.isArray(args.sans) ? args.sans.map(String) : [];
2836
+ const longLineWarn = longLineWarning(sansArg.length);
2837
+ return applyMutation(args, (file, idIndex) => {
2838
+ const parentPath = resolveNodeId(idIndex, argNodeId(args, "parent_id"));
2839
+ const parent = getNodeByPath(file.root, parentPath);
2840
+ const noStatsWarn = noStatsCheckWarning(parent);
2841
+ const step = addLine(file, parentPath, sansArg);
2683
2842
  const lastId = step.line.length > 0 ? step.line[step.line.length - 1].id : argNodeId(args, "parent_id");
2684
- return { file: step.file, id: lastId, results: step.line };
2843
+ const combined = [longLineWarn, noStatsWarn].filter((s) => !!s);
2844
+ return {
2845
+ file: step.file,
2846
+ id: lastId,
2847
+ results: step.line,
2848
+ ...(combined.length > 0 ? { warnings: combined } : {}),
2849
+ };
2685
2850
  });
2686
- case "set_comment":
2687
- return applyMutation(args, (file, idIndex) => setComment(file, resolveNodeId(idIndex, argNodeId(args)), typeof args.comment === "string" ? args.comment : ""));
2851
+ }
2852
+ case "set_comment": {
2853
+ const commentStr = typeof args.comment === "string" ? args.comment : "";
2854
+ const commentWarns = commentAntiPatterns(commentStr);
2855
+ return applyMutation(args, (file, idIndex) => {
2856
+ const step = setComment(file, resolveNodeId(idIndex, argNodeId(args)), commentStr);
2857
+ return {
2858
+ ...step,
2859
+ ...(commentWarns.length > 0 ? { warnings: commentWarns } : {}),
2860
+ };
2861
+ });
2862
+ }
2688
2863
  case "set_nags":
2689
2864
  return applyMutation(args, (file, idIndex) => setNags(file, resolveNodeId(idIndex, argNodeId(args)), Array.isArray(args.nags) ? args.nags.map(String) : []));
2690
2865
  case "set_annotations": {
@@ -191,8 +191,19 @@ Two calls:
191
191
 
192
192
  If the user is specifically preparing to *play* the black side in a must-win, add `contempt=-30` (or up to `-60` for a harder steer) on a follow-up call to see which lines Lc0 finds most fighting for Black. Compare against Stockfish's objective read to make sure the fighting choice isn't just losing.
193
193
 
194
+ ## The PV is not a line to paste
195
+
196
+ `cloud_analyse` caps each PV at 6 plies (3 full moves) by default and marks longer ones `pv_truncated: true`. This is deliberate — the tail of a PV is where the engine's confidence collapses (SF at depth 24 has resolved the first few plies solidly and hedged everything after), and pasting long PVs into `add_line` as prep is the biggest documented anti-pattern of this whole system.
197
+
198
+ **A PV tells you what the engine sees, not what will be played.** A 15-ply PV pasted as a variation is one line of engine output through positions where the opponent had 2-3 real alternatives at almost every ply. That's not prep — that's the engine's preferred game, and no opponent plays the engine's preferred game.
199
+
200
+ **To see further into a line, walk the tree.** Take the position at the tail of your truncated PV, run a fresh `cloud_analyse` on it. That call gives you the multipv candidate set at THAT position — the opponent's actual options — which is what you need to decide whether to branch. Don't raise `pv_max_plies` unless you're verifying a forcing sequence (a mate, an obligated recapture chain).
201
+
202
+ Practical: raise `lc0_multipv` (default 8) to see the candidate spread on the current position, NOT to see further down one PV. If Lc0 shows moves 1-3 within 0.15 of each other, that's a branching point — three responses need coverage, not one PV.
203
+
194
204
  ## What NOT to do
195
205
 
206
+ - **Don't paste PVs as `add_line` variations.** See the section above and `pgn-authoring.md`'s "Prep is a TREE, not a line" section. This is not a stylistic preference — the tool warns you starting at 9 plies and warns hard at 14+, and the truncated `pv_truncated: true` marker is telling you the engine itself doesn't stand behind the tail.
196
207
  - **Don't quote Lc0's contempt-biased eval as objective.** If you tell the user "Lc0 gives Black +0.30 here" without disclosing you set contempt=-30, that's misleading.
197
208
  - **Don't run cloud analysis just for casual questions.** `cloud_analyse` costs the user real money per second. If the question is "is 1.e4 or 1.d4 better?", the free `analyse` (single Stockfish, 2s) or `get_position_stats` (11.7M-game database) is enough.
198
209
  - **Don't ignore the disagreement.** When Stockfish and Lc0 diverge sharply, that's exactly when you should explain *why* to the user — not paper over it.
@@ -155,15 +155,80 @@ Prose is NEVER for:
155
155
  - Move recommendations ("here White should play h4") — add_move it.
156
156
  - Restating the eval a NAG already conveys.
157
157
  - **Describing a sibling variation you already added as a branch.** If move A has variation B added as `add_move(A, sibling)`, don't ALSO write `{if B then ...}` on A. The reader clicks B on the board — the branch is already there.
158
- - **Restating what the app already renders.** The reader opens the file in the app and sees: every sibling move (with count / avg rating / top players from the DB), each node's stored `ceoEval`, the NAG glyphs, the tree structure. Duplicating any of that in prose is pure noise.
158
+ - **Restating what the app already renders.** The reader opens the file in the app and sees: every sibling move (with count / avg rating / top players from the DB), each node's stored `ceoEval`, the NAG glyphs, the tree structure. Duplicating any of that in prose is pure noise. Three specific patterns to never emit:
159
159
 
160
- - ❌ `{5...Bb4 (180/247), 5...d6 (26), 5...Be7 (18), 5...d5 (7), 5...g6 (2)}` — those are the sibling variations, already visible.
161
- - ❌ `{Main move, 180 of 247 games (So, Giri, Karjakin, Duda). Eval −0.20/−0.27.}` — count, top players, eval all shown by the app.
162
- - ✅ `{Main move; the sharpest test is actually 5...d5 (only 7 games but avg 2526) — see the variation.}`
163
- - ✅ `{Popular, but leads to the endgame Black draws — 6.Bd2 is where prep depth matters.}`
160
+ **1. Spread lists.** The database viewer already shows sibling counts and fashion scores next to every move. Pasting them into prose is doubled noise.
161
+
162
+ - ❌ `{Spread: 5.O-O ≈50, 6.h3 ≈42, 6.a4 ≈35, 6.Be3 ≈27, 6.Nbd2 ≈18 — the more White delays castling the less he gets.}` — every number here is one click away.
163
+ - ❌ `{Spread: 5.Nf3 ≈56, 5.Bd3 ≈55, 5.Be3 ≈47, 5.Rb1 ≈35, 5.h3 ≈32.}` — same problem.
164
+ - ✅ `{Two roads: quiet 5.Bd3 keeps position closed, sharp 5.e5 concedes the centre for tempo — cover both.}` — names the *character*, not the numbers.
165
+
166
+ **2. Raw centipawn values in prose.** The app shows `ceoEval` as `+0.20 / −0.27` next to every node and the NAG glyph next to that. If you write `≈−60` or `+0.35` in a comment, no reader knows whether that's a spread number, an eval, or a made-up decoration — and every one of them is visible without your prose.
167
+
168
+ - ❌ `{Best try, but ≈80 — a fifth of a pawn worse than the ...Nd7 move order.}` — cp number, opaque.
169
+ - ❌ `{0.00 at depth 31, 259M nodes.}` — engine metadata masquerading as insight; the eval is already visible.
170
+ - ❌ `{≈−60. White's f5 sacrifice does not work with the centre already liquidated.}` — the number tells the reader nothing; the *reason* is the whole comment.
171
+ - ✅ `{White's f5 sacrifice doesn't work with the centre already liquidated — no target for the pawn.}` — same content, no fake precision.
172
+ - ✅ Or better: set the NAG (`$17` for clear Black advantage) and drop the prose entirely; the glyph carries the judgment.
173
+
174
+ **3. Top-player rosters.** Count + names of the top players are shown on hover in the app. `146 GM games, Nakamura, Kramnik, MVL, So all play this` restates two visible facts.
175
+
176
+ - ❌ `{150 GM games and Caruana's choice against Liang in 2026.}` — count is visible; the specific-game citation is fine on its own if it carries prep signal.
177
+ - ✅ `{Caruana played this against Liang, Superbet 2026 — the current top-choice among elite Black players.}` — same specific-game citation, no restated count.
178
+
179
+ **Positive vocabulary for what the app can't render.** The reader wants labels the DB doesn't provide:
180
+
181
+ - `{The old main line — dominant through 2015, replaced by 6.Bd2 after Ding-Carlsen 2016.}` — historical context, not visible.
182
+ - `{The current fashion — 40+ games since 2024, mostly at 2700+.}` — recency signal condensed to a phrase, not a number list.
183
+ - `{Solid try (holds objectively) vs the sharper 6.Nd5 (small edge but requires memory) — choose based on style.}` — practical framing, uses labels the reader can act on.
184
+ - `{Prophylactic — every White plan is based on Bg5, this pre-empts it.}` — one word (prophylactic / restraint / clamp / breakthrough) does the work of a paragraph.
164
185
 
165
186
  Test: if the reader can see it by looking at the position or clicking a branch, don't write it. Prose is only for plans, prep-signal, or WHY — the layer the app can't derive.
166
187
 
188
+ - **Prose "prevents Y" claims — always show Y as a `?`-tagged variation instead.** When you write `{6.f3 is necessary to prevent ...Bxh3.}` the reader has to trust you that the tactic exists. When you instead add a sibling variation `6.O-O? Bxh3 7.gxh3 …` marked with `?` in the NAG, the reader can play through the refutation themselves. Two benefits: (1) grounds the claim in an actual move sequence, so hallucinated tactics get exposed at authoring time when SAN validation runs; (2) the reader learns the tactic instead of taking your word for it. Rule: any prose of the shape "X because it prevents/avoids/deals with Y" should be either supplemented by or replaced with a `?`-marked variation showing Y.
189
+
190
+ - ❌ `{6.f3 is necessary — 6.O-O? runs into ...Bxh3 winning the exchange.}` — no way to check.
191
+ - ✅ Under 5.Nc3, add both `6.f3` (mainline) AND `6.O-O` as a sibling variation with `set_nags(["$2"])` and continuation `[Bxh3, gxh3, ...]` showing the refutation. The prose on 6.f3 shrinks to `{The 6.O-O branch shows why f3 must come first.}` — six words, refutation is playable.
192
+
193
+ ## Prep is a TREE, not a line — the pasted-engine-PV anti-pattern
194
+
195
+ This is the single biggest quality problem in current LLM output on this system: after a `cloud_analyse` call the LLM sees a PV like `[Nf3, Nc6, Bb5, a6, Ba4, Nf6, O-O, Be7, Re1, b5, Bb3, O-O, ...]` and pastes it into a single `add_line`. 15 moves in one call, no branching, no reason to think the opponent will play any of those specific moves — one line of engine output through positions where both sides had real choices.
196
+
197
+ **The reader can tell.** A pasted engine PV always looks the same: long, straight, no comments, no NAGs, ends in a position with no obvious relevance. It's the shape of the output, not the individual moves, that gives it away.
198
+
199
+ **The fix is branching, not length.** Every ply along a variation is a decision point for whoever's turn it is. If the opponent has more than one plausible move at that ply (`get_position_stats` shows two or more moves with meaningful frequency; `predict_human_move` shows two or more moves with real WDL differences; `cloud_analyse.lc0.lines` shows several evals within 0.2 of each other), then that ply MUST branch — you're not preparing if you only cover one response.
200
+
201
+ **Concrete rules:**
202
+
203
+ - **`cloud_analyse` PVs are capped at 6 plies by default and marked `pv_truncated: true` when longer.** This is not a bug — it's telling you that the engine's confidence tail is not repertoire material. To see further into a line, don't raise `pv_max_plies` — pick the position at the end of the truncated PV and run a fresh `cloud_analyse` on it. That's what makes it prep instead of pasted output.
204
+
205
+ - **`add_line` warns when you pass ≥9 plies** and warns hard at ≥14 plies. Long unbranched lines with no comment default to "engine PV pasted as prep" in the reader's eyes. Rule of thumb: if you added ≥8 plies in one call, at least half of them should have branched.
206
+
207
+ - **Genuine forcing sequences ARE allowed** — a 12-ply mate combination, an obligated exchange sequence where both sides have exactly one reasonable move at every ply. In those cases: (a) write a comment naming what makes it forced (`{Every move here is forced by the mate threat on h7.}`), and (b) don't stop where the engine PV stops — stop where the position becomes evaluatable ("winning endgame, technique wins"; "mate in 3, easy calculation from here").
208
+
209
+ **Correct pattern for building a variation.** At every ply:
210
+
211
+ 1. What are the plausible replies? `get_position_stats` (frequencies), `cloud_analyse` with `lc0_multipv: 8` (candidate spread), `predict_human_move` (what people actually play).
212
+ 2. If ≥2 are plausible → branch. `add_move` each, then recurse on each branch or `add_line` for each of the several straightforward continuations.
213
+ 3. If exactly 1 → continue linearly; note *why* it's the only move in a comment.
214
+
215
+ The failure mode you're avoiding: writing prep that reads as if the opponent will helpfully play the engine's #1 preference at every ply. They won't; that's the whole point of prep.
216
+
217
+ ## Course chapters describe COVERAGE, not consensus — always `get_position_stats` at mainline branch points
218
+
219
+ Concrete failure this rule was written to fix: a Modern Defence file made 6.O-O-O the mainline of the entire "5.Qd2 Nd7" branch, wrote a chapter around it, and analysed 15+ plies deep. `get_position_stats` at that position was NEVER called this session. Instead, the LLM ran `find_position_in_courses`, saw So / Kraai / Mihajlov all had chapters titled "5.Qd2 b5 6.O-O-O Bb7" — and cargo-culted that into "6.O-O-O is the main line". It isn't. 6.O-O-O is one of five White tries, and it wasn't even the most-played.
220
+
221
+ **Course chapter titles tell you what the author decided to cover, not what practical opponents play.** A White repertoire author picks one continuation per branch and writes it up in depth — the chapter is named after what they cover. That is not the same as "this is the mainline in current practice", nor is it the same as "this is the most-played move against 5...Nd7". Five different courses can all pick different 6th moves for the same position; five different courses can all pick the SAME 6th move for coverage reasons (that's the sharpest / most-testing / easiest-to-teach) even though the DB shows practice is split five ways.
222
+
223
+ **Rule:** before committing to a mainline branch — either `add_move` as the first child of a parent that's on the mainline, or `add_line` for a linear continuation you're calling THE way White/Black plays — you must have called `get_position_stats` at that parent position in this session. If you didn't, the mutation will warn (soft). Course reads are for what the authors *say about the move*, not what the mainline *is*.
224
+
225
+ **How the two tools relate at a branching decision:**
226
+
227
+ 1. `get_position_stats(position)` — what moves are actually played, ranked by count / avg rating / fashion. This decides which moves need a branch (any move ≥5% frequency in reasonable practice; any move with unusually high avg rating even if less frequent).
228
+ 2. `find_position_in_courses(position)` → `read_course_at_position(...)` — for each branch you decided to include, what do the authors say about it, and where do they disagree. This decides the *content* of each branch (recommended reply, key concepts, historical context), not which branches exist.
229
+
230
+ Getting these backwards is the failure this section exists to prevent.
231
+
167
232
  ## Transpositions: don't analyse (or comment on) the same position twice
168
233
 
169
234
  Move orders diverge and re-converge constantly. `1.d4 Nf6 2.c4 e6 3.Nc3` and `1.c4 e6 2.Nc3 Nf6 3.d4` land on the same position. The tree model doesn't merge those into one node — it stores both nodes with the same position — so if you're not careful you'll analyse both, quote engine numbers on both, and write two different comments for what is the same chess.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chessceo/mcp",
3
- "version": "0.40.0",
3
+ "version": "0.42.0",
4
4
  "description": "Model Context Protocol server for chess.ceo — 11.7M+ games, ~1.5M FIDE player profiles, opening preparation, live broadcasts.",
5
5
  "type": "module",
6
6
  "bin": {