@trainheroic-unofficial/coach-mcp 3.4.0 → 3.5.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.
Files changed (2) hide show
  1. package/dist/server.mjs +121 -13
  2. package/package.json +3 -3
package/dist/server.mjs CHANGED
@@ -244,6 +244,10 @@ z.object({
244
244
  notes: z.string().optional(),
245
245
  rpe: z.number().int().min(1).max(10).optional()
246
246
  }).refine((v) => v.notes !== void 0 || v.rpe !== void 0, { message: "Provide notes and/or rpe" });
247
+ z.object({
248
+ savedWorkoutSetExerciseId: idArgSchema,
249
+ notes: z.string()
250
+ });
247
251
  const presentedNullNumber = z.number().nullable();
248
252
  const presentedNullString = z.string().nullable();
249
253
  /** Flattened exercise within a presented workout: prescriptions, logged results, units. */
@@ -251,6 +255,7 @@ const athleteWorkoutExerciseSchema = z.object({
251
255
  exerciseId: presentedNullNumber,
252
256
  title: z.string(),
253
257
  instruction: presentedNullString,
258
+ notes: presentedNullString,
254
259
  units: z.array(presentedNullString),
255
260
  prescribed: z.array(z.string()),
256
261
  performed: z.array(z.string())
@@ -359,6 +364,7 @@ const rosterActivityOutputSchema = z.array(rosterActivityRowSchema);
359
364
  const presentedExerciseSessionSchema = z.object({
360
365
  date: z.string(),
361
366
  abr: presentedNullString,
367
+ notes: presentedNullString,
362
368
  estimated1RM: presentedNullNumber,
363
369
  sets: z.array(z.object({
364
370
  setNumber: z.number(),
@@ -513,6 +519,7 @@ const logSetTargetOutputSchema = z.object({
513
519
  savedWorkoutSetExerciseId: z.number(),
514
520
  title: z.string(),
515
521
  units: z.array(nullableString),
522
+ notes: nullableString,
516
523
  prescribed: z.array(z.string()),
517
524
  performed: z.array(z.string())
518
525
  }))
@@ -587,6 +594,10 @@ z.object({
587
594
  notes: z.string(),
588
595
  rpe: nullableNumber
589
596
  });
597
+ z.object({
598
+ savedWorkoutSetExerciseId: z.number(),
599
+ notes: z.string()
600
+ });
590
601
  const workoutReadExerciseOutputSchema = z.object({
591
602
  order: z.number(),
592
603
  title: z.string(),
@@ -690,6 +701,12 @@ const exerciseSpecSchema = z.object({
690
701
  instr: z.string().optional(),
691
702
  param_1_type: z.number().optional(),
692
703
  param_2_type: z.number().optional()
704
+ }).superRefine((exercise, ctx) => {
705
+ if (Array.isArray(exercise.reps) && Array.isArray(exercise.weight) && exercise.reps.length !== exercise.weight.length) ctx.addIssue({
706
+ code: "custom",
707
+ message: `Per-set reps and weight arrays must have the same length; received ${exercise.reps.length} reps and ${exercise.weight.length} weights.`,
708
+ path: ["weight"]
709
+ });
693
710
  });
694
711
  /** A block's Red-Zone leaderboard: a unit string/number, or an object with options. */
695
712
  const leaderboardSpecSchema = z.union([
@@ -1529,6 +1546,16 @@ function performedSlotsByExerciseId(sets) {
1529
1546
  }
1530
1547
  return map;
1531
1548
  }
1549
+ /** Per-exercise athlete notes keyed by the prescription template id (`workout_set_exercise_id`). */
1550
+ function notesByTemplateId(sets) {
1551
+ const map = /* @__PURE__ */ new Map();
1552
+ for (const { exercises } of sets) for (const ex of exercises) {
1553
+ const id = coerceInt(ex.workout_set_exercise_id);
1554
+ const notes = str$1(ex.notes);
1555
+ if (id !== null && notes !== null) map.set(id, notes);
1556
+ }
1557
+ return map;
1558
+ }
1532
1559
  /** Align an exercise's prescribed slots with the slots the athlete logged, per set index. */
1533
1560
  function mergeExercise(prescribed, performed, meta) {
1534
1561
  const indices = [.../* @__PURE__ */ new Set([...prescribed.keys(), ...performed.keys()])].sort((a, b) => a - b);
@@ -1542,7 +1569,7 @@ function mergeExercise(prescribed, performed, meta) {
1542
1569
  };
1543
1570
  }
1544
1571
  /** A prescription block, each exercise aligned with the slots the athlete logged against it. */
1545
- function mergePrescriptionBlock(set, performedById) {
1572
+ function mergePrescriptionBlock(set, performedById, notesById) {
1546
1573
  const exercises = Array.isArray(set.workoutSetExercises) ? set.workoutSetExercises : [];
1547
1574
  return {
1548
1575
  order: coerceInt(set.order) ?? 0,
@@ -1556,6 +1583,7 @@ function mergePrescriptionBlock(set, performedById) {
1556
1583
  exerciseId: coerceInt(ex.exercise_id),
1557
1584
  title: typeof ex.title === "string" ? ex.title : "",
1558
1585
  instruction: str$1(ex.instruction),
1586
+ notes: id !== null ? notesById.get(id) ?? null : null,
1559
1587
  units: exerciseUnits(ex.param_1_type, ex.param_2_type)
1560
1588
  });
1561
1589
  })
@@ -1572,6 +1600,7 @@ function mergeSavedBlock(set, exercises) {
1572
1600
  exerciseId: coerceInt(ex.exercise_id),
1573
1601
  title: typeof ex.exercise_title === "string" ? ex.exercise_title : "",
1574
1602
  instruction: str$1(ex.instruction),
1603
+ notes: str$1(ex.notes),
1575
1604
  units: exerciseUnits(ex.param_1_type, ex.param_2_type)
1576
1605
  }))
1577
1606
  };
@@ -1590,7 +1619,8 @@ function mergeAthleteWorkout(raw) {
1590
1619
  const prescriptionSets = (Array.isArray(workout.workoutSets) ? workout.workoutSets : []).filter(isRecord);
1591
1620
  const logged = savedSets(saved);
1592
1621
  const performedById = performedSlotsByExerciseId(logged);
1593
- const blocks = prescriptionSets.map((s) => mergePrescriptionBlock(s, performedById)).sort((a, b) => a.order - b.order);
1622
+ const notesById = notesByTemplateId(logged);
1623
+ const blocks = prescriptionSets.map((s) => mergePrescriptionBlock(s, performedById, notesById)).sort((a, b) => a.order - b.order);
1594
1624
  const prescribedIds = /* @__PURE__ */ new Set();
1595
1625
  for (const s of prescriptionSets) {
1596
1626
  const exs = Array.isArray(s.workoutSetExercises) ? s.workoutSetExercises : [];
@@ -1636,6 +1666,7 @@ function toStringExercise(ex) {
1636
1666
  exerciseId: ex.exerciseId,
1637
1667
  title: ex.title,
1638
1668
  instruction: ex.instruction,
1669
+ notes: ex.notes,
1639
1670
  units: ex.units,
1640
1671
  prescribed: sideStrings(ex.sets, (s) => s.prescribed),
1641
1672
  performed: sideStrings(ex.sets, (s) => s.performed)
@@ -1730,6 +1761,7 @@ function presentLogTargets(list) {
1730
1761
  savedWorkoutSetExerciseId: id,
1731
1762
  title: exerciseTitle(ex),
1732
1763
  units: exerciseUnits(ex.param_1_type, ex.param_2_type),
1764
+ notes: str$1(ex.notes),
1733
1765
  prescribed: prescribedStrings(ex),
1734
1766
  performed: performedStrings(ex)
1735
1767
  };
@@ -1810,6 +1842,7 @@ function presentExerciseHistory(detail) {
1810
1842
  sessions: (detail.history ?? []).map((h) => ({
1811
1843
  date: h.dateCompleted,
1812
1844
  abr: h.abr ?? null,
1845
+ notes: str$1(h.notes),
1813
1846
  estimated1RM: h.bestEstimated1RM ?? null,
1814
1847
  sets: (h.sets ?? []).map((s) => ({
1815
1848
  setNumber: s.setNumber,
@@ -2433,9 +2466,75 @@ function repsList(ex) {
2433
2466
  const reps = ex.reps;
2434
2467
  if (Array.isArray(reps)) return reps.map((r) => String(r));
2435
2468
  if (reps === void 0 || reps === null) return [];
2436
- const sets = Math.max(1, Math.trunc(Number(ex.sets ?? 1)) || 1);
2469
+ const sets = Array.isArray(ex.weight) ? ex.weight.length : Math.max(1, Math.trunc(Number(ex.sets ?? 1)) || 1);
2437
2470
  return Array.from({ length: sets }, () => String(reps));
2438
2471
  }
2472
+ /** Number of sets that the encoder will write for an exercise. */
2473
+ function exerciseSetCount(ex) {
2474
+ if (Array.isArray(ex.reps) && ex.reps.length > 0) return ex.reps.length;
2475
+ if (Array.isArray(ex.weight)) return ex.weight.length;
2476
+ if (!Array.isArray(ex.reps) && ex.reps !== void 0 && ex.reps !== null || ex.weight !== void 0 && ex.weight !== null) return Math.max(1, Math.trunc(Number(ex.sets ?? 1)) || 1);
2477
+ return 0;
2478
+ }
2479
+ function findSetSplits(blocks) {
2480
+ return blocks.flatMap((block) => block.exercises.flatMap((exercise) => {
2481
+ const setCount = exerciseSetCount(exercise);
2482
+ if (setCount <= 10) return [];
2483
+ return [{
2484
+ blockTitle: block.title,
2485
+ exerciseTitle: exercise.title ?? String(exercise.id),
2486
+ setCount,
2487
+ blockCount: Math.ceil(setCount / 10)
2488
+ }];
2489
+ }));
2490
+ }
2491
+ function setSplitSummary(blocks) {
2492
+ const splits = findSetSplits(blocks);
2493
+ if (splits.length === 0) return null;
2494
+ return `TrainHeroic supports at most 10 sets per exercise block. The following will be split into consecutive same-titled blocks: ${splits.map(({ blockTitle, exerciseTitle, setCount, blockCount }) => `${blockTitle} / ${exerciseTitle}: ${setCount} sets into ${blockCount} blocks`).join("; ")}.`;
2495
+ }
2496
+ function sliceExercise(exercise, setCount, start) {
2497
+ if (start > 0 && setCount <= start) return null;
2498
+ const chunkCount = setCount === 0 ? 0 : Math.min(10, Math.max(0, setCount - start));
2499
+ const chunk = { ...exercise };
2500
+ const hasPerSetReps = Array.isArray(exercise.reps) && exercise.reps.length > 0;
2501
+ const hasScalarReps = !Array.isArray(exercise.reps) && exercise.reps !== void 0 && exercise.reps !== null;
2502
+ if (Array.isArray(exercise.reps) && exercise.reps.length > 0) {
2503
+ chunk.reps = exercise.reps.slice(start, start + 10);
2504
+ delete chunk.sets;
2505
+ } else if (hasScalarReps) chunk.sets = chunkCount;
2506
+ if (Array.isArray(exercise.weight)) {
2507
+ chunk.weight = exercise.weight.slice(start, start + 10);
2508
+ if (!hasPerSetReps && !hasScalarReps) delete chunk.sets;
2509
+ } else if (!hasPerSetReps && exercise.weight !== void 0 && exercise.weight !== null) chunk.sets = chunkCount;
2510
+ return chunk;
2511
+ }
2512
+ /**
2513
+ * Split blocks so no encoded exercise exceeds TrainHeroic's ten parameter slots.
2514
+ * Exercises in a superset stay aligned by set range; shorter exercises appear only in
2515
+ * chunks where they still have sets.
2516
+ */
2517
+ function splitOversizedBlocks(blocks) {
2518
+ return blocks.flatMap((block) => {
2519
+ const setCounts = block.exercises.map(exerciseSetCount);
2520
+ const largestSetCount = Math.max(0, ...setCounts);
2521
+ const chunkCount = Math.max(1, Math.ceil(largestSetCount / 10));
2522
+ if (chunkCount === 1) return [block];
2523
+ return Array.from({ length: chunkCount }, (_, index) => {
2524
+ const start = index * 10;
2525
+ const exercises = block.exercises.map((exercise, exerciseIndex) => sliceExercise(exercise, setCounts[exerciseIndex] ?? 0, start)).filter((exercise) => exercise !== null);
2526
+ if (index === 0) return {
2527
+ ...block,
2528
+ exercises
2529
+ };
2530
+ return {
2531
+ title: block.title,
2532
+ ...block.type === void 0 ? {} : { type: block.type },
2533
+ exercises
2534
+ };
2535
+ });
2536
+ });
2537
+ }
2439
2538
  /** Build one saveWorkoutSetExercises payload entry with all ten param slots filled. */
2440
2539
  function makeExercise(ex, workoutSetId, order, key) {
2441
2540
  const reps = repsList(ex);
@@ -2443,8 +2542,7 @@ function makeExercise(ex, workoutSetId, order, key) {
2443
2542
  if (instruction === "" && ex.rpe !== void 0 && ex.rpe !== null) instruction = `RPE ${ex.rpe}`;
2444
2543
  const hasWeight = ex.weight !== void 0 && ex.weight !== null;
2445
2544
  const weightArr = Array.isArray(ex.weight) ? ex.weight : null;
2446
- let count = reps.length;
2447
- if (count === 0 && hasWeight) count = weightArr ? weightArr.length : Math.max(1, Math.trunc(Number(ex.sets ?? 1)) || 1);
2545
+ const count = exerciseSetCount(ex);
2448
2546
  let param2Type;
2449
2547
  let param2Values;
2450
2548
  if (hasWeight) {
@@ -2475,8 +2573,8 @@ function makeExercise(ex, workoutSetId, order, key) {
2475
2573
  eType: "e",
2476
2574
  use_count: 0
2477
2575
  };
2478
- const p1 = slots(reps);
2479
- const p2 = slots(param2Values);
2576
+ const p1 = slots(reps, 10);
2577
+ const p2 = slots(param2Values, 10);
2480
2578
  for (let i = 0; i < 10; i += 1) {
2481
2579
  entry[`param_1_data_${i + 1}`] = p1[i] ?? "";
2482
2580
  entry[`param_2_data_${i + 1}`] = p2[i] ?? "";
@@ -2594,7 +2692,10 @@ function createPath(opts) {
2594
2692
  return `/2.0/coach/calendar/workout/createWorkoutForDay/${opts.programId}/${y}/${m}/${d}/0`;
2595
2693
  }
2596
2694
  async function buildSession(client, opts) {
2597
- const blocks = z.array(blockSpecSchema).parse(opts.blocks);
2695
+ const validatedBlocks = z.array(blockSpecSchema).parse(opts.blocks);
2696
+ const splitSummary = setSplitSummary(validatedBlocks);
2697
+ if (splitSummary !== null && opts.confirmSetSplit !== true) throw new Error(`${splitSummary} Set confirmSetSplit:true to allow this change.`);
2698
+ const blocks = splitSummary === null ? validatedBlocks : splitOversizedBlocks(validatedBlocks);
2598
2699
  const sess = await req(client, "POST", createPath(opts), {});
2599
2700
  checkResponse(sessionCreateResponseSchema, sess, "session create");
2600
2701
  const workoutId = Number(sess.workout_id);
@@ -4429,30 +4530,37 @@ function registerExerciseTools(server, ctx) {
4429
4530
  function registerBuild(server, ctx) {
4430
4531
  server.registerTool("workout_build", {
4431
4532
  title: "Build a workout session (draft)",
4432
- description: "Build an UNPUBLISHED session from a spec (program -> session -> blocks -> exercises). Pass programId for a team/group calendar (list_teams → group_program), or athleteId to write on that roster athlete's coach calendar (resolved via /v5/calendars/athletes/{id} — the same calendar the coach web app opens from My Athletes). athleteId requires date. Two exercises in one block become a superset. A block with empty exercises and a non-empty block instruction is a text-only Circuit / Conditioning block (type 1). Add a block 'leaderboard' for a Red-Zone score, or a top-level 'instruction' for the session note (Coach Instructions). Returns the draft ids, a read-back, and unit advisories. Review, then workout_publish.",
4533
+ description: "Build an UNPUBLISHED session from a spec (program -> session -> blocks -> exercises). Pass programId for a team/group calendar (list_teams → group_program), or athleteId to write on that roster athlete's coach calendar (resolved via /v5/calendars/athletes/{id} — the same calendar the coach web app opens from My Athletes). athleteId requires date. Two exercises in one block become a superset. A block with empty exercises and a non-empty block instruction is a text-only Circuit / Conditioning block (type 1). Add a block 'leaderboard' for a Red-Zone score, or a top-level 'instruction' for the session note (Coach Instructions). Returns the draft ids, a read-back, and unit advisories. Exercises above 10 sets are split into consecutive same-titled blocks and require confirmation (elicitation, or confirm:true). Review, then workout_publish.",
4433
4534
  inputSchema: {
4434
4535
  programId: z.number().optional(),
4435
4536
  athleteId: idParam.optional(),
4436
4537
  date: z.string().optional(),
4437
4538
  timelineDay: z.number().optional(),
4438
4539
  blocks: z.array(blockSpecSchema),
4439
- instruction: z.string().optional()
4540
+ instruction: z.string().optional(),
4541
+ confirm: z.boolean().optional()
4440
4542
  },
4441
4543
  outputSchema: toolOutputSchema(workoutBuildOutputSchema),
4442
4544
  annotations: ADDITIVE
4443
- }, ({ programId, athleteId, date, timelineDay, blocks, instruction }) => attempt(async () => {
4545
+ }, ({ programId, athleteId, date, timelineDay, blocks, instruction, confirm }, extra) => attempt(async () => {
4444
4546
  if (date === void 0 && timelineDay === void 0) return errorResult("Provide either date (YYYY-M-D) or timelineDay.");
4547
+ const typed = blocks;
4548
+ const splitSummary = setSplitSummary(typed);
4549
+ if (splitSummary !== null) {
4550
+ const blocked = confirmGate(extra, `${splitSummary} Continue?`, confirm);
4551
+ if (blocked) return blocked;
4552
+ }
4445
4553
  const resolveArgs = {};
4446
4554
  if (programId !== void 0) resolveArgs.programId = programId;
4447
4555
  if (athleteId !== void 0) resolveArgs.athleteId = toId(athleteId);
4448
4556
  if (date !== void 0) resolveArgs.date = date;
4449
4557
  const resolved = await resolveBuildProgramId(ctx.client, resolveArgs);
4450
- const typed = blocks;
4451
4558
  const opts = {
4452
4559
  programId: resolved,
4453
4560
  blocks: typed,
4454
4561
  publish: false
4455
4562
  };
4563
+ if (splitSummary !== null) opts.confirmSetSplit = true;
4456
4564
  if (date !== void 0) opts.date = parseWorkoutDate(date);
4457
4565
  if (timelineDay !== void 0) opts.timelineDay = timelineDay;
4458
4566
  if (instruction !== void 0) opts.instruction = instruction;
@@ -4724,7 +4832,7 @@ var JsonFileLibraryCache = class {
4724
4832
  };
4725
4833
  //#endregion
4726
4834
  //#region package.json
4727
- var version = "3.4.0";
4835
+ var version = "3.5.1";
4728
4836
  //#endregion
4729
4837
  //#region src/server.ts
4730
4838
  function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/coach-mcp",
3
- "version": "3.4.0",
3
+ "version": "3.5.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,8 +21,8 @@
21
21
  "dependencies": {
22
22
  "@modelcontextprotocol/server": "2.0.0",
23
23
  "zod": "^4.4.3",
24
- "@trainheroic-unofficial/core": "3.4.0",
25
- "@trainheroic-unofficial/js": "3.4.0"
24
+ "@trainheroic-unofficial/core": "3.5.1",
25
+ "@trainheroic-unofficial/js": "3.5.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^26.3.0",