@trainheroic-unofficial/coach-mcp 1.6.1 → 1.7.1
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/server.mjs +150 -93
- 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
|
|
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);
|
|
@@ -742,7 +750,7 @@ function withUnits(row) {
|
|
|
742
750
|
* Present a full raw exercise object for display: drop the raw param-type codes and add the
|
|
743
751
|
* positional `units` array. Keeps every other field of the raw object intact.
|
|
744
752
|
*/
|
|
745
|
-
function presentExercise
|
|
753
|
+
function presentExercise(raw) {
|
|
746
754
|
const { param_1_type, param_2_type, ...rest } = raw;
|
|
747
755
|
return {
|
|
748
756
|
...rest,
|
|
@@ -954,66 +962,40 @@ function nonEmpty(value) {
|
|
|
954
962
|
return value !== void 0 && value !== null && String(value).trim() !== "";
|
|
955
963
|
}
|
|
956
964
|
/**
|
|
957
|
-
*
|
|
958
|
-
*
|
|
959
|
-
*
|
|
965
|
+
* Slot-indexed values for one exercise. With `requireMade`, only slots the athlete logged
|
|
966
|
+
* (`param_i_made === 1`) — the performed reader; otherwise every slot carrying data — the
|
|
967
|
+
* prescription reader. Values stay raw; the projectors format or parse them.
|
|
960
968
|
*/
|
|
961
|
-
function
|
|
962
|
-
const
|
|
969
|
+
function slotValues(ex, requireMade) {
|
|
970
|
+
const map = /* @__PURE__ */ new Map();
|
|
963
971
|
for (let i = 1; i <= 10; i += 1) {
|
|
972
|
+
if (requireMade && coerceInt(ex[`param_${i}_made`]) !== 1) continue;
|
|
964
973
|
const p1 = ex[`param_1_data_${i}`];
|
|
965
974
|
const p2 = ex[`param_2_data_${i}`];
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
else out.push(`@ ${p2}`);
|
|
975
|
+
if (!nonEmpty(p1) && !nonEmpty(p2)) continue;
|
|
976
|
+
map.set(i, {
|
|
977
|
+
p1: nonEmpty(p1) ? p1 : null,
|
|
978
|
+
p2: nonEmpty(p2) ? p2 : null
|
|
979
|
+
});
|
|
972
980
|
}
|
|
973
|
-
return
|
|
981
|
+
return map;
|
|
974
982
|
}
|
|
975
|
-
/**
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
const out = [];
|
|
984
|
-
for (let i = 1; i <= 10; i += 1) {
|
|
985
|
-
if (coerceInt(ex[`param_${i}_made`]) !== 1) continue;
|
|
986
|
-
const p1 = ex[`param_1_data_${i}`];
|
|
987
|
-
const p2 = ex[`param_2_data_${i}`];
|
|
988
|
-
const has1 = nonEmpty(p1);
|
|
989
|
-
const has2 = nonEmpty(p2);
|
|
990
|
-
if (has1 && has2) out.push(`${p1} @ ${p2}`);
|
|
991
|
-
else if (has1) out.push(String(p1));
|
|
992
|
-
else if (has2) out.push(`@ ${p2}`);
|
|
993
|
-
}
|
|
994
|
-
return out;
|
|
983
|
+
/** The joined display for a slot, kept verbatim (`"5 @ 225"`, `"AMRAP"`, `"@ 225"`). */
|
|
984
|
+
function fmtSlot(slot) {
|
|
985
|
+
const has1 = slot.p1 !== null;
|
|
986
|
+
const has2 = slot.p2 !== null;
|
|
987
|
+
if (has1 && has2) return `${slot.p1} @ ${slot.p2}`;
|
|
988
|
+
if (has1) return String(slot.p1);
|
|
989
|
+
if (has2) return `@ ${slot.p2}`;
|
|
990
|
+
return "";
|
|
995
991
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
return {
|
|
1000
|
-
exerciseId: coerceInt(ex.exercise_id),
|
|
1001
|
-
title: typeof ex.title === "string" ? ex.title : "",
|
|
1002
|
-
instruction,
|
|
1003
|
-
units: exerciseUnits(ex.param_1_type, ex.param_2_type),
|
|
1004
|
-
prescribed: prescribedSets(ex),
|
|
1005
|
-
performed: (id !== null ? performedById.get(id) : void 0) ?? []
|
|
1006
|
-
};
|
|
992
|
+
/** Every slot carrying data, joined for display (the prescription reader): `["5 @ 225", "AMRAP"]`. */
|
|
993
|
+
function prescribedStrings(ex) {
|
|
994
|
+
return [...slotValues(ex, false).values()].map(fmtSlot);
|
|
1007
995
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
return
|
|
1011
|
-
order: coerceInt(set.order) ?? 0,
|
|
1012
|
-
title: typeof set.title === "string" && set.title !== "" ? set.title : null,
|
|
1013
|
-
instruction: typeof set.instruction === "string" && set.instruction !== "" ? set.instruction : null,
|
|
1014
|
-
isTest: coerceInt(set.is_test) === 1,
|
|
1015
|
-
exercises: exercises.filter(isRecord).map((ex) => presentExercise(ex, performedById))
|
|
1016
|
-
};
|
|
996
|
+
/** The slots the athlete logged (`param_i_made === 1`), joined for display (the performed reader). */
|
|
997
|
+
function performedStrings(ex) {
|
|
998
|
+
return [...slotValues(ex, true).values()].map(fmtSlot);
|
|
1017
999
|
}
|
|
1018
1000
|
/** Every logged set (programmed + athlete-added) in the saved copy, paired with its exercises. */
|
|
1019
1001
|
function savedSets(saved) {
|
|
@@ -1032,54 +1014,82 @@ function savedSets(saved) {
|
|
|
1032
1014
|
return out;
|
|
1033
1015
|
}
|
|
1034
1016
|
/**
|
|
1035
|
-
* Map each prescription exercise id to the
|
|
1036
|
-
* copy
|
|
1037
|
-
* entered values live in the same `param_N_data` slots as a prescription
|
|
1038
|
-
* prescription reader works on them unchanged.
|
|
1017
|
+
* Map each prescription exercise id to the slot-indexed values the athlete logged against it. In
|
|
1018
|
+
* the saved copy `workout_set_exercise_id` points back at the prescription exercise's `id`, and the
|
|
1019
|
+
* entered values live in the same `param_N_data` slots as a prescription.
|
|
1039
1020
|
*/
|
|
1040
|
-
function
|
|
1021
|
+
function performedSlotsByExerciseId(sets) {
|
|
1041
1022
|
const map = /* @__PURE__ */ new Map();
|
|
1042
1023
|
for (const { exercises } of sets) for (const ex of exercises) {
|
|
1043
1024
|
const id = coerceInt(ex.workout_set_exercise_id);
|
|
1044
1025
|
if (id === null) continue;
|
|
1045
|
-
const
|
|
1046
|
-
if (
|
|
1026
|
+
const slots = slotValues(ex, true);
|
|
1027
|
+
if (slots.size > 0) map.set(id, slots);
|
|
1047
1028
|
}
|
|
1048
1029
|
return map;
|
|
1049
1030
|
}
|
|
1050
|
-
/**
|
|
1051
|
-
function
|
|
1031
|
+
/** Align an exercise's prescribed slots with the slots the athlete logged, per set index. */
|
|
1032
|
+
function mergeExercise(prescribed, performed, meta) {
|
|
1033
|
+
const indices = [.../* @__PURE__ */ new Set([...prescribed.keys(), ...performed.keys()])].sort((a, b) => a - b);
|
|
1034
|
+
return {
|
|
1035
|
+
...meta,
|
|
1036
|
+
sets: indices.map((i) => ({
|
|
1037
|
+
set: i,
|
|
1038
|
+
prescribed: prescribed.get(i) ?? null,
|
|
1039
|
+
performed: performed.get(i) ?? null
|
|
1040
|
+
}))
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
/** A prescription block, each exercise aligned with the slots the athlete logged against it. */
|
|
1044
|
+
function mergePrescriptionBlock(set, performedById) {
|
|
1045
|
+
const exercises = Array.isArray(set.workoutSetExercises) ? set.workoutSetExercises : [];
|
|
1052
1046
|
return {
|
|
1053
1047
|
order: coerceInt(set.order) ?? 0,
|
|
1054
|
-
title:
|
|
1055
|
-
instruction:
|
|
1048
|
+
title: str$1(set.title),
|
|
1049
|
+
instruction: str$1(set.instruction),
|
|
1056
1050
|
isTest: coerceInt(set.is_test) === 1,
|
|
1057
|
-
exercises: exercises.map((ex) =>
|
|
1051
|
+
exercises: exercises.filter(isRecord).map((ex) => {
|
|
1052
|
+
const id = coerceInt(ex.id);
|
|
1053
|
+
const performed = (id !== null ? performedById.get(id) : void 0) ?? /* @__PURE__ */ new Map();
|
|
1054
|
+
return mergeExercise(slotValues(ex, false), performed, {
|
|
1055
|
+
exerciseId: coerceInt(ex.exercise_id),
|
|
1056
|
+
title: typeof ex.title === "string" ? ex.title : "",
|
|
1057
|
+
instruction: str$1(ex.instruction),
|
|
1058
|
+
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
1059
|
+
});
|
|
1060
|
+
})
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
/** A logged block straight from the saved copy (athlete-added or personal work; no prescription). */
|
|
1064
|
+
function mergeSavedBlock(set, exercises) {
|
|
1065
|
+
return {
|
|
1066
|
+
order: coerceInt(set.order) ?? 0,
|
|
1067
|
+
title: str$1(set.title),
|
|
1068
|
+
instruction: str$1(set.instruction),
|
|
1069
|
+
isTest: coerceInt(set.is_test) === 1,
|
|
1070
|
+
exercises: exercises.map((ex) => mergeExercise(/* @__PURE__ */ new Map(), slotValues(ex, true), {
|
|
1058
1071
|
exerciseId: coerceInt(ex.exercise_id),
|
|
1059
1072
|
title: typeof ex.exercise_title === "string" ? ex.exercise_title : "",
|
|
1060
|
-
instruction:
|
|
1061
|
-
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
1062
|
-
prescribed: [],
|
|
1063
|
-
performed: performedSets(ex)
|
|
1073
|
+
instruction: str$1(ex.instruction),
|
|
1074
|
+
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
1064
1075
|
}))
|
|
1065
1076
|
};
|
|
1066
1077
|
}
|
|
1067
1078
|
/**
|
|
1068
|
-
* Flatten one `/3.0/athlete/programworkout/range` item into
|
|
1079
|
+
* Flatten one `/3.0/athlete/programworkout/range` item into the canonical merged form, joining the
|
|
1069
1080
|
* prescription (`summarizedSavedWorkout.workout`) with what the athlete logged
|
|
1070
|
-
* (`summarizedSavedWorkout.saved_workout`).
|
|
1071
|
-
*
|
|
1072
|
-
* own blocks. No `raw` is needed to see logged results.
|
|
1081
|
+
* (`summarizedSavedWorkout.saved_workout`). Prescription blocks are enriched with logged slots;
|
|
1082
|
+
* athlete-added / personal work with no prescription is appended as its own block.
|
|
1073
1083
|
*/
|
|
1074
|
-
function
|
|
1084
|
+
function mergeAthleteWorkout(raw) {
|
|
1075
1085
|
const rec = raw;
|
|
1076
1086
|
const ssw = isRecord(rec.summarizedSavedWorkout) ? rec.summarizedSavedWorkout : {};
|
|
1077
1087
|
const workout = isRecord(ssw.workout) ? ssw.workout : {};
|
|
1078
1088
|
const saved = isRecord(ssw.saved_workout) ? ssw.saved_workout : {};
|
|
1079
1089
|
const prescriptionSets = (Array.isArray(workout.workoutSets) ? workout.workoutSets : []).filter(isRecord);
|
|
1080
1090
|
const logged = savedSets(saved);
|
|
1081
|
-
const performedById =
|
|
1082
|
-
const blocks = prescriptionSets.map((s) =>
|
|
1091
|
+
const performedById = performedSlotsByExerciseId(logged);
|
|
1092
|
+
const blocks = prescriptionSets.map((s) => mergePrescriptionBlock(s, performedById)).sort((a, b) => a.order - b.order);
|
|
1083
1093
|
const prescribedIds = /* @__PURE__ */ new Set();
|
|
1084
1094
|
for (const s of prescriptionSets) {
|
|
1085
1095
|
const exs = Array.isArray(s.workoutSetExercises) ? s.workoutSetExercises : [];
|
|
@@ -1091,11 +1101,11 @@ function presentAthleteWorkout(raw) {
|
|
|
1091
1101
|
}
|
|
1092
1102
|
for (const { set, exercises } of logged) {
|
|
1093
1103
|
const extra = exercises.filter((ex) => {
|
|
1094
|
-
if (
|
|
1104
|
+
if (slotValues(ex, true).size === 0) return false;
|
|
1095
1105
|
const id = coerceInt(ex.workout_set_exercise_id);
|
|
1096
1106
|
return id === null || !prescribedIds.has(id);
|
|
1097
1107
|
});
|
|
1098
|
-
if (extra.length > 0) blocks.push(
|
|
1108
|
+
if (extra.length > 0) blocks.push(mergeSavedBlock(set, extra));
|
|
1099
1109
|
}
|
|
1100
1110
|
return {
|
|
1101
1111
|
id: coerceInt(rec.id),
|
|
@@ -1104,11 +1114,58 @@ function presentAthleteWorkout(raw) {
|
|
|
1104
1114
|
program: str$1(rec.program_title),
|
|
1105
1115
|
team: str$1(rec.team_title),
|
|
1106
1116
|
instruction: str$1(workout.instruction),
|
|
1107
|
-
logged: blocks.some((b) => b.exercises.some((e) => e.
|
|
1117
|
+
logged: blocks.some((b) => b.exercises.some((e) => e.sets.some((s) => s.performed !== null))),
|
|
1108
1118
|
personal: isPersonalSession(rec),
|
|
1109
1119
|
blocks
|
|
1110
1120
|
};
|
|
1111
1121
|
}
|
|
1122
|
+
/** The per-set displays for one side (prescribed or performed), in slot order. */
|
|
1123
|
+
function sideStrings(sets, pick) {
|
|
1124
|
+
const out = [];
|
|
1125
|
+
for (const s of sets) {
|
|
1126
|
+
const slot = pick(s);
|
|
1127
|
+
if (slot) out.push(fmtSlot(slot));
|
|
1128
|
+
}
|
|
1129
|
+
return out;
|
|
1130
|
+
}
|
|
1131
|
+
function toStringExercise(ex) {
|
|
1132
|
+
return {
|
|
1133
|
+
exerciseId: ex.exerciseId,
|
|
1134
|
+
title: ex.title,
|
|
1135
|
+
instruction: ex.instruction,
|
|
1136
|
+
units: ex.units,
|
|
1137
|
+
prescribed: sideStrings(ex.sets, (s) => s.prescribed),
|
|
1138
|
+
performed: sideStrings(ex.sets, (s) => s.performed)
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
function toStringBlock(b) {
|
|
1142
|
+
return {
|
|
1143
|
+
order: b.order,
|
|
1144
|
+
title: b.title,
|
|
1145
|
+
instruction: b.instruction,
|
|
1146
|
+
isTest: b.isTest,
|
|
1147
|
+
exercises: b.exercises.map(toStringExercise)
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Flatten one range item into a readable workout: each exercise carries its `prescribed` and
|
|
1152
|
+
* `performed` sets as joined `"5 @ 225"` strings; athlete-added/personal work that has no
|
|
1153
|
+
* prescription is appended as its own blocks. No `raw` is needed to see logged results.
|
|
1154
|
+
*/
|
|
1155
|
+
function presentAthleteWorkout(raw) {
|
|
1156
|
+
const w = mergeAthleteWorkout(raw);
|
|
1157
|
+
return {
|
|
1158
|
+
id: w.id,
|
|
1159
|
+
date: w.date,
|
|
1160
|
+
title: w.title,
|
|
1161
|
+
program: w.program,
|
|
1162
|
+
team: w.team,
|
|
1163
|
+
instruction: w.instruction,
|
|
1164
|
+
logged: w.logged,
|
|
1165
|
+
personal: w.personal,
|
|
1166
|
+
blocks: w.blocks.map(toStringBlock)
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1112
1169
|
function presentAthleteWorkouts(list) {
|
|
1113
1170
|
return list.map(presentAthleteWorkout);
|
|
1114
1171
|
}
|
|
@@ -1168,8 +1225,8 @@ function presentLogTargets(list) {
|
|
|
1168
1225
|
savedWorkoutSetExerciseId: id,
|
|
1169
1226
|
title: exerciseTitle(ex),
|
|
1170
1227
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type),
|
|
1171
|
-
prescribed:
|
|
1172
|
-
performed:
|
|
1228
|
+
prescribed: prescribedStrings(ex),
|
|
1229
|
+
performed: performedStrings(ex)
|
|
1173
1230
|
};
|
|
1174
1231
|
}).filter((e) => e !== null);
|
|
1175
1232
|
targets.push({
|
|
@@ -2743,7 +2800,7 @@ var ExerciseLibrary = class {
|
|
|
2743
2800
|
await this.ensureFresh();
|
|
2744
2801
|
const s = this.#byId.get(id);
|
|
2745
2802
|
if (!s) return null;
|
|
2746
|
-
return presentExercise
|
|
2803
|
+
return presentExercise(s.raw);
|
|
2747
2804
|
}
|
|
2748
2805
|
async defaults(id) {
|
|
2749
2806
|
const s = this.#byId.get(id);
|
|
@@ -3680,7 +3737,7 @@ var JsonFileLibraryCache = class {
|
|
|
3680
3737
|
};
|
|
3681
3738
|
//#endregion
|
|
3682
3739
|
//#region package.json
|
|
3683
|
-
var version = "1.
|
|
3740
|
+
var version = "1.7.1";
|
|
3684
3741
|
//#endregion
|
|
3685
3742
|
//#region src/server.ts
|
|
3686
3743
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/coach-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
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/core": "1.
|
|
25
|
-
"@trainheroic-unofficial/js": "1.
|
|
24
|
+
"@trainheroic-unofficial/core": "1.7.1",
|
|
25
|
+
"@trainheroic-unofficial/js": "1.7.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.0.1",
|