@trainheroic-unofficial/cli 1.2.0 → 1.4.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/cli.mjs +338 -12
  2. package/package.json +3 -3
package/dist/cli.mjs CHANGED
@@ -319,7 +319,20 @@ function parseWorkoutDate(s) {
319
319
  }
320
320
  //#endregion
321
321
  //#region ../js/src/auth.ts
322
- const AUTH_URL = "https://apis.trainheroic.com/auth";
322
+ const DEFAULT_AUTH_URL = "https://apis.trainheroic.com/auth";
323
+ /**
324
+ * The login endpoint, allowing an env override so a test harness can authenticate against a local
325
+ * fake backend. Precedence: an explicit `TH_AUTH_URL`, else `${TH_APIS_BASE}/auth` (login lives on
326
+ * the apis host, so it follows that base), else the real endpoint. Read via `globalThis.process`
327
+ * (no `import process`) to keep this module workerd-safe, and per call so a child-env override wins.
328
+ */
329
+ function authUrl() {
330
+ const env = globalThis.process?.env;
331
+ if (env?.TH_AUTH_URL && env.TH_AUTH_URL.length > 0) return env.TH_AUTH_URL;
332
+ const apis = env?.TH_APIS_BASE;
333
+ if (apis && apis.length > 0) return `${apis.replace(/\/$/, "")}/auth`;
334
+ return DEFAULT_AUTH_URL;
335
+ }
323
336
  /**
324
337
  * Authenticate against TrainHeroic. Returns the session bundle, or null on bad
325
338
  * credentials. TrainHeroic returns only { id, scope, role, session_id } (verified in
@@ -327,7 +340,7 @@ const AUTH_URL = "https://apis.trainheroic.com/auth";
327
340
  * is sent as the `session-token` header and works against both API hosts.
328
341
  */
329
342
  async function loginTrainHeroic(email, password) {
330
- const res = await fetch(AUTH_URL, {
343
+ const res = await fetch(authUrl(), {
331
344
  method: "POST",
332
345
  headers: {
333
346
  "content-type": "application/x-www-form-urlencoded",
@@ -350,8 +363,19 @@ async function loginTrainHeroic(email, password) {
350
363
  }
351
364
  //#endregion
352
365
  //#region ../js/src/client.ts
353
- const COACH_BASE = "https://api.trainheroic.com";
354
- const APIS_BASE = "https://apis.trainheroic.com";
366
+ const DEFAULT_COACH_BASE = "https://api.trainheroic.com";
367
+ const DEFAULT_APIS_BASE = "https://apis.trainheroic.com";
368
+ /**
369
+ * Resolve an API host, allowing an env override. The override exists so a test harness can point
370
+ * the client at a local fake backend (and it doubles as a staging knob); production leaves these
371
+ * unset and gets the real hosts. Read through `globalThis.process?.env` — not an `import process`
372
+ * — so the runtime-agnostic `.` entry stays free of `node:*` and runs unchanged on workerd, and
373
+ * read per request (not at module load) so a value the harness sets in the child env always wins.
374
+ */
375
+ function envBase(key, fallback) {
376
+ const v = (globalThis.process?.env)?.[key];
377
+ return v && v.length > 0 ? v : fallback;
378
+ }
355
379
  var TrainHeroicAuthError = class extends Error {
356
380
  name = "TrainHeroicAuthError";
357
381
  };
@@ -390,7 +414,7 @@ var TrainHeroicClient = class {
390
414
  return this.#sessionId;
391
415
  }
392
416
  async request(method, path, options = {}) {
393
- const url = `${options.base === "apis" ? APIS_BASE : COACH_BASE}/${path.replace(/^\//, "")}`;
417
+ const url = `${options.base === "apis" ? envBase("TH_APIS_BASE", DEFAULT_APIS_BASE) : envBase("TH_COACH_BASE", DEFAULT_COACH_BASE)}/${path.replace(/^\//, "")}`;
394
418
  let session = await this.#ensureSession();
395
419
  let res = await this.#send(method, url, session, options.body);
396
420
  if (res.status === 401 || res.status === 403) {
@@ -475,6 +499,14 @@ function coerceInt(value) {
475
499
  }
476
500
  return null;
477
501
  }
502
+ function coerceNum(value) {
503
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
504
+ if (typeof value === "string" && value.trim() !== "") {
505
+ const n = Number(value);
506
+ return Number.isFinite(n) ? n : null;
507
+ }
508
+ return null;
509
+ }
478
510
  function unitLabel(paramType) {
479
511
  const t = coerceInt(paramType);
480
512
  if (t === null) return null;
@@ -896,12 +928,35 @@ function presentAthleteWorkouts(list) {
896
928
  return list.map(presentAthleteWorkout);
897
929
  }
898
930
  /**
931
+ * Narrow a coach-athlete workout range to a single program or team. The range endpoint returns
932
+ * every program the athlete is enrolled in on a date; for a high-enrollment athlete that is many
933
+ * workouts, so a caller wanting one program's session narrows it here. Match by `programId`/`teamId`
934
+ * (exact, on the raw `program_id`/`team_id`) or by `programTitle` (case-insensitive substring on the
935
+ * `program_title`/`team_title`) — the title match lets a caller target a program by name without
936
+ * first resolving its id. Any one match keeps the workout; with no filter the list is unchanged.
937
+ */
938
+ function selectWorkoutsByProgram(list, filter) {
939
+ const { programId, teamId, programTitle } = filter;
940
+ const needle = programTitle?.trim().toLowerCase();
941
+ if (programId === void 0 && teamId === void 0 && !needle) return [...list];
942
+ return list.filter((pw) => {
943
+ const rec = pw;
944
+ if (programId !== void 0 && coerceInt(rec.program_id) === programId) return true;
945
+ if (teamId !== void 0 && coerceInt(rec.team_id) === teamId) return true;
946
+ if (needle) {
947
+ if (`${str$1(rec.program_title) ?? ""} ${str$1(rec.team_title) ?? ""}`.toLowerCase().includes(needle)) return true;
948
+ }
949
+ return false;
950
+ });
951
+ }
952
+ /**
899
953
  * Project a workout range to just the ids a set-log write needs, read from the SAME saved-copy
900
954
  * location {@link findSavedWorkoutSet} matches against (`summarizedSavedWorkout.saved_workout`).
901
955
  * This is the self-service path for logging: instead of grepping the multi-KB `--raw` blob for
902
956
  * which of several id fields maps to `--set`, callers read `savedWorkoutSetId` and each
903
- * `savedWorkoutSetExerciseId` straight off these rows. One row per saved set, dropping any set
904
- * with no resolvable id.
957
+ * `savedWorkoutSetExerciseId` straight off these rows. Each target also carries its program/team
958
+ * so a caller can pick the right session when the athlete is on several. One row per saved set,
959
+ * dropping any set with no resolvable id.
905
960
  */
906
961
  function presentLogTargets(list) {
907
962
  const targets = [];
@@ -912,6 +967,10 @@ function presentLogTargets(list) {
912
967
  if (!saved) continue;
913
968
  const date = str$1(rec.date) ?? "";
914
969
  const workoutTitle = str$1(rec.workout_title) ?? "";
970
+ const program = str$1(rec.program_title);
971
+ const programId = coerceInt(rec.program_id);
972
+ const team = str$1(rec.team_title);
973
+ const teamId = coerceInt(rec.team_id);
915
974
  const sets = Array.isArray(saved.workoutSets) ? saved.workoutSets : [];
916
975
  for (const s of sets) {
917
976
  if (!isRecord(s)) continue;
@@ -931,6 +990,10 @@ function presentLogTargets(list) {
931
990
  targets.push({
932
991
  date,
933
992
  workoutTitle,
993
+ program,
994
+ programId,
995
+ team,
996
+ teamId,
934
997
  savedWorkoutSetId,
935
998
  setTitle: str$1(s.title),
936
999
  exercises
@@ -1292,7 +1355,7 @@ async function writeSetResults(client, target, workouts, savedWorkoutSetId, resu
1292
1355
  throw new Error(`savedWorkoutSetExerciseId ${result.savedWorkoutSetExerciseId} not found in saved workout set ${savedWorkoutSetId}. Exercises in this set: ${valid.join(", ") || "none"}.`);
1293
1356
  }
1294
1357
  const workoutSetExerciseId = coerceInt(ex.workout_set_exercise_id);
1295
- if (!workoutSetExerciseId) throw new Error(`Could not resolve workout_set_exercise_id for exercise ${result.savedWorkoutSetExerciseId}.`);
1358
+ if (!workoutSetExerciseId) throw new Error(`savedWorkoutSetExercise ${result.savedWorkoutSetExerciseId} is missing its workout_set_exercise_id (the prescription-template pointer the write needs). This is the savedWorkoutSetExerciseId, not an exercise_id — re-read the ids from athlete_saved_workouts.`);
1296
1359
  const body = {
1297
1360
  ...buildExerciseSetPayload(result.savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, result.sets, mode),
1298
1361
  ...extra
@@ -1556,6 +1619,7 @@ function presentExerciseHistory(detail) {
1556
1619
  description: p.description ?? null,
1557
1620
  reps: p.reps ?? null,
1558
1621
  weight: p.weight ?? null,
1622
+ units: p.units ?? null,
1559
1623
  date: p.dateCompleted ?? null
1560
1624
  })),
1561
1625
  sessions: (detail.history ?? []).map((h) => ({
@@ -1573,6 +1637,37 @@ function presentExerciseHistory(detail) {
1573
1637
  function emailList(emails) {
1574
1638
  return [...new Set(emails.map((e) => e.trim()).filter((e) => e.length > 0))];
1575
1639
  }
1640
+ /** The display name on a /v5/athletes row: `fullName` (e.g. "Cohen, A"), else first+last. */
1641
+ function rosterName(rec) {
1642
+ const full = typeof rec.fullName === "string" ? rec.fullName.trim() : "";
1643
+ if (full !== "") return full;
1644
+ const combined = `${typeof rec.firstName === "string" ? rec.firstName : ""} ${typeof rec.lastName === "string" ? rec.lastName : ""}`.trim();
1645
+ return combined !== "" ? combined : null;
1646
+ }
1647
+ /**
1648
+ * The coach's roster as id + display name, from /v5/athletes. One home for the id coercion and the
1649
+ * name-field choice (the API uses `fullName` / `firstName`+`lastName`), so the CLI, the MCP tools,
1650
+ * and the warehouse store map the roster identically. Includes the account owner and
1651
+ * demo/placeholder athletes (the raw roster does); pass `ids` to keep only a subset.
1652
+ */
1653
+ async function fetchCoachRoster(client, ids) {
1654
+ const res = await client.request("GET", "/v5/athletes");
1655
+ if (!res.ok || !Array.isArray(res.data)) throw new Error(`List athletes failed (HTTP ${res.status}).`);
1656
+ const keep = ids && ids.length > 0 ? new Set(ids) : null;
1657
+ const out = [];
1658
+ for (const row of res.data) {
1659
+ if (typeof row !== "object" || row === null) continue;
1660
+ const rec = row;
1661
+ const id = coerceInt(rec.id);
1662
+ if (id === null || id <= 0) continue;
1663
+ if (keep && !keep.has(id)) continue;
1664
+ out.push({
1665
+ id,
1666
+ name: rosterName(rec)
1667
+ });
1668
+ }
1669
+ return out;
1670
+ }
1576
1671
  /**
1577
1672
  * Invite athletes to a team — TrainHeroic's two-step "create athlete" flow: validate the
1578
1673
  * addresses (`POST /v5/emails/validate`), then invite the validated ones
@@ -1852,6 +1947,213 @@ async function teamVolume(client, args) {
1852
1947
  };
1853
1948
  }
1854
1949
  //#endregion
1950
+ //#region ../js/src/main-lifts.ts
1951
+ /**
1952
+ * The "main lifts" — Big 4 plus the two Olympic lifts. ORDER MATTERS: a title is classified by the
1953
+ * first family that matches, so the more specific / easily-confused families come before the broad
1954
+ * overhead-press rule. That ordering is why "Bench Press" classifies as `bench` and never gets
1955
+ * swept up as an overhead press, and why "Clean & Jerk" is not mistaken for a clean-only movement.
1956
+ * This is the single place to edit the lift set.
1957
+ */
1958
+ const MAIN_LIFT_FAMILIES = [
1959
+ {
1960
+ key: "cleanjerk",
1961
+ label: "Clean & Jerk",
1962
+ matches: (t) => t.includes("jerk") || t.includes("clean") && !t.includes("clean pull")
1963
+ },
1964
+ {
1965
+ key: "snatch",
1966
+ label: "Snatch",
1967
+ matches: (t) => t.includes("snatch")
1968
+ },
1969
+ {
1970
+ key: "deadlift",
1971
+ label: "Deadlift",
1972
+ matches: (t) => t.includes("deadlift")
1973
+ },
1974
+ {
1975
+ key: "squat",
1976
+ label: "Squat",
1977
+ matches: (t) => t.includes("squat")
1978
+ },
1979
+ {
1980
+ key: "bench",
1981
+ label: "Bench Press",
1982
+ matches: (t) => t.includes("bench")
1983
+ },
1984
+ {
1985
+ key: "overhead",
1986
+ label: "Overhead Press",
1987
+ matches: (t) => t.includes("ohp") || (t.includes("overhead") || t.includes("shoulder") || t.includes("military") || t.includes("strict") || t.includes("push")) && t.includes("press")
1988
+ }
1989
+ ];
1990
+ /** The lift family a logged exercise title belongs to, or null if it is not a main lift. */
1991
+ function classifyMainLift(title) {
1992
+ const t = title.toLowerCase();
1993
+ for (const family of MAIN_LIFT_FAMILIES) if (family.matches(t)) return family.key;
1994
+ return null;
1995
+ }
1996
+ const DEFAULT_MONTHS = 12;
1997
+ function pad2(n) {
1998
+ return String(n).padStart(2, "0");
1999
+ }
2000
+ /** A local Date as a YYYY-MM-DD day string (the range endpoint's date format). */
2001
+ function isoDay(d) {
2002
+ return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
2003
+ }
2004
+ /**
2005
+ * Discover a roster athlete's main lifts from what they actually logged. Reads the athlete's
2006
+ * logged workouts over the last `months` (default 12) — the program-workout range, the reliable
2007
+ * record of performed sets — buckets every performed exercise into a lift family, and for each
2008
+ * family picks the variant logged most often. Returns one entry per family the athlete has logged;
2009
+ * families they never trained are simply absent. (The monthly calendar summary is not used: it
2010
+ * comes back empty for some accounts that have logged sets in the range endpoint.)
2011
+ */
2012
+ async function resolveAthleteMainLifts(client, athleteId, opts = {}) {
2013
+ const months = opts.months ?? DEFAULT_MONTHS;
2014
+ const now = opts.now ?? /* @__PURE__ */ new Date();
2015
+ const start = new Date(now.getFullYear(), now.getMonth() - (months - 1), 1);
2016
+ const tally = /* @__PURE__ */ new Map();
2017
+ let workouts = [];
2018
+ try {
2019
+ workouts = await fetchCoachAthleteWorkouts(client, athleteId, isoDay(start), isoDay(now));
2020
+ } catch {
2021
+ workouts = [];
2022
+ }
2023
+ for (const view of presentAthleteWorkouts(workouts)) for (const block of view.blocks) for (const ex of block.exercises) {
2024
+ if (ex.performed.length === 0 || ex.exerciseId === null) continue;
2025
+ const family = classifyMainLift(ex.title);
2026
+ if (family === null) continue;
2027
+ const byId = tally.get(family) ?? /* @__PURE__ */ new Map();
2028
+ const prev = byId.get(ex.exerciseId);
2029
+ byId.set(ex.exerciseId, {
2030
+ count: (prev?.count ?? 0) + 1,
2031
+ title: prev?.title ?? ex.title
2032
+ });
2033
+ tally.set(family, byId);
2034
+ }
2035
+ const lifts = [];
2036
+ for (const family of MAIN_LIFT_FAMILIES) {
2037
+ const byId = tally.get(family.key);
2038
+ if (!byId || byId.size === 0) continue;
2039
+ let best = null;
2040
+ for (const [exerciseId, { count, title }] of byId) if (best === null || count > best.count || count === best.count && exerciseId < best.exerciseId) best = {
2041
+ exerciseId,
2042
+ count,
2043
+ title
2044
+ };
2045
+ if (best) lifts.push({
2046
+ family: family.key,
2047
+ label: family.label,
2048
+ exerciseId: best.exerciseId,
2049
+ title: best.title
2050
+ });
2051
+ }
2052
+ return {
2053
+ athleteId,
2054
+ athleteName: null,
2055
+ lifts
2056
+ };
2057
+ }
2058
+ const PR_CONCURRENCY = 5;
2059
+ /** The heaviest PR on an exercise's board (ties broken by more reps). */
2060
+ function bestPr(liftPRs) {
2061
+ let best = null;
2062
+ for (const pr of liftPRs) {
2063
+ const weight = coerceNum(pr.weight);
2064
+ if (weight === null) continue;
2065
+ const reps = coerceInt(pr.reps);
2066
+ if (best === null || weight > best.weight || weight === best.weight && (reps ?? 0) > (best.reps ?? 0)) best = {
2067
+ weight,
2068
+ reps,
2069
+ units: pr.units,
2070
+ date: pr.date
2071
+ };
2072
+ }
2073
+ return best;
2074
+ }
2075
+ /**
2076
+ * A roster athlete's best PR for each main lift. Discovers the lift variants they log
2077
+ * ({@link resolveAthleteMainLifts}), then pulls each variant's PR board and keeps the heaviest set.
2078
+ * The result always carries one entry per family in {@link MAIN_LIFT_FAMILIES} order; a family the
2079
+ * athlete has not logged comes back with null fields (the "no PR yet" case), so a dashboard can
2080
+ * render a stable row of columns.
2081
+ */
2082
+ async function fetchAthleteMainLiftPRs(client, athleteId, opts = {}) {
2083
+ const { athleteName, lifts } = await resolveAthleteMainLifts(client, athleteId, opts);
2084
+ const byFamily = new Map(lifts.map((l) => [l.family, l]));
2085
+ return {
2086
+ athleteId,
2087
+ athleteName,
2088
+ prs: await mapPool(MAIN_LIFT_FAMILIES, PR_CONCURRENCY, async (family) => {
2089
+ const lift = byFamily.get(family.key);
2090
+ const base = {
2091
+ family: family.key,
2092
+ label: family.label
2093
+ };
2094
+ const empty = {
2095
+ exerciseId: null,
2096
+ title: null,
2097
+ weight: null,
2098
+ reps: null,
2099
+ units: null,
2100
+ date: null
2101
+ };
2102
+ if (!lift) return {
2103
+ ...base,
2104
+ ...empty
2105
+ };
2106
+ const known = {
2107
+ exerciseId: lift.exerciseId,
2108
+ title: lift.title
2109
+ };
2110
+ try {
2111
+ const best = bestPr(presentExerciseHistory(await fetchExerciseHistoryDetail(client, lift.exerciseId, athleteId)).liftPRs);
2112
+ return {
2113
+ ...base,
2114
+ ...known,
2115
+ weight: best?.weight ?? null,
2116
+ reps: best?.reps ?? null,
2117
+ units: best?.units ?? null,
2118
+ date: best?.date ?? null
2119
+ };
2120
+ } catch {
2121
+ return {
2122
+ ...base,
2123
+ ...known,
2124
+ weight: null,
2125
+ reps: null,
2126
+ units: null,
2127
+ date: null
2128
+ };
2129
+ }
2130
+ })
2131
+ };
2132
+ }
2133
+ const ROSTER_CONCURRENCY = 4;
2134
+ /**
2135
+ * Every roster athlete's main-lift PRs in one call: list the roster ({@link fetchCoachRoster}) and
2136
+ * resolve each athlete's board ({@link fetchAthleteMainLiftPRs}), fanned out with a bounded pool.
2137
+ * `athleteIds` restricts to a subset (else the whole roster). Each entry's `athleteName` falls back
2138
+ * to the roster name when the per-athlete read can't supply one. This is the single roster-level
2139
+ * primitive the CLI, the MCP tool, and the warehouse store all build on.
2140
+ */
2141
+ async function fetchRosterMainLiftPRs(client, opts = {}) {
2142
+ const roster = await fetchCoachRoster(client, opts.athleteIds);
2143
+ const inner = {
2144
+ ...opts.months !== void 0 ? { months: opts.months } : {},
2145
+ ...opts.now !== void 0 ? { now: opts.now } : {}
2146
+ };
2147
+ return mapPool(roster, opts.concurrency ?? ROSTER_CONCURRENCY, async (athlete) => {
2148
+ const result = await fetchAthleteMainLiftPRs(client, athlete.id, inner);
2149
+ return {
2150
+ athleteId: athlete.id,
2151
+ athleteName: result.athleteName ?? athlete.name,
2152
+ prs: result.prs
2153
+ };
2154
+ });
2155
+ }
2156
+ //#endregion
1855
2157
  //#region ../js/src/util.ts
1856
2158
  /**
1857
2159
  * Drop the keys whose value is `undefined`, so the result can be passed to a function or
@@ -2511,9 +2813,10 @@ Coach — manage a roster (needs a coach account):
2511
2813
  roster athlete reads (three lenses — pick by the question):
2512
2814
  coach roster-activity --athletes <id,id,...> [--metric] rank roster by recency; --metric adds session count + training volume. All-time snapshot, NO date range — for a windowed total use 'coach team-volume'. Get the full id list from 'coach athletes'.
2513
2815
  coach team-volume (--team <id> | --athletes <id,id,...>) --start Y-M-D --end Y-M-D team training volume scoped to a date window: per-athlete rows (only those who logged in range) + rolled-up totals (volume in lb). --team resolves the roster; --athletes passes ids directly.
2514
- coach athlete-workouts --athlete <id> --start Y-M-D --end Y-M-D [--logged-only] [--summary] [--raw|--log-ids] prescribed + logged work over a date range; --logged-only/--summary narrow it to what was actually logged; --log-ids prints just the savedWorkoutSetId + savedWorkoutSetExerciseId per set that log-set needs
2816
+ coach athlete-workouts --athlete <id> --start Y-M-D --end Y-M-D [--program <title>|--program-id <id>|--team <id>] [--logged-only] [--summary] [--raw|--log-ids] prescribed + logged work over a date range; --program (title substring) / --program-id / --team targets one program when the athlete is on several; --logged-only/--summary narrow it to what was actually logged; --log-ids prints just the savedWorkoutSetId + savedWorkoutSetExerciseId per set that log-set needs
2515
2817
  coach athlete-training --athlete <id> --year <YYYY> --month <1-12> sessions the athlete LOGGED in one month (empty = nothing logged that month, not an error)
2516
2818
  coach athlete-lift-history --athlete <id> --exercise <id> [--since Y-M-D] [--until Y-M-D] [--raw] one exercise's logged history + PRs
2819
+ coach main-lift-prs [--athlete <id>] [--athletes <id,id,...>] [--months <n>] best PRs for the main lifts (squat/bench/deadlift/overhead press/clean & jerk/snatch); auto-discovers the logged variant. With --athlete, one athlete; otherwise the whole roster (or --athletes subset)
2517
2820
 
2518
2821
  log for an athlete (record their reps/weights; real invited athletes only — demo/seeded ones 401):
2519
2822
  coach log-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson>|--file f --yes
@@ -3077,7 +3380,7 @@ async function cmdInstallSkill() {
3077
3380
  }
3078
3381
  out({ installed });
3079
3382
  }
3080
- const COACH_USAGE = "usage: trainheroic coach <head-coach|athletes|programs|teams|notifications|analytics|program <id>|team <id>|team-codes <id>|roster-activity|team-volume|athlete-training|athlete-lift-history|athlete-workouts|log-set|log-session|prescribe-set|swap-exercise|athlete-invite|athlete-archive|athlete-restore|team-create|team-update|team-delete|team-code-create|team-code-delete|session-copy|session-unpublish|session-save-template|analytics-query|exercise|workout|message>";
3383
+ const COACH_USAGE = "usage: trainheroic coach <head-coach|athletes|programs|teams|notifications|analytics|program <id>|team <id>|team-codes <id>|roster-activity|team-volume|athlete-training|athlete-lift-history|main-lift-prs|athlete-workouts|log-set|log-session|prescribe-set|swap-exercise|athlete-invite|athlete-archive|athlete-restore|team-create|team-update|team-delete|team-code-create|team-code-delete|session-copy|session-unpublish|session-save-template|analytics-query|exercise|workout|message>";
3081
3384
  const COACH_LOG_SET_USAGE = "coach log-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson> --yes";
3082
3385
  async function cmdCoachLogSet(client, a) {
3083
3386
  const { values, positionals } = parse(a, {
@@ -3189,18 +3492,26 @@ async function cmdCoachTeamVolume(client, a) {
3189
3492
  }));
3190
3493
  }
3191
3494
  async function cmdCoachAthleteWorkouts(client, a) {
3192
- const usage = "coach athlete-workouts --athlete <id> --start Y-M-D --end Y-M-D [--raw|--log-ids] [--logged-only] [--limit N] [--summary]";
3495
+ const usage = "coach athlete-workouts --athlete <id> --start Y-M-D --end Y-M-D [--program <title>|--program-id <id>|--team <id>] [--raw|--log-ids] [--logged-only] [--limit N] [--summary]";
3193
3496
  const { values } = parse(a, {
3194
3497
  athlete: { type: "string" },
3195
3498
  start: { type: "string" },
3196
3499
  end: { type: "string" },
3500
+ program: { type: "string" },
3501
+ "program-id": { type: "string" },
3502
+ team: { type: "string" },
3197
3503
  raw: { type: "boolean" },
3198
3504
  "log-ids": { type: "boolean" },
3199
3505
  "logged-only": { type: "boolean" },
3200
3506
  limit: { type: "string" },
3201
3507
  summary: { type: "boolean" }
3202
3508
  });
3203
- const workouts = await fetchCoachAthleteWorkouts(client, toInt(need(values.athlete, usage), "--athlete"), isoDate(need(values.start, usage), "--start"), isoDate(need(values.end, usage), "--end"));
3509
+ const all = await fetchCoachAthleteWorkouts(client, toInt(need(values.athlete, usage), "--athlete"), isoDate(need(values.start, usage), "--start"), isoDate(need(values.end, usage), "--end"));
3510
+ const filter = {};
3511
+ if (values.program !== void 0) filter.programTitle = values.program;
3512
+ if (values["program-id"] !== void 0) filter.programId = toInt(values["program-id"], "--program-id");
3513
+ if (values.team !== void 0) filter.teamId = toInt(values.team, "--team");
3514
+ const workouts = selectWorkoutsByProgram(all, filter);
3204
3515
  if (values["log-ids"] === true) return out(presentLogTargets(workouts));
3205
3516
  if (values.raw === true) return out(workouts);
3206
3517
  const opts = {};
@@ -3393,6 +3704,20 @@ async function cmdCoachAthleteLiftHistory(client, a) {
3393
3704
  sessions
3394
3705
  });
3395
3706
  }
3707
+ async function cmdCoachMainLiftPrs(client, a) {
3708
+ const { values } = parse(a, {
3709
+ athlete: { type: "string" },
3710
+ athletes: { type: "string" },
3711
+ months: { type: "string" }
3712
+ });
3713
+ const opts = values.months !== void 0 ? { months: toInt(values.months, "--months") } : {};
3714
+ if (values.athlete !== void 0) return out(await fetchAthleteMainLiftPRs(client, toInt(values.athlete, "--athlete"), opts));
3715
+ const subset = values.athletes !== void 0 ? values.athletes.split(",").map((s) => s.trim()).filter((s) => s.length > 0).map((s) => toInt(s, "--athletes")) : void 0;
3716
+ return out(await fetchRosterMainLiftPRs(client, {
3717
+ ...opts,
3718
+ ...subset ? { athleteIds: subset } : {}
3719
+ }));
3720
+ }
3396
3721
  async function cmdCoach(client, rest) {
3397
3722
  const [sub, ...a] = rest;
3398
3723
  switch (sub) {
@@ -3409,6 +3734,7 @@ async function cmdCoach(client, rest) {
3409
3734
  case "team-volume": return cmdCoachTeamVolume(client, a);
3410
3735
  case "athlete-training": return cmdCoachAthleteTraining(client, a);
3411
3736
  case "athlete-lift-history": return cmdCoachAthleteLiftHistory(client, a);
3737
+ case "main-lift-prs": return cmdCoachMainLiftPrs(client, a);
3412
3738
  case "athlete-workouts": return cmdCoachAthleteWorkouts(client, a);
3413
3739
  case "log-set": return cmdCoachLogSet(client, a);
3414
3740
  case "log-session": return cmdCoachLogSession(client, a);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/cli",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,8 +21,8 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "zod": "^4.4.3",
24
- "@trainheroic-unofficial/dto": "1.2.0",
25
- "@trainheroic-unofficial/js": "1.2.0"
24
+ "@trainheroic-unofficial/dto": "1.4.0",
25
+ "@trainheroic-unofficial/js": "1.4.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^26.0.0",