@trainheroic-unofficial/core 1.5.0 → 1.6.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.
Files changed (2) hide show
  1. package/dist/index.mjs +55 -6
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { blockSpecSchema, coachLogSessionArgsSchema, coachLogSetArgsSchema, coachPrescribeSetArgsSchema, commentDraftSchema, dateString, exerciseCreateSchema, idArgSchema, logSessionArgsSchema, logSetArgsSchema, parseWorkoutDate, swapAthleteExerciseArgsSchema } from "@trainheroic-unofficial/dto";
1
+ import { athleteSessionRemoveArgsSchema, blockSpecSchema, coachLogSessionArgsSchema, coachLogSetArgsSchema, coachPrescribeSetArgsSchema, commentDraftSchema, dateString, exerciseCreateSchema, idArgSchema, logSessionArgsSchema, logSetArgsSchema, parseWorkoutDate, swapAthleteExerciseArgsSchema } from "@trainheroic-unofficial/dto";
2
2
  import { z } from "zod";
3
- import { ANALYTICS_METRIC_KEYS, addExercisesToWorkout, buildCommentPayload, buildSession, coerceInt, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, prescribeForAthlete, presentAthleteWorkouts, presentCoachAthleteTraining, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, readLive, readSession, removeSession, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults } from "@trainheroic-unofficial/js";
3
+ import { ANALYTICS_METRIC_KEYS, addExercisesToWorkout, buildCommentPayload, buildSession, coerceInt, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, prescribeForAthlete, presentAthleteWorkouts, presentCoachAthleteTraining, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, readLive, readSession, removePersonalWorkout, removeSession, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults } from "@trainheroic-unofficial/js";
4
4
  //#region src/context.ts
5
5
  /** A tool argument that accepts a numeric id as a number or a string of digits. */
6
6
  const idParam = idArgSchema;
@@ -489,6 +489,7 @@ function registerProfileTools(server, ctx, whoami, userId) {
489
489
  }));
490
490
  }
491
491
  const ATHLETE_WORKOUTS_DESC = "Workouts in an inclusive YYYY-MM-DD window, flattened to blocks/exercises. Each exercise carries both its `prescribed` sets (what the program called for) and `performed` sets (what the athlete actually logged); each workout has a top-level `logged` flag. Use `performed`/`logged` to tell what was recorded or done. That is the reliable signal: a session can hold logged sets while the API's own completion flags stay 0, and an empty `performed` means nothing was logged for that exercise. For 'did I record anything / what did I do', set loggedOnly:true to return only sessions with logged sets (it keeps whole sessions that have any logged set, so individual exercises inside can still show empty `performed`; it also shrinks a large result); limit returns the most recent N workouts (newest first). For a high-level overview ('what's on my schedule this week', 'what have I been training lately') set summary:true to get one compact row per session (date, program, title, logged flag, and exerciseCount/performedCount — read performedCount against exerciseCount, e.g. 1 of 12 logged) instead of every set — a multi-program week of full detail is large, so prefer summary first, then re-query a single day without it to drill into that day's sets. For 'what's my next workout', query a forward window from today; if it comes back empty, the most recent session is likely yesterday's still-unlogged one, so widen the window backward a day or two. Both filters apply to the presented view, not raw. raw:true returns the untouched API objects. This is a date-windowed fetch, NOT an aggregate: for lifetime totals (all-time session count, total volume, first/last logged date) call athlete_profile instead of summing windows — a multi-year range here can time out. Narrow the window if the result is truncated.";
492
+ const ATHLETE_LOG_TARGETS_DESC = "The savedWorkoutSetId + savedWorkoutSetExerciseId that athlete_log_set needs, read straight off your scheduled/logged workouts in an inclusive YYYY-MM-DD window — no raw needed. This is the self-service path for logging into a COACH-SCHEDULED workout: read the ids here, then pass them to athlete_log_set. The default view is COMPACT: one row per saved set, each carrying its program/programId, the savedWorkoutSetId, and every exercise's savedWorkoutSetExerciseId with prescribed/performed values. When several workouts fall on the same day (you're on more than one program), narrow to one with program (a case-insensitive title substring, e.g. 'bodybuilding' — no id lookup needed), or programId/teamId if you have the id. raw:true returns the untouched API objects, but that blob is large and can be truncated when several workouts share a date — prefer the program filter + the default view. For reading what you actually did (not the log ids), use athlete_workouts.";
492
493
  const ATHLETE_EXERCISE_HISTORY_DESC = "Per-exercise PRs and the dated session time-series (sets performed, estimated 1RM). The returned `sessions` run all-time, newest first; pass since/until (YYYY-MM-DD, inclusive) to keep only sessions in that window — use it for 'last 3 months' / 'this year' questions so the result stays small. estimated1RM is a formula off the session's best set and reads high when a session mixes a heavy single with high-rep backdown work, so treat it as approximate, not a logged single. `liftPRs` are always all-time and ignore since/until, but each carries the date it was set, so filter those dates yourself to answer 'PRs set this year'. Set raw:true for the untouched API object. Get the exercise id from athlete_exercises.";
493
494
  const ATHLETE_EXERCISES_DESC = "The exercises the athlete has logged (id + title + positional units). Pass q to free-text search by name; use the returned id with athlete_exercise_history, athlete_personal_records, or athlete_exercise_stats (all of which require an exercise id). A common name returns several variants (e.g. plain 'Bench Press' id 1162 vs 'BARBELL BENCH PRESS'); each variant keeps its own separate history and PR board, so prefer the plain canonical entry, and if a PR or trend looks incomplete, the work may be split across variants — check the others.";
494
495
  function runAthleteWorkouts(ctx, args) {
@@ -566,7 +567,31 @@ function registerExerciseTools$1(server, ctx, userId) {
566
567
  annotations: READ
567
568
  }, ({ exerciseId, date }) => attempt(async () => jsonResult(await fetchExerciseStats(ctx.client, toId(exerciseId), await userId(), date))));
568
569
  }
569
- /** Create a personal workout session and add exercises to it. */
570
+ /** The compact log-id read: savedWorkoutSetId + savedWorkoutSetExerciseId for athlete_log_set. */
571
+ function registerLogTargetsTool(server, ctx) {
572
+ server.registerTool("athlete_log_targets", {
573
+ title: "Saved-workout log ids (for athlete_log_set)",
574
+ description: ATHLETE_LOG_TARGETS_DESC,
575
+ inputSchema: {
576
+ startDate: dateString,
577
+ endDate: dateString,
578
+ program: z.string().optional(),
579
+ programId: idParam.optional(),
580
+ teamId: idParam.optional(),
581
+ raw: z.boolean().optional()
582
+ },
583
+ annotations: READ
584
+ }, ({ startDate, endDate, program, programId, teamId, raw }) => attempt(async () => {
585
+ const workouts = selectWorkoutsByProgram(await fetchAthleteWorkouts(ctx.client, startDate, endDate), definedProps({
586
+ programTitle: program,
587
+ programId: programId === void 0 ? void 0 : toId(programId),
588
+ teamId: teamId === void 0 ? void 0 : toId(teamId)
589
+ }));
590
+ if (raw === true) return jsonResult(workouts, { hint: "Each set's id is the savedWorkoutSetId; each savedWorkoutSetExercises[].id is the savedWorkoutSetExerciseId. Large — if truncated, pass program (a title substring) or use the default compact view." });
591
+ return jsonResult(presentLogTargets(workouts), { hint: "One row per saved set: savedWorkoutSetId plus each savedWorkoutSetExerciseId, with the program it belongs to. Pass both to athlete_log_set. Filter with program (title substring), programId, or teamId if you're on several programs." });
592
+ }));
593
+ }
594
+ /** Create a personal workout session, add exercises, and remove a stray personal session. */
570
595
  function registerSessionTools(server, ctx) {
571
596
  server.registerTool("athlete_session_create", {
572
597
  title: "Create personal workout session",
@@ -600,6 +625,27 @@ function registerSessionTools(server, ctx) {
600
625
  }));
601
626
  return jsonResult(await addExercisesToWorkout(ctx.client, toId(workoutId), mapped), { hint: "Each top-level id is a savedWorkoutSetId; savedWorkoutSetExercises[].id is the savedWorkoutSetExerciseId for athlete_log_set." });
602
627
  }));
628
+ server.registerTool("athlete_session_remove", {
629
+ title: "Remove a personal workout session",
630
+ description: "Delete a personal (self-created) workout session from your calendar — use it to clean up a stray ad-hoc session, e.g. one athlete_log_session created when you meant to log into a coach-scheduled workout. Give the programWorkoutId (the `id` of the session in athlete_workouts, where personal:true marks a personal session) and its date. ONLY personal sessions can be removed: the tool re-reads that day and refuses a coach-scheduled workout. Requires confirmation (elicitation or confirm:true).",
631
+ inputSchema: {
632
+ ...athleteSessionRemoveArgsSchema.shape,
633
+ confirm: z.boolean().optional()
634
+ },
635
+ annotations: DESTRUCTIVE
636
+ }, ({ programWorkoutId, date, confirm }, extra) => attempt(async () => {
637
+ const id = toId(programWorkoutId);
638
+ if (!await confirmGate(server, extra.requestId, `Permanently remove personal session ${id} on ${date}? This deletes the session and anything logged in it.`, confirm)) return errorResult(NOT_CONFIRMED);
639
+ await removePersonalWorkout(ctx.client, {
640
+ programWorkoutId: id,
641
+ date
642
+ });
643
+ return jsonResult({
644
+ removed: true,
645
+ programWorkoutId: id,
646
+ date
647
+ });
648
+ }));
603
649
  }
604
650
  /** Map validated logSession exercises to the SDK's SessionExercise[] (ids coerced, slots trimmed). */
605
651
  function mapSessionExercises(exercises) {
@@ -630,14 +676,16 @@ function registerLogTool(server, ctx) {
630
676
  annotations: DESTRUCTIVE
631
677
  }, ({ date, exercises, confirm }, extra) => attempt(async () => {
632
678
  if (!await confirmGate(server, extra.requestId, `Log a session of ${exercises.length} exercise(s) on ${date}? This writes to your coach-visible training log.`, confirm)) return errorResult(NOT_CONFIRMED);
633
- return jsonResult(await logAdHocSession(ctx.client, {
679
+ const res = await logAdHocSession(ctx.client, {
634
680
  date,
635
681
  exercises: mapSessionExercises(exercises)
636
- }));
682
+ });
683
+ if (res.scheduledAlternatives !== void 0 && res.scheduledAlternatives.length > 0) return jsonResult(res, { hint: "Heads up: one or more of these lifts were already on a coach-scheduled workout today (see scheduledAlternatives). This logged a SEPARATE personal session. To log into the scheduled workout instead, use athlete_log_set with the savedWorkoutSetId / savedWorkoutSetExerciseId shown there — and athlete_session_remove to delete this personal session if it was a mistake." });
684
+ return jsonResult(res);
637
685
  }));
638
686
  server.registerTool("athlete_log_set", {
639
687
  title: "Log completed set results",
640
- description: "Athlete-facing write: record entered results (reps/weight per set) for a saved workout set on a given day. Writes to the athlete's (coach-visible) training log and shows in exercise history. Each set fills the next position in order; give a set a 1-based `slot` to place it at a specific position — e.g. log three top singles into positions 4-6 of an 8,5,3,1,1,1 ramp. A partial log records only the positions you send (plus any logged in an earlier call) and leaves the rest unlogged, so it does not mark untouched sets as performed. In a superset/circuit the block is marked done only once every exercise in it has logged results, so logging one exercise leaves its siblings untouched (the response's `setCompleted` reports whether the block was completed). Get savedWorkoutSetId + savedWorkoutSetExerciseId from athlete_workouts (raw:true). Requires confirmation (elicitation or confirm:true).",
688
+ description: "Athlete-facing write: record entered results (reps/weight per set) for a saved workout set on a given day. Writes to the athlete's (coach-visible) training log and shows in exercise history. Each set fills the next position in order; give a set a 1-based `slot` to place it at a specific position — e.g. log three top singles into positions 4-6 of an 8,5,3,1,1,1 ramp. A partial log records only the positions you send (plus any logged in an earlier call) and leaves the rest unlogged, so it does not mark untouched sets as performed. In a superset/circuit the block is marked done only once every exercise in it has logged results, so logging one exercise leaves its siblings untouched (the response's `setCompleted` reports whether the block was completed). Get savedWorkoutSetId + savedWorkoutSetExerciseId from athlete_log_targets (filter by program when several workouts share a date). Requires confirmation (elicitation or confirm:true).",
641
689
  inputSchema: {
642
690
  ...logSetArgsSchema.shape,
643
691
  confirm: z.boolean().optional()
@@ -674,6 +722,7 @@ function registerAthleteTrainingTools(server, ctx) {
674
722
  };
675
723
  registerProfileTools(server, ctx, whoami, userId);
676
724
  registerExerciseTools$1(server, ctx, userId);
725
+ registerLogTargetsTool(server, ctx);
677
726
  registerSessionTools(server, ctx);
678
727
  registerLogTool(server, ctx);
679
728
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/core",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,8 +25,8 @@
25
25
  "@cfworker/json-schema": "^4.1.1",
26
26
  "@modelcontextprotocol/sdk": "^1.29.0",
27
27
  "zod": "^4.4.3",
28
- "@trainheroic-unofficial/dto": "1.5.0",
29
- "@trainheroic-unofficial/js": "1.5.0"
28
+ "@trainheroic-unofficial/dto": "1.6.0",
29
+ "@trainheroic-unofficial/js": "1.6.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/node": "^26.0.0",