@trainheroic-unofficial/coach-mcp 1.7.0 → 1.7.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.
Files changed (2) hide show
  1. package/dist/server.mjs +33 -20
  2. package/package.json +3 -3
package/dist/server.mjs CHANGED
@@ -365,6 +365,23 @@ const DEFAULT_RESULT_BUDGET = 6e4;
365
365
  const MARKER_RESERVE = 300;
366
366
  const DEFAULT_ARRAY_HINT = "Result was truncated to fit the size budget. Narrow it with a filter/search argument or paginate to see the rest.";
367
367
  const DEFAULT_OBJECT_HINT = "Result was truncated to fit the size budget. Request a more specific id or sub-resource.";
368
+ /**
369
+ * Clip an array to its first `keep` items and attach the `__truncated` marker describing what was
370
+ * dropped. The marker is model-facing (tools instruct the model to key off `__truncated`), so its
371
+ * shape has exactly one definition here: the size-budget path (`boundedSerialize`) and any tool
372
+ * that deliberately caps a list (e.g. `athlete_exercises`) emit the same thing.
373
+ */
374
+ function clipArray(items, keep, hint) {
375
+ return {
376
+ items: items.slice(0, keep),
377
+ __truncated: {
378
+ returned: keep,
379
+ total: items.length,
380
+ omitted: items.length - keep,
381
+ hint: hint ?? DEFAULT_ARRAY_HINT
382
+ }
383
+ };
384
+ }
368
385
  /** Active budget. Overridable via TH_MCP_RESULT_BUDGET on Node; the default on workerd. */
369
386
  function resultBudget() {
370
387
  const raw = (globalThis.process?.env)?.TH_MCP_RESULT_BUDGET;
@@ -421,16 +438,7 @@ function boundedSerialize(data, budget, hint) {
421
438
  }
422
439
  if (Array.isArray(data)) {
423
440
  const k = largestPrefixCount(data.map((el) => JSON.stringify(el) ?? "null"), budget - MARKER_RESERVE);
424
- const wrapped = {
425
- items: data.slice(0, k),
426
- __truncated: {
427
- returned: k,
428
- total: data.length,
429
- omitted: data.length - k,
430
- hint: hint ?? DEFAULT_ARRAY_HINT
431
- }
432
- };
433
- const out = JSON.stringify(wrapped);
441
+ const out = JSON.stringify(clipArray(data, k, hint));
434
442
  if (out.length <= budget) return out;
435
443
  } else if (isPlainObject(data)) {
436
444
  const key = largestArrayValuedKey(data);
@@ -1336,8 +1344,10 @@ function toSetResults(results) {
1336
1344
  * `param_2_data_N` string values plus a `param_N_made` flag.
1337
1345
  *
1338
1346
  * `mode` selects which write this is — the same endpoint serves both:
1339
- * - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has data
1340
- * and the exercise `completed` flag is 1 when any set has logged data.
1347
+ * - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has reps
1348
+ * entered (`param1`) and the exercise `completed` flag is 1 when any set is performed. A slot
1349
+ * carrying only a weight (`param2`) with no reps is a target, not a performed set, so it stays
1350
+ * un-made — matching the app, which shows no completion checkmark until reps are logged.
1341
1351
  * - `"prescribe"`: the values are prescribed targets, written with every `param_N_made` and
1342
1352
  * `completed` left at 0 so the set is not marked done. This matches what the app sends when a
1343
1353
  * coach edits an athlete's prescribed reps/weight.
@@ -1382,7 +1392,7 @@ function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, w
1382
1392
  if (target) {
1383
1393
  p1 = target.param1 !== void 0 ? String(target.param1) : "";
1384
1394
  p2 = target.param2 !== void 0 ? String(target.param2) : "";
1385
- made = performed && (p1 !== "" || p2 !== "") ? 1 : 0;
1395
+ made = performed && p1 !== "" ? 1 : 0;
1386
1396
  } else if (carryOver && coerceInt(existing?.[`param_${i}_made`]) === 1) {
1387
1397
  p1 = existingSlotData(existing, `param_1_data_${i}`);
1388
1398
  p2 = existingSlotData(existing, `param_2_data_${i}`);
@@ -1410,16 +1420,19 @@ function exerciseHasLoggedData(ex) {
1410
1420
  for (let i = 1; i <= 10; i += 1) if (coerceInt(ex[`param_${i}_made`]) === 1) return true;
1411
1421
  return false;
1412
1422
  }
1413
- /** True when a result carries at least one non-empty param value (so it produces a performed slot). */
1414
- function resultHasData(result) {
1415
- return result.sets.some((s) => s.param1 !== void 0 && String(s.param1) !== "" || s.param2 !== void 0 && String(s.param2) !== "");
1423
+ /** True when a result carries at least one set with reps entered (so it produces a performed slot).
1424
+ * A weight-only set (`param2` set, `param1` blank) is a target, not a performed result, and so does
1425
+ * not count — mirroring the `made` rule in {@link buildExerciseSetPayload}. */
1426
+ function resultHasPerformedSet(result) {
1427
+ return result.sets.some((s) => s.param1 !== void 0 && String(s.param1) !== "");
1416
1428
  }
1417
1429
  /**
1418
1430
  * Whether every exercise in a saved workout set now has logged data — either written with data in
1419
1431
  * this call (`loggedIds`) or already carrying a performed slot. Gates the set-completion PUT: a
1420
1432
  * superset/circuit stays open until the last exercise is logged, so completing it on a partial log
1421
- * does not flip its still-empty siblings to "done". An exercise written with only empty values does
1422
- * not count (it would not be marked performed), so an all-empty log never completes the set.
1433
+ * does not flip its still-empty siblings to "done". An exercise written with no reps — empty values,
1434
+ * or a weight (`param2`) with no reps (`param1`) — does not count (it would not be marked performed),
1435
+ * so a no-reps log never completes the set.
1423
1436
  */
1424
1437
  function isSetFullyLogged(exercises, loggedIds) {
1425
1438
  return exercises.every((ex) => {
@@ -1653,7 +1666,7 @@ async function writeSetResults(client, target, workouts, savedWorkoutSetId, resu
1653
1666
  }
1654
1667
  let setCompleted = false;
1655
1668
  if (mode === "log") {
1656
- if (isSetFullyLogged(exercises, new Set(results.filter(resultHasData).map((r) => r.savedWorkoutSetExerciseId)))) {
1669
+ if (isSetFullyLogged(exercises, new Set(results.filter(resultHasPerformedSet).map((r) => r.savedWorkoutSetExerciseId)))) {
1657
1670
  const setBody = {
1658
1671
  ...buildSetCompletePayload(rawSet, exercises.map((e) => coerceInt(e.id)).filter((n) => n !== null), true),
1659
1672
  ...extra
@@ -3729,7 +3742,7 @@ var JsonFileLibraryCache = class {
3729
3742
  };
3730
3743
  //#endregion
3731
3744
  //#region package.json
3732
- var version = "1.7.0";
3745
+ var version = "1.7.2";
3733
3746
  //#endregion
3734
3747
  //#region src/server.ts
3735
3748
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/coach-mcp",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,8 +21,8 @@
21
21
  "dependencies": {
22
22
  "@modelcontextprotocol/sdk": "^1.29.0",
23
23
  "zod": "^4.4.3",
24
- "@trainheroic-unofficial/js": "1.7.0",
25
- "@trainheroic-unofficial/core": "1.7.0"
24
+ "@trainheroic-unofficial/core": "1.7.2",
25
+ "@trainheroic-unofficial/js": "1.7.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^26.0.1",